diff --git a/src/helpers.c b/src/helpers.c index 5e648f85..5f551b33 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -584,6 +584,21 @@ out_fds: return ret; } +/* Return a duplicated copy of the string using strdup(). + * Abort if there's no memory to allocate the new string. +*/ +char *strdup_or_die(const char *const str) +{ + char *result; + + result = strdup(str); + if (!result) { + abort(); + } + + return result; +} + void string_or_die(char **strp, const char *fmt, ...) { va_list ap; diff --git a/src/swupd.h b/src/swupd.h index d31273a1..dc7406b7 100644 --- a/src/swupd.h +++ b/src/swupd.h @@ -357,6 +357,7 @@ extern void print_manifest_files(struct manifest *m); extern void swupd_deinit(int lock_fd, struct list **subs); extern int swupd_init(int *lock_fd); extern void string_or_die(char **strp, const char *fmt, ...); +char *strdup_or_die(const char *const str); extern void free_string(char **s); void update_motd(int new_release); void delete_motd(void);