mirror of
https://github.com/clearlinux/swupd-client.git
synced 2026-10-03 15:29:29 +00:00
helpers: Add a strdup_or_die() function
Add a helper similar to string_or_die() that performs a strdup and abort on errors. This function have the same behaviour as string_or_die with format set to "%s".
This commit is contained in:
committed by
Matthew Johnson
parent
fb668f615c
commit
1eeed64dd0
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user