mirror of
https://github.com/versity/scoutfs.git
synced 2026-09-18 22:14:15 +00:00
Add strdup_or_error()
Add a helper function to handle the impossible event that strdup fails. Signed-off-by: Andy Grover <agrover@versity.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#define _PARSE_H_
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <argp.h>
|
||||
|
||||
int parse_human(char* str, u64 *val_ret);
|
||||
int parse_u64(char *str, u64 *val_ret);
|
||||
@@ -9,4 +10,13 @@ int parse_s64(char *str, s64 *val_ret);
|
||||
int parse_u32(char *str, u32 *val_ret);
|
||||
int parse_timespec(char *str, struct timespec *ts);
|
||||
|
||||
static inline char* strdup_or_error(const struct argp_state *state, char *str)
|
||||
{
|
||||
char *new = strdup(str);
|
||||
if (!new)
|
||||
argp_error(state, "memory allocation failed");
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user