diff --git a/mx_util.c b/mx_util.c index 790fc6b7..14d294c1 100644 --- a/mx_util.c +++ b/mx_util.c @@ -553,6 +553,16 @@ int mx_strtoi64(char *str, int64_t *to) return 0; } +void *mx_malloc_forever(size_t size) +{ + void *ret; + do { + ret=malloc(size); + assert(ret || (!ret && errno == ENOMEM)); + } while (!ret); + return ret ; +} + char *mx_strdup_forever(char *str) { char *dup; diff --git a/mx_util.h b/mx_util.h index f79d77fa..f8585fec 100644 --- a/mx_util.h +++ b/mx_util.h @@ -146,6 +146,7 @@ int mx_strtoi16(char *str, int16_t *to); int mx_strtoi32(char *str, int32_t *to); int mx_strtoi64(char *str, int64_t *to); +void *mx_malloc_forever(size_t size); char *mx_strdup_forever(char *str); int mx_vasprintf_forever(char **strp, const char *fmt, va_list ap); int mx_asprintf_forever(char **strp, const char *fmt, ...) __attribute__ ((format(printf, 2, 3)));