diff options
author | Hiltjo Posthuma <hiltjo@codemadness.org> | 2015-01-02 15:32:45 +0100 |
---|---|---|
committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2015-01-02 15:32:45 +0100 |
commit | f5be0d36c5d45c10e055c13dd8060152effa3aed (patch) | |
tree | 940dd802eceaccbc78cdd865f3f88faec5f070cb /sfeed_stats.c | |
parent | bcd1e1972d63cdd2ca8b42572a129be521558aba (diff) |
cleanup
- dont free at end (not needed in our case).
- use 0 and 1 instead of EXIT_SUCCESS, EXIT_FAILURE.
- use err (from err.h) instead of custom die().
Diffstat (limited to 'sfeed_stats.c')
-rw-r--r-- | sfeed_stats.c | 26 |
1 files changed, 5 insertions, 21 deletions
diff --git a/sfeed_stats.c b/sfeed_stats.c index 800c0c9..151a5fd 100644 --- a/sfeed_stats.c +++ b/sfeed_stats.c @@ -1,4 +1,5 @@ #include <ctype.h> +#include <err.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> @@ -10,22 +11,6 @@ static struct feed *feeds = NULL; /* start of feeds linked-list. */ static char *line = NULL; -static void -cleanup(void) -{ - free(line); /* free line */ - line = NULL; - feedsfree(feeds); /* free feeds linked-list */ -} - -/* print error message to stderr */ -static void -die(const char *s) -{ - fprintf(stderr, "sfeed_stats: %s\n", s); - exit(EXIT_FAILURE); -} - int main(void) { @@ -36,11 +21,10 @@ main(void) time_t parsedtime, comparetime, timenewest = 0; size_t size = 0; - atexit(cleanup); comparetime = time(NULL) - (3600 * 24); /* 1 day is old news */ if(!(fcur = calloc(1, sizeof(struct feed)))) - die("can't allocate enough memory"); + err(1, "calloc"); feeds = fcur; while(parseline(&line, &size, fields, FieldLast, '\t', stdin) > 0) { @@ -52,7 +36,7 @@ main(void) /* first of feed section or new feed section. */ if(!totalfeeds || (fcur && strcmp(fcur->name, fields[FieldFeedName]))) { if(!(f = calloc(1, sizeof(struct feed)))) - die("can't allocate enough memory"); + err(1, "calloc"); if(totalfeeds) { /* end previous one. */ fcur->next = f; fcur = f; @@ -73,7 +57,7 @@ main(void) /* TODO: memcpy and make fcur->name static? */ if(!(fcur->name = strdup(fields[FieldFeedName]))) - die("can't allocate enough memory"); + err(1, "strdup"); totalfeeds++; } @@ -95,5 +79,5 @@ main(void) printf(" ================================\n"); printf("%c %-20.20s [%4lu/%-4lu] %s\n", totalnew > 0 ? 'N' : ' ', "Total:", totalnew, totalitems, timenewestformat); - return EXIT_SUCCESS; + return 0; } |