summaryrefslogtreecommitdiff
path: root/libavutil
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-08-14 00:29:06 +0200
committerMichael Niedermayer <michaelni@gmx.at>2014-08-14 00:29:06 +0200
commitc8571c61ec4c352e7eac7147b7c1644d2406189e (patch)
tree7b30d14ae332d5b9d5b79ba257cc2833d28e3855 /libavutil
parent097bf149c92aeae8af7f3559878e046a047e892d (diff)
parent8ddc32629a6d6be77256694c9e322dde134609f3 (diff)
Merge commit '8ddc32629a6d6be77256694c9e322dde134609f3'
* commit '8ddc32629a6d6be77256694c9e322dde134609f3': mem: add av_strndup() for duplicating substrings Conflicts: libavutil/mem.c libavutil/mem.h libavutil/version.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/mem.c20
-rw-r--r--libavutil/mem.h10
-rw-r--r--libavutil/version.h2
3 files changed, 31 insertions, 1 deletions
diff --git a/libavutil/mem.c b/libavutil/mem.c
index 8226168eed..35a82e8a2d 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -267,6 +267,26 @@ char *av_strdup(const char *s)
return ptr;
}
+char *av_strndup(const char *s, size_t len)
+{
+ char *ret = NULL, *end;
+
+ if (!s)
+ return NULL;
+
+ end = memchr(s, 0, len);
+ if (end)
+ len = end - s;
+
+ ret = av_realloc(NULL, len + 1);
+ if (!ret)
+ return NULL;
+
+ memcpy(ret, s, len);
+ ret[len] = 0;
+ return ret;
+}
+
void *av_memdup(const void *p, size_t size)
{
void *ptr = NULL;
diff --git a/libavutil/mem.h b/libavutil/mem.h
index 0be2127071..2a1e36d69f 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -241,6 +241,16 @@ av_alloc_size(1, 2) static inline void *av_mallocz_array(size_t nmemb, size_t si
char *av_strdup(const char *s) av_malloc_attrib;
/**
+ * Duplicate a substring of the string s.
+ * @param s string to be duplicated
+ * @param len the maximum length of the resulting string (not counting the
+ * terminating byte).
+ * @return Pointer to a newly-allocated string containing a
+ * copy of s or NULL if the string cannot be allocated.
+ */
+char *av_strndup(const char *s, size_t len) av_malloc_attrib;
+
+/**
* Duplicate the buffer p.
* @param p buffer to be duplicated
* @return Pointer to a newly allocated buffer containing a
diff --git a/libavutil/version.h b/libavutil/version.h
index 43114c7899..f5b92778e2 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -56,7 +56,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 54
-#define LIBAVUTIL_VERSION_MINOR 2
+#define LIBAVUTIL_VERSION_MINOR 3
#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \