The function jumps to the next string in buffer where strings are
separated by \0.
Signed-off-by: Karel Zak <kzak@redhat.com>
*p = '\0';
}
+/* returns next string after \0 if before @end */
+static inline char *ul_next_string(char *p, char *end)
+{
+ char *last;
+
+ if (!p || !end || p >= end)
+ return NULL;
+
+ for (last = p; p < end; p++) {
+ if (*last == '\0' && p != last)
+ return p;
+ last = p;
+ }
+
+ return NULL;
+}
+
extern char *strnconcat(const char *s, const char *suffix, size_t b);
extern char *strconcat(const char *s, const char *suffix);
extern char *strfconcat(const char *s, const char *format, ...)
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"