sfeed

simple feed reader - forked from git.codemadness.org/sfeed
git clone git://src.gearsix.net/sfeed
Log | Files | Refs | Atom | README | LICENSE

commit 4e505a8eccafe3defaf0e491ec6c347ee0e87830
parent f4b0df7bfe0f4016bb2d3ff90f36f00b76a02f57
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun, 28 Feb 2016 18:49:06 +0100

sfeed_frames: fix open file permission (write only).

check errno EEXIST (file exist? -> ignore), handle other errno codes as errors.

... also make sure to fflush write before modifying file access and modification
timestamps or it will be overwritten again.

Diffstat:
Msfeed_frames.c | 11++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/sfeed_frames.c b/sfeed_frames.c @@ -155,11 +155,11 @@ printfeed(FILE *fpitems, FILE *fpin, struct feed *f) strtotime(fields[FieldUnixTimestamp], &parsedtime); /* content file doesn't exist yet and has write access */ - if ((fd = open(filepath, O_CREAT | O_EXCL)) == -1) { - if (errno == EACCES) + if ((fd = open(filepath, O_CREAT | O_EXCL | O_WRONLY)) == -1) { + if (errno != EEXIST) err(1, "open: %s", filepath); } else { - if (!(fpcontent = fdopen(fd, "w+b"))) + if (!(fpcontent = fdopen(fd, "wb"))) err(1, "fdopen: %s", filepath); fputs("<html><head>" "<link rel=\"stylesheet\" type=\"text/css\" href=\"../../style.css\" />" @@ -185,6 +185,11 @@ printfeed(FILE *fpitems, FILE *fpin, struct feed *f) /* set modified and access time of file to time of item. */ if (parsedtime) { + /* flush writes before setting atime and mtime + else the remaining (buffered) write can occur at + fclose() and overwrite our time again. */ + fflush(fpcontent); + times[0].tv_sec = parsedtime; times[1].tv_sec = parsedtime;