Skip to content

Commit

Permalink
mx_util: add mx_malloc_forever
Browse files Browse the repository at this point in the history
  • Loading branch information
donald authored and mariux committed Oct 16, 2015
1 parent f83e67a commit 03703e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions mx_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions mx_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down

0 comments on commit 03703e1

Please sign in to comment.