diff options
author | Karel Zak | 2013-01-29 15:25:47 +0100 |
---|---|---|
committer | Karel Zak | 2013-03-11 13:00:54 +0100 |
commit | 23106a29b0342ef8ada46bfc3df33b5d8e9c5e77 (patch) | |
tree | dd06db1e83a0bcb932d2d68b167ae7f7397abee3 /include/strutils.h | |
parent | fdisk: add callback for ask-numbers API (diff) | |
download | kernel-qcow2-util-linux-23106a29b0342ef8ada46bfc3df33b5d8e9c5e77.tar.gz kernel-qcow2-util-linux-23106a29b0342ef8ada46bfc3df33b5d8e9c5e77.tar.xz kernel-qcow2-util-linux-23106a29b0342ef8ada46bfc3df33b5d8e9c5e77.zip |
lib/strutils: simplify strtosize(), return info about suffix
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'include/strutils.h')
-rw-r--r-- | include/strutils.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/include/strutils.h b/include/strutils.h index 38eb1ce6a..695343405 100644 --- a/include/strutils.h +++ b/include/strutils.h @@ -1,6 +1,7 @@ #ifndef UTIL_LINUX_STRUTILS #define UTIL_LINUX_STRUTILS +#include <stdlib.h> #include <inttypes.h> #include <string.h> #include <sys/types.h> @@ -11,6 +12,7 @@ #endif +extern int parse_size(const char *str, uintmax_t *res, int *power); extern int strtosize(const char *str, uintmax_t *res); extern uintmax_t strtosize_or_err(const char *str, const char *errmesg); @@ -50,6 +52,25 @@ static inline void xstrncpy(char *dest, const char *src, size_t n) dest[n-1] = 0; } +static inline char *strdup_to_offset(void *stru, size_t offset, const char *str) +{ + char *n = NULL; + char **o = (char **) ((char *) stru + offset); + + if (str) { + n = strdup(str); + if (!n) + return NULL; + } + + free(*o); + *o = n; + return n; +} + +#define strdup_to_struct_member(_s, _m, _str) \ + strdup_to_offset((void *) _s, offsetof(__typeof__(*(_s)), _m), _str) + extern void strmode(mode_t mode, char *str); /* Options for size_to_human_string() */ |