diff options
author | Hiltjo Posthuma <hiltjo@codemadness.org> | 2015-01-05 12:16:00 +0100 |
---|---|---|
committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2015-01-05 12:16:00 +0100 |
commit | 319522e3d61eb28fe990a9c900d0193cb296b2df (patch) | |
tree | bc702ae137c58999996c653ae55db12beed2a0be | |
parent | fbb61c843fdd7444adc33d2ac27dfcf02d73faf0 (diff) |
sfeed_frames: improve makepathname, cleanup
-rw-r--r-- | sfeed_frames.c | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/sfeed_frames.c b/sfeed_frames.c index 9152cb7..ae4aa12 100644 --- a/sfeed_frames.c +++ b/sfeed_frames.c @@ -94,26 +94,29 @@ printcontent(const char *s, FILE *fp) } } -/* TODO: bufsiz - 1 ? */ static size_t -makepathname(const char *path, char *buffer, size_t bufsiz) +makepathname(const char *path, char *buf, size_t bufsiz) { size_t i = 0, r = 0; - for(; *path && i < bufsiz - 1; path++) { + for(; *path && i < bufsiz; path++) { if(isalpha((int)*path) || isdigit((int)*path)) { - buffer[i++] = tolower((int)*path); + buf[i++] = tolower((int)*path); r = 0; } else { - if(!r) /* don't repeat '-'. */ - buffer[i++] = '-'; + /* don't repeat '-'. */ + if(!r) + buf[i++] = '-'; r++; } } - buffer[i] = '\0'; - /* remove trailing - */ - for(; i > 0 && (buffer[i] == '-' || buffer[i] == '\0'); i--) - buffer[i] = '\0'; + /* remove trailing '-' */ + for(; i > 0 && (buf[i - 1] == '-'); i--) + ; + + if(bufsiz > 0) + buf[i] = '\0'; + return i; } @@ -131,15 +134,14 @@ main(int argc, char *argv[]) time_t parsedtime, comparetime; size_t linesize = 0, namelen, basepathlen; struct stat st; - struct utimbuf contenttime; int r; - memset(&contenttime, 0, sizeof(contenttime)); - if(argc > 1 && argv[1][0] != '\0') basepath = argv[1]; - comparetime = time(NULL) - (3600 * 24); /* 1 day is old news */ + /* 1 day is old news */ + comparetime = time(NULL) - 86400; + basepathlen = strlen(basepath); if(basepathlen > 0) mkdir(basepath, S_IRWXU); |