commit fc51ac87a52f859af5084e1abf3ab7d346f0cc20
parent 9e979da3399e46e243a5dc9023a0c77e0f6377a2
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Fri, 4 Mar 2016 12:14:29 +0100
sfeed_frames: use mkdir and check errno EEXIST
no need to stat and then mkdir, this is a (theoretical) race-condition too.
Diffstat:
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/sfeed_frames.c b/sfeed_frames.c
@@ -106,7 +106,6 @@ printfeed(FILE *fpitems, FILE *fpin, struct feed *f)
char dirpath[PATH_MAX], filepath[PATH_MAX];
char *fields[FieldLast], *feedname, name[128];
ssize_t linelen;
- struct stat st;
FILE *fpcontent = NULL;
unsigned int isnew;
time_t parsedtime;
@@ -123,8 +122,8 @@ printfeed(FILE *fpitems, FILE *fpin, struct feed *f)
strlcpy(dirpath, name, sizeof(dirpath));
- /* directory doesn't exist: try to create it. */
- if (stat(dirpath, &st) == -1 && mkdir(dirpath, S_IRWXU) == -1)
+ /* error creating directory and it doesn't exist. */
+ if (mkdir(dirpath, S_IRWXU | S_IRWXG | S_IRWXO) == -1 && errno != EEXIST)
err(1, "mkdir: %s", dirpath);
/* menu if not unnamed */