diff options
author | wm4 <wm4@nowhere> | 2014-11-14 20:19:14 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-11-14 20:35:31 +0100 |
commit | f2788e6a61e7c2c2d7122f8a90812f55a9958f76 (patch) | |
tree | 3748ad6b26bdcea5bf80686bc85d981c0ae24749 /libass/ass_utils.c | |
parent | dc4544a0d493d79de3766f267df893d377fa148a (diff) | |
download | libass-f2788e6a61e7c2c2d7122f8a90812f55a9958f76.tar.bz2 libass-f2788e6a61e7c2c2d7122f8a90812f55a9958f76.tar.xz |
Add another helper-macro for array allocation
Diffstat (limited to 'libass/ass_utils.c')
-rw-r--r-- | libass/ass_utils.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/libass/ass_utils.c b/libass/ass_utils.c index 27fc025..593d787 100644 --- a/libass/ass_utils.c +++ b/libass/ass_utils.c @@ -102,6 +102,23 @@ void *ass_realloc_array(void *ptr, size_t nmemb, size_t size) return realloc(ptr, size); } +/** + * Like ass_realloc_array(), but: + * 1. on failure, return the original ptr value, instead of NULL + * 2. set errno to indicate failure (errno!=0) or success (errno==0) + */ +void *ass_try_realloc_array(void *ptr, size_t nmemb, size_t size) +{ + void *new_ptr = ass_realloc_array(ptr, nmemb, size); + if (new_ptr) { + errno = 0; + return new_ptr; + } else { + errno = ENOMEM; + return ptr; + } +} + void skip_spaces(char **str) { char *p = *str; |