* commit '8ddc32629a6d6be77256694c9e322dde134609f3': mem: add av_strndup() for duplicating substrings Conflicts: libavutil/mem.c libavutil/mem.h libavutil/version.h
Unified · Split
| @@ -15,6 +15,9 @@ libavutil: 2014-08-09 · 14 unmodified lines | ||
| 15 | 15 | |
| 16 | 16 | API changes, most recent first: |
| 17 | 17 | |
| 18 | +2014-08-xx - xxxxxxx - lavu 54.03.0 - mem.h | |
| 19 | + Add av_strndup(). | |
| 20 | + | |
| 18 | 21 | 2014-xx-xx - xxxxxxx - lavu 54.02.0 - opt.h |
| 19 | 22 | Add av_opt_get_dict_val/set_dict_val with AV_OPT_TYPE_DICT to support |
| 20 | 23 | dictionary types being set as options. |
| @@ -267,6 +267,26 @@ char *av_strdup(const char *s) · 266 unmodified lines | ||
| 267 | 267 | return ptr; |
| 268 | 268 | } |
| 269 | 269 | |
| 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 | + | |
| 270 | 290 | void *av_memdup(const void *p, size_t size) |
| 271 | 291 | { |
| 272 | 292 | void *ptr = NULL; |
| @@ -240,6 +240,16 @@ av_alloc_size(1, 2) static inline void *av_mallocz_array(size_t nmemb, size_t si · 239 unmodified lines | ||
| 240 | 240 | */ |
| 241 | 241 | char *av_strdup(const char *s) av_malloc_attrib; |
| 242 | 242 | |
| 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 | + | |
| 243 | 253 | /** |
| 244 | 254 | * Duplicate the buffer p. |
| 245 | 255 | * @param p buffer to be duplicated |
| @@ -56,7 +56,7 @@ · 55 unmodified lines | ||
| 56 | 56 | */ |
| 57 | 57 | |
| 58 | 58 | #define LIBAVUTIL_VERSION_MAJOR 54 |
| 59 | −#define LIBAVUTIL_VERSION_MINOR 2 | |
| 59 | +#define LIBAVUTIL_VERSION_MINOR 3 | |
| 60 | 60 | #define LIBAVUTIL_VERSION_MICRO 100 |
| 61 | 61 | |
| 62 | 62 | #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ |