X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Fccanlint%2Fget_file_lines.c;h=2f27a012dca5431a44c240a90c16307127ce9cbf;hp=e9ef302b32f0c739be09d289b5feccaaab5b078f;hb=999da3406c580e5b866e4fc0ac5a91bf5696dfb9;hpb=650c775ff00cccd03fc84e7789a03c51d9839004;ds=sidebyside diff --git a/tools/ccanlint/get_file_lines.c b/tools/ccanlint/get_file_lines.c index e9ef302b..2f27a012 100644 --- a/tools/ccanlint/get_file_lines.c +++ b/tools/ccanlint/get_file_lines.c @@ -49,31 +49,6 @@ static void *grab_file(const void *ctx, const char *filename) return buffer; } -/* This is a dumb one which copies. We could mangle instead. */ -static char **split(const void *ctx, const char *text, const char *delims, - unsigned int *nump) -{ - char **lines = NULL; - unsigned int max = 64, num = 0; - - lines = talloc_array(ctx, char *, max+1); - - while (*text != '\0') { - unsigned int len = strcspn(text, delims); - lines[num] = talloc_array(lines, char, len + 1); - memcpy(lines[num], text, len); - lines[num][len] = '\0'; - text += len; - text += strspn(text, delims); - if (++num == max) - lines = talloc_realloc(ctx, lines, char *, max*=2 + 1); - } - lines[num] = NULL; - if (nump) - *nump = num; - return lines; -} - char **get_file_lines(void *ctx, const char *name, unsigned int *num_lines) { char *buffer = grab_file(ctx, name); @@ -81,5 +56,5 @@ char **get_file_lines(void *ctx, const char *name, unsigned int *num_lines) if (!buffer) err(1, "Getting file %s", name); - return split(buffer, buffer, "\n", num_lines); + return strsplit(buffer, buffer, "\n", num_lines); }