summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNitroretro <nitroretro@protonmail.com>2019-12-24 10:10:58 +0200
committerLukas Fleischer <lfleischer@calcurse.org>2019-12-29 13:22:57 +0100
commit002cf305a59d311d1dc3806009ecae90a5d9be38 (patch)
treeb6e1ecaa8315852405fb4ae693969ed3f42efa36 /src
parent0cd8c210bd50837d896054e9fb1198175cd3316a (diff)
downloadcalcurse-002cf305a59d311d1dc3806009ecae90a5d9be38.tar.gz
calcurse-002cf305a59d311d1dc3806009ecae90a5d9be38.zip
Optimize error handling in io_check_dir()
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src')
-rw-r--r--src/io.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/io.c b/src/io.c
index 6488401..76d4490 100644
--- a/src/io.c
+++ b/src/io.c
@@ -1084,17 +1084,15 @@ int io_check_dir(const char *dir)
char *path = mem_strdup(dir);
char *index;
- int existed = 1;
+ int existed = 1, failed = 0;
errno = 0;
for (index = path + 1; *index; index++) {
if (*index == '/') {
*index = '\0';
if (mkdir(path, 0700) != 0) {
if (errno != EEXIST) {
- fprintf(stderr,
- _("FATAL ERROR: could not create %s: %s\n"),
- path, strerror(errno));
- exit_calcurse(EXIT_FAILURE);
+ failed = 1;
+ break;
}
} else {
existed = 0;
@@ -1103,17 +1101,20 @@ int io_check_dir(const char *dir)
}
}
- if (mkdir(path, 0700) != 0) {
- if (errno != EEXIST) {
- fprintf(stderr,
- _("FATAL ERROR: could not create %s: %s\n"),
- path, strerror(errno));
- exit_calcurse(EXIT_FAILURE);
- }
+ if (!failed && mkdir(path, 0700) != 0) {
+ if (errno != EEXIST)
+ failed = 1;
} else {
existed = 0;
}
+ if(failed) {
+ fprintf(stderr,
+ _("FATAL ERROR: could not create %s: %s\n"),
+ path, strerror(errno));
+ exit_calcurse(EXIT_FAILURE);
+ }
+
mem_free(path);
return existed;
}