summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2014-04-02 22:46:45 +0200
committerHiltjo Posthuma <hiltjo@codemadness.org>2014-04-02 22:46:45 +0200
commitcad00e1a8b11b59e996e1d5c95092dd17274ae5d (patch)
treea75edd1921bcf9df59935c10f85267aaac2f5f61
parent87c760ca74fc5e6c296af0463f9d9d64072210d5 (diff)
sfeed_frames: just use snprintf and strlcpy, mmmkay
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
-rw-r--r--sfeed_frames.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/sfeed_frames.c b/sfeed_frames.c
index 405d990..f37812f 100644
--- a/sfeed_frames.c
+++ b/sfeed_frames.c
@@ -115,16 +115,16 @@ main(int argc, char **argv) {
mkdir(basepath, S_IRWXU);
/* write main index page */
- if(basepathlen + strlen("/index.html") < sizeof(dirpath) - 1)
- sprintf(dirpath, "%s/index.html", basepath);
+/* if(basepathlen + strlen("/index.html") < sizeof(dirpath) - 1)*/
+ snprintf(dirpath, sizeof(dirpath), "%s/index.html", basepath);
if(!(fpindex = fopen(dirpath, "w+b")))
die("can't write index.html");
- if(basepathlen + strlen("/menu.html") < sizeof(dirpath) - 1)
- sprintf(dirpath, "%s/menu.html", basepath);
+/* if(basepathlen + strlen("/menu.html") < sizeof(dirpath) - 1)*/
+ snprintf(dirpath, sizeof(dirpath), "%s/menu.html", basepath);
if(!(fpmenu = fopen(dirpath, "w+b")))
die("can't write menu.html");
- if(basepathlen + strlen("/items.html") < sizeof(dirpath) - 1)
- sprintf(dirpath, "%s/items.html", basepath);
+/* if(basepathlen + strlen("/items.html") < sizeof(dirpath) - 1)*/
+ snprintf(dirpath, sizeof(dirpath), "%s/items.html", basepath);
if(!(fpitems = fopen(dirpath, "w+b")))
die("can't write items.html");
fputs("<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"../style.css\" />"
@@ -155,8 +155,8 @@ main(int argc, char **argv) {
if(!(namelen = makepathname(name, sizeof(name) - 1, fields[FieldFeedName])))
continue;
- if(basepathlen + namelen + 1 < sizeof(dirpath) - 1)
- sprintf(dirpath, "%s/%s", basepath, name);
+/* if(basepathlen + namelen + 1 < sizeof(dirpath) - 1)*/
+ snprintf(dirpath, sizeof(dirpath), "%s/%s", basepath, name);
/* TODO: handle error. */
if(stat(dirpath, &st) == -1) {
if(mkdir(dirpath, S_IRWXU) == -1) {
@@ -166,10 +166,11 @@ main(int argc, char **argv) {
}
/* TODO: test, replaces strncpy (strncpy is slow) */
reldirpath[0] = '\0';
- if(namelen < sizeof(reldirpath) - 2) {
- memcpy(reldirpath, name, namelen + 1); /* copy including nul byte */
+/* if(namelen < sizeof(reldirpath) - 2) {*/
+ strlcpy(reldirpath, name, sizeof(reldirpath));
+ /*memcpy(reldirpath, name, namelen + 1);*/ /* copy including nul byte */
/* reldirpath[namelen] = '\0';*/
- }
+/* }*/
/* strncpy(reldirpath, name, sizeof(reldirpath) - 1);*/
@@ -218,10 +219,10 @@ main(int argc, char **argv) {
/* write content */
if(!(namelen = makepathname(name, sizeof(name), fields[FieldTitle])))
continue;
- if(strlen(dirpath) + namelen + strlen("/.html") < sizeof(filepath) - 1)
- sprintf(filepath, "%s/%s.html", dirpath, name);
- if(strlen(reldirpath) + namelen + strlen("/.html") < sizeof(relfilepath) - 1)
- sprintf(relfilepath, "%s/%s.html", reldirpath, name);
+/* if(strlen(dirpath) + namelen + strlen("/.html") < sizeof(filepath) - 1)*/
+ snprintf(filepath, sizeof(filepath), "%s/%s.html", dirpath, name);
+/* if(strlen(reldirpath) + namelen + strlen("/.html") < sizeof(relfilepath) - 1)*/
+ snprintf(relfilepath, sizeof(relfilepath), "%s/%s.html", reldirpath, name);
if(!fileexists(filepath) && (fpcontent = fopen(filepath, "w+b"))) {
fputs("<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"../../style.css\" />"
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /></head>\n"