diff --git a/src/basedir.c b/src/basedir.c index 852fc7b..747bcfa 100644 --- a/src/basedir.c +++ b/src/basedir.c @@ -496,16 +496,19 @@ int xdgMakePath(const char * path, mode_t mode) if (tmpPath[length-1] == DIR_SEPARATOR_CHAR) tmpPath[length-1] = '\0'; - for (tmpPtr = tmpPath; *tmpPtr; ++tmpPtr) + /* skip tmpPath[0] since if it's a seperator we have an absolute path */ + for (tmpPtr = tmpPath+1; *tmpPtr; ++tmpPtr) { if (*tmpPtr == DIR_SEPARATOR_CHAR) { *tmpPtr = '\0'; if (mkdir(tmpPath, mode) == -1) { - /* here mkdir will have already set errno */ - free(tmpPath); - return -1; + if (errno != EEXIST) + { + free(tmpPath); + return -1; + } } *tmpPtr = DIR_SEPARATOR_CHAR; }