From d6c3b1b3269543f9c052fd61d3720f6e63898f8f Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Sun, 24 Feb 2013 09:32:27 +0100 Subject: [PATCH] Doesn't use access to check if a directory exists. --- util.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/util.c b/util.c index 59f35f53..c4e13f1b 100644 --- a/util.c +++ b/util.c @@ -678,9 +678,14 @@ int mkancestor(const char* file) return 0; } - if (access(dir, F_OK) == 0) { - /* the directory/file exists */ - return 0; + /* try creating it */ + if (mkdir(dir, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) != 0) { + /* if it already exists, we are done */ + if (errno == EEXIST) { + return 0; + } + fprintf(stderr, "Error creating directory '%s'. %s.\n", dir, strerror(errno)); + return -1; } /* recursively create them all */ @@ -693,7 +698,7 @@ int mkancestor(const char* file) fprintf(stderr, "Error creating directory '%s'. %s.\n", dir, strerror(errno)); return -1; } - + return 0; }