From fc51ac87a52f859af5084e1abf3ab7d346f0cc20 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 4 Mar 2016 12:14:29 +0100 Subject: sfeed_frames: use mkdir and check errno EEXIST no need to stat and then mkdir, this is a (theoretical) race-condition too. --- sfeed_frames.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sfeed_frames.c b/sfeed_frames.c index 6edf3c9..06d2c0d 100644 --- 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 */ -- cgit v1.2.3