diff options
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | sfeed.c | 7 | ||||
-rw-r--r-- | util.c | 49 |
3 files changed, 9 insertions, 49 deletions
@@ -9,3 +9,5 @@ bugs?: [ ] flabber link is broken (flabberc2 feedname). [ ] feeds file: empty tab (encoding cant be detected?) + +[ ] optimize afgets() @@ -402,7 +402,7 @@ tmtotime(struct tm *tm) { } static time_t -parsetime(const char *s, char *buf) { +parsetime(const char *s, char *buf, size_t bufsiz) { struct tm tm; char tz[64]; const char *end; @@ -414,7 +414,7 @@ parsetime(const char *s, char *buf) { offset = gettimetz(end, tz, sizeof(tz) - 1); /* TODO: use snprintf(): make sure *printf can't overflow */ if(buf) - sprintf(buf, "%04d-%02d-%02d %02d:%02d:%02d %-.16s", + snprintf(buf, bufsiz, "%04d-%02d-%02d %02d:%02d:%02d %-.16s", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, tz); /* return UNIX time, reverse offset to GMT+0 */ @@ -683,7 +683,8 @@ xml_handler_end_element(XMLParser *p, const char *name, size_t namelen, int issh (feeditem.feedtype == FeedTypeRSS && istag(name, namelen, "item", strlen("item")))) /* RSS */ { - printf("%ld", (long)parsetime((&feeditem.timestamp)->data, timebuf)); + printf("%ld", (long)parsetime((&feeditem.timestamp)->data, + timebuf, sizeof(timebuf))); putchar(FieldSeparator); fputs(timebuf, stdout); putchar(FieldSeparator); @@ -7,47 +7,6 @@ #include "util.h" -#if 0 -/* TODO: optimize */ -char * -afgets(char **p, size_t *size, FILE *fp) { - char buf[BUFSIZ], *alloc = NULL; - size_t n, len = 0, allocsiz; - int end = 0; - - while(fgets(buf, sizeof(buf), fp)) { - n = strlen(buf); - if(buf[n - 1] == '\n') { /* dont store newlines. */ - buf[n - 1] = '\0'; - n--; - end = 1; /* newline found, end */ - } - len += n; - allocsiz = len + 1; - if(allocsiz > *size) { - if((alloc = realloc(*p, allocsiz))) { - *p = alloc; - *size = allocsiz; - } else { - free(*p); - *p = NULL; - fputs("error: could not realloc\n", stderr); - exit(EXIT_FAILURE); - return NULL; - } - } - strncpy((*p + (len - n)), buf, n); - if(end || feof(fp)) - break; - } - if(*p && len > 0) { - (*p)[len] = '\0'; - return *p; - } - return NULL; -} -#endif - /* * Taken from OpenBSD. * Copy src to string dst of size siz. At most siz-1 characters @@ -77,7 +36,6 @@ strlcpy(char *dst, const char *src, size_t siz) { return(s - src - 1); /* count does not include NUL */ } -/* TODO: optimize */ char * afgets(char **p, size_t *size, FILE *fp) { char buf[BUFSIZ], *alloc = NULL; @@ -105,8 +63,7 @@ afgets(char **p, size_t *size, FILE *fp) { return NULL; } } - strlcpy((*p + (len - n)), buf, n + 1); /* TODO: dont depend on strlcpy */ -/* strncpy((*p + (len - n)), buf, n);*/ + strlcpy((*p + (len - n)), buf, n + 1); } if(*p && len > 0) { (*p)[len] = '\0'; @@ -194,9 +151,9 @@ feedsfree(struct feed *f) { for(; f; f = next) { next = f->next; - /*f->next = NULL;*/ + f->next = NULL; free(f->name); - /*f->name = NULL;*/ + f->name = NULL; free(f); } } |