diff options
author | Karel Zak | 2015-05-15 14:57:04 +0200 |
---|---|---|
committer | Karel Zak | 2015-05-15 14:57:04 +0200 |
commit | 548b9714e82ec7aca28958f5d5c2927a9b134fbe (patch) | |
tree | 4ccf0a33d6dff3998f2e34607e42d4f7119885a0 /include | |
parent | script: Fix mangled EOF and hang on big endian (diff) | |
download | kernel-qcow2-util-linux-548b9714e82ec7aca28958f5d5c2927a9b134fbe.tar.gz kernel-qcow2-util-linux-548b9714e82ec7aca28958f5d5c2927a9b134fbe.tar.xz kernel-qcow2-util-linux-548b9714e82ec7aca28958f5d5c2927a9b134fbe.zip |
lib/strv: add new functions (from systemd)
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/Makemodule.am | 1 | ||||
-rw-r--r-- | include/strutils.h | 4 | ||||
-rw-r--r-- | include/strv.h | 54 |
3 files changed, 59 insertions, 0 deletions
diff --git a/include/Makemodule.am b/include/Makemodule.am index f4556a687..be94f8a87 100644 --- a/include/Makemodule.am +++ b/include/Makemodule.am @@ -47,6 +47,7 @@ dist_noinst_HEADERS += \ include/setproctitle.h \ include/statfs_magic.h \ include/strutils.h \ + include/strv.h \ include/swapheader.h \ include/swapprober.h \ include/sysfs.h \ diff --git a/include/strutils.h b/include/strutils.h index 8235b5017..9eb9c8127 100644 --- a/include/strutils.h +++ b/include/strutils.h @@ -203,4 +203,8 @@ static inline size_t ltrim_whitespace(unsigned char *str) return len; } +extern char *strnappend(const char *s, const char *suffix, size_t b); +extern char *strappend(const char *s, const char *suffix); +extern const char *split(const char **state, size_t *l, const char *separator, int quoted); + #endif diff --git a/include/strv.h b/include/strv.h new file mode 100644 index 000000000..52862989a --- /dev/null +++ b/include/strv.h @@ -0,0 +1,54 @@ +#ifndef UTIL_LINUX_STRV +#define UTIL_LINUX_STRV + +#include <stdarg.h> + +#include "c.h" + +char **strv_free(char **l); +void strv_clear(char **l); +char **strv_copy(char * const *l); +unsigned strv_length(char * const *l); + +int strv_extend_strv(char ***a, char **b); +int strv_extend_strv_concat(char ***a, char **b, const char *suffix); +int strv_extend(char ***l, const char *value); +int strv_extendf(char ***l, const char *format, ...) + __attribute__ ((__format__ (__printf__, 2, 0))); +int strv_push(char ***l, char *value); +int strv_push_prepend(char ***l, char *value); +int strv_consume(char ***l, char *value); +int strv_consume_prepend(char ***l, char *value); + +char **strv_remove(char **l, const char *s); + +char **strv_new(const char *x, ...); +char **strv_new_ap(const char *x, va_list ap); + +static inline const char* STRV_IFNOTNULL(const char *x) { + return x ? x : (const char *) -1; +} + +static inline int strv_isempty(char * const *l) { + return !l || !*l; +} + +char **strv_split(const char *s, const char *separator); +char *strv_join(char **l, const char *separator); + +#define STRV_FOREACH(s, l) \ + for ((s) = (l); (s) && *(s); (s)++) + +#define STRV_FOREACH_BACKWARDS(s, l) \ + STRV_FOREACH(s, l) \ + ; \ + for ((s)--; (l) && ((s) >= (l)); (s)--) + + +#define STRV_MAKE_EMPTY ((char*[1]) { NULL }) + +char **strv_reverse(char **l); + +#endif /* UTIL_LINUX_STRV */ + + |