X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=util.c;h=f0455833985c909d394593a9fa435fdac2a3af1d;hp=bcb608480f7d54cc0dc6c80f0a36b392d0e21340;hb=5cb5a6ffc33667c93e9bc3572534dcaa684046e3;hpb=852618039bea9f6fa851a0ae3101f79b65d3cf6b diff --git a/util.c b/util.c index bcb608480..f04558339 100644 --- a/util.c +++ b/util.c @@ -81,7 +81,7 @@ bool startswith(const char *s, const char *prefix) { return memcmp(s, prefix, pl) == 0; } -int nointr_close(int fd) { +int close_nointr(int fd) { assert(fd >= 0); for (;;) { @@ -145,3 +145,22 @@ int safe_atoi(const char *s, int *ret_i) { *ret_i = (unsigned) l; return 0; } + +/* What is interpreted as whitespace? */ +#define WHITESPACE " \t\n" + +/* Split a string into words. */ +char *split_spaces(const char *c, size_t *l, char **state) { + char *current; + + current = *state ? *state : (char*) c; + + if (!*current || *c == 0) + return NULL; + + current += strspn(current, WHITESPACE); + *l = strcspn(current, WHITESPACE); + *state = current+*l; + + return (char*) current; +}