From c2fb75f4e5971d4309c7a19b3e9f69e8111d03f0 Mon Sep 17 00:00:00 2001 From: "\"John Hawthorn ext:(%22)" Date: Wed, 31 Dec 2008 14:08:49 -0800 Subject: use GNU getline (temporary) --- src/main.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index b2ed1e9..7b687c5 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,5 @@ +#define _GNU_SOURCE #include #include @@ -256,11 +257,12 @@ void readlist(FILE *f){ while(!feof(f)){ images = realloc(images, lsize * sizeof(char *)); while(imageslen < lsize && !feof(f)){ - char *tmp = malloc(512); - if(fgets(tmp, 512, f)){ - tmp[strlen(tmp)-1] = '\0'; - images[imageslen] = tmp; - imageslen++; + char *line = NULL; + size_t slen = 0; + ssize_t read; + if((read = getline(&line, &slen, f)) > 0){ + line[read-1] = '\0'; + images[imageslen++] = line; } } lsize *= 2; -- cgit v1.2.3