History

Merge commit '8ddc32629a6d6be77256694c9e322dde134609f3'

* commit '8ddc32629a6d6be77256694c9e322dde134609f3': mem: add av_strndup() for duplicating substrings Conflicts: libavutil/mem.c libavutil/mem.h libavutil/version.h

Michael Niedermayer committed 12 years ago

Commit c8571c62 parents 097bf14 8ddc3264 files · +34 −1Browse files

Unified · Split

4 files
  1. doc/APIchanges +3 −0
  2. libavutil/mem.c +20 −0
  3. libavutil/mem.h +10 −0
  4. libavutil/version.h +1 −1
doc/APIchanges+3−0
@@ -15,6 +15,9 @@ libavutil: 2014-08-09 · 14 unmodified lines
1515
1616 API changes, most recent first:
1717
18+2014-08-xx - xxxxxxx - lavu 54.03.0 - mem.h
19+ Add av_strndup().
20+
1821 2014-xx-xx - xxxxxxx - lavu 54.02.0 - opt.h
1922 Add av_opt_get_dict_val/set_dict_val with AV_OPT_TYPE_DICT to support
2023 dictionary types being set as options.
libavutil/mem.c+20−0
@@ -267,6 +267,26 @@ char *av_strdup(const char *s) · 266 unmodified lines
267267 return ptr;
268268 }
269269
270+char *av_strndup(const char *s, size_t len)
271+{
272+ char *ret = NULL, *end;
273+
274+ if (!s)
275+ return NULL;
276+
277+ end = memchr(s, 0, len);
278+ if (end)
279+ len = end - s;
280+
281+ ret = av_realloc(NULL, len + 1);
282+ if (!ret)
283+ return NULL;
284+
285+ memcpy(ret, s, len);
286+ ret[len] = 0;
287+ return ret;
288+}
289+
270290 void *av_memdup(const void *p, size_t size)
271291 {
272292 void *ptr = NULL;
libavutil/mem.h+10−0
@@ -240,6 +240,16 @@ av_alloc_size(1, 2) static inline void *av_mallocz_array(size_t nmemb, size_t si · 239 unmodified lines
240240 */
241241 char *av_strdup(const char *s) av_malloc_attrib;
242242
243+/**
244+ * Duplicate a substring of the string s.
245+ * @param s string to be duplicated
246+ * @param len the maximum length of the resulting string (not counting the
247+ * terminating byte).
248+ * @return Pointer to a newly-allocated string containing a
249+ * copy of s or NULL if the string cannot be allocated.
250+ */
251+char *av_strndup(const char *s, size_t len) av_malloc_attrib;
252+
243253 /**
244254 * Duplicate the buffer p.
245255 * @param p buffer to be duplicated
libavutil/version.h+1−1
@@ -56,7 +56,7 @@ · 55 unmodified lines
5656 */
5757
5858 #define LIBAVUTIL_VERSION_MAJOR 54
59−#define LIBAVUTIL_VERSION_MINOR 2
59+#define LIBAVUTIL_VERSION_MINOR 3
6060 #define LIBAVUTIL_VERSION_MICRO 100
6161
6262 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t