diff options
-rw-r--r-- | neols.c | 13 | ||||
-rw-r--r-- | shared.h | 23 |
2 files changed, 6 insertions, 30 deletions
diff --git a/neols.c b/neols.c index a288fee..01ce98c 100644 --- a/neols.c +++ b/neols.c @@ -1,11 +1,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "shared.h" -/* A majority of lines in files.json -are less than 80 characters long. */ -#define GUESS 80 /* Each informative line has 6 spaces, a quote, then the data type, then a quote, then a colon, then a space, then a quote, @@ -97,15 +93,15 @@ main(int argc, char **argv) else dir = argv[i]; } - char *line; + char *line = NULL; /* The various statistics related to each entry are stored, one entry at a time. A path may be any size, so each line need be handled by realloc. */ char *path = NULL, *updated_at = NULL, *sha1_hash = NULL; int is_directory = 0, size = 0; - int end, len; - for (end = 0; ! end;) { - line = storeline(in, &end, &len, GUESS); + int len; + unsigned long line_size = 0; + while ((len = getline(&line, &line_size, in)) > 0) { /* Only on lines terminating an entry, '}' is the fifth character. The ninth character of each data line is unique. */ @@ -143,6 +139,7 @@ main(int argc, char **argv) } else if (line[8] == 'h') { sha1_hash = line; } + line = NULL; } return 0; } diff --git a/shared.h b/shared.h index b4232ae..740984d 100644 --- a/shared.h +++ b/shared.h @@ -1,22 +1 @@ -static char * -storeline(FILE *in, int *end, int *len, int guess) -{ - static char *line; - line = calloc(guess, sizeof(char)); - int i = 0, buflen = guess; - char ch; - while ((ch = fgetc(in)) != EOF && ch != '\n') { - if (i == buflen - 1) { - buflen += guess; - line = realloc(line, buflen * sizeof(char)); - } - line[i] = ch; - ++i; - } - line[i] = '\0'; - *len = i; - if (ch == EOF) - *end = 1; - - return line; -} +char *site = "https://kaa.neocities.org/"; |