diff --git a/cmdline/support.c b/cmdline/support.c index 433fca22..d41f9a2d 100644 --- a/cmdline/support.c +++ b/cmdline/support.c @@ -586,30 +586,27 @@ char* polish(char* s) return s; } -unsigned split(char** split_map, unsigned split_max, char* str) +unsigned split(char** split_map, unsigned split_max, char* str, const char* delimiters) { unsigned mac = 0; - /* skip initial spaces */ - while (isspace(*str)) - ++str; + /* skip initial delimiers */ + str += strspn(str, delimiters); while (*str != 0 || mac == split_max) { /* start of the token */ split_map[mac] = str; ++mac; - /* find the first separator or the end of the string */ - while (*str != 0 && !isspace(*str)) - ++str; + /* find the first delimiter or the end of the string */ + str += strcspn(str, delimiters); /* put the final terminator if missing */ if (*str != 0) *str++ = 0; - /* skip trailing spaces */ - while (isspace(*str)) - ++str; + /* skip trailing delimiters */ + str += strspn(str, delimiters); } return mac; diff --git a/cmdline/support.h b/cmdline/support.h index c9e3ab0a..2c74320d 100644 --- a/cmdline/support.h +++ b/cmdline/support.h @@ -244,11 +244,11 @@ const char* quote(char prefix, const char* str, char* buffer); char* polish(char* s); /** - * Split a string in multiple tokens separated by spaces. + * Split a string in multiple tokens separated by delimiters. * - * Multiple spaces are grouped together. + * Multiple delimiters are grouped together. */ -unsigned split(char** split_map, unsigned split_max, char* line); +unsigned split(char** split_map, unsigned split_max, char* line, const char* delimiters); /****************************************************************************/ /* path */ diff --git a/cmdline/unix.c b/cmdline/unix.c index eeba8e33..2a6252c5 100644 --- a/cmdline/unix.c +++ b/cmdline/unix.c @@ -101,7 +101,7 @@ static int devresolve_proc(uint64_t device, char* path, size_t path_size) break; /* split the line */ - split_mac = split(split_map, 9, s); + split_mac = split(split_map, 9, s, " \t\r\n"); /* if too short, it's the wrong line */ if (split_mac < 9)