[vlc-commits] objres: add vlc_obj_strdup()
Rémi Denis-Courmont
git at videolan.org
Thu May 3 19:13:30 CEST 2018
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu May 3 20:05:36 2018 +0300| [13c5935c1c89661c0018ffba470297db8392cf8b] | committer: Rémi Denis-Courmont
objres: add vlc_obj_strdup()
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=13c5935c1c89661c0018ffba470297db8392cf8b
---
include/vlc_objects.h | 1 +
src/libvlccore.sym | 1 +
src/misc/objres.c | 14 ++++++++++++++
3 files changed, 16 insertions(+)
diff --git a/include/vlc_objects.h b/include/vlc_objects.h
index 4e0314acbb..8a107dbfad 100644
--- a/include/vlc_objects.h
+++ b/include/vlc_objects.h
@@ -139,6 +139,7 @@ VLC_API char *vlc_object_get_name( const vlc_object_t * ) VLC_USED;
VLC_API VLC_MALLOC void *vlc_obj_malloc(vlc_object_t *, size_t);
VLC_API VLC_MALLOC void *vlc_obj_calloc(vlc_object_t *, size_t, size_t);
+VLC_API VLC_MALLOC char *vlc_obj_strdup(vlc_object_t *, const char *);
VLC_API void vlc_obj_free(vlc_object_t *, void *);
/** @} */
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index ce655489dc..9528af18b0 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -273,6 +273,7 @@ vlc_strerror
vlc_strerror_c
vlc_obj_malloc
vlc_obj_calloc
+vlc_obj_strdup
vlc_obj_free
msleep
mwait
diff --git a/src/misc/objres.c b/src/misc/objres.c
index 843ba40056..c5c3d96711 100644
--- a/src/misc/objres.c
+++ b/src/misc/objres.c
@@ -26,6 +26,7 @@
#include <errno.h>
#include <stdlib.h>
#include <stddef.h>
+#include <string.h>
#include <vlc_common.h>
@@ -166,6 +167,19 @@ void *vlc_obj_calloc(vlc_object_t *obj, size_t nmemb, size_t size)
return vlc_obj_alloc_common(obj, nmemb, size, true);
}
+static void *vlc_obj_memdup(vlc_object_t *obj, const void *base, size_t len)
+{
+ void *ptr = vlc_obj_malloc(obj, len);
+ if (likely(ptr != NULL))
+ memcpy(ptr, base, len);
+ return ptr;
+}
+
+char *vlc_obj_strdup(vlc_object_t *obj, const char *str)
+{
+ return vlc_obj_memdup(obj, str, strlen(str) + 1);
+}
+
void vlc_obj_free(vlc_object_t *obj, void *ptr)
{
vlc_objres_remove(obj, ptr, ptrcmp);
More information about the vlc-commits
mailing list