From 03703e1d478c5f040f53ffe6b6e850754d575ce5 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Wed, 14 Oct 2015 18:32:20 +0200 Subject: [PATCH] mx_util: add mx_malloc_forever --- mx_util.c | 10 ++++++++++ mx_util.h | 1 + 2 files changed, 11 insertions(+) diff --git a/mx_util.c b/mx_util.c index 790fc6b..14d294c 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 f79d77f..f8585fe 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)));