diff options
| author | Karel Zak <kzak@redhat.com> | 2023-10-11 12:37:40 +0200 |
|---|---|---|
| committer | Karel Zak <kzak@redhat.com> | 2023-10-23 21:54:00 +0200 |
| commit | 357e6a0efc62f2151ba24b4730cc35015559bd41 (patch) | |
| tree | 438658661f79b76d48d6e0185ef36e54504b656a /lib/strutils.c | |
| parent | c2f3f40ecc78ac298118d14a6ec037f854076afe (diff) | |
| download | util-linux-357e6a0efc62f2151ba24b4730cc35015559bd41.tar.gz | |
lib/strutils: add ul_next_string()
The function jumps to the next string in buffer where strings are
separated by \0.
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib/strutils.c')
| -rw-r--r-- | lib/strutils.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/strutils.c b/lib/strutils.c index 2bfc8ac6cf..ccf71b987f 100644 --- a/lib/strutils.c +++ b/lib/strutils.c @@ -1414,6 +1414,15 @@ int main(int argc, char *argv[]) printf("\"%s\" --> \"%s\"\n", argv[2], ul_strchr_escaped(argv[2], *argv[3])); return EXIT_SUCCESS; + } else if (argc == 2 && strcmp(argv[1], "--next-string") == 0) { + char *buf = "abc\0Y\0\0xyz\0X"; + char *end = buf + 12; + char *p = buf; + + do { + printf("str: '%s'\n", p); + } while ((p = ul_next_string(p, end))); + } else { fprintf(stderr, "usage: %1$s --size <number>[suffix]\n" " %1$s --cmp-paths <path> <path>\n" |
