X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udev_utils_file.c;h=ba70b6b395f95d42b43a05401751a0be157b14f2;hp=9bf60696d94ed74d9ddd79d5b854e918154dc1c2;hb=a7e2961c0f6dfb50bed2c66f30c4be16cadfa088;hpb=27b77df44daebbd7597c572343105c16de099233 diff --git a/udev_utils_file.c b/udev_utils_file.c index 9bf60696d..ba70b6b39 100644 --- a/udev_utils_file.c +++ b/udev_utils_file.c @@ -36,14 +36,13 @@ int create_path(const char *path) char *pos; struct stat stats; - strcpy (p, path); + strlcpy(p, path, sizeof(p)); pos = strrchr(p, '/'); if (pos == p || pos == NULL) return 0; while (pos[-1] == '/') pos--; - pos[0] = '\0'; dbg("stat '%s'\n", p); @@ -54,7 +53,12 @@ int create_path(const char *path) return -1; dbg("mkdir '%s'\n", p); - return mkdir(p, 0755); + if (mkdir(p, 0755) == 0) + return 0; + if (errno == EEXIST) + if (stat(p, &stats) == 0 && (stats.st_mode & S_IFMT) == S_IFDIR) + return 0; + return -1; } int delete_path(const char *path) @@ -65,6 +69,9 @@ int delete_path(const char *path) strcpy (p, path); pos = strrchr(p, '/'); + if (pos == p || pos == NULL) + return 0; + while (1) { *pos = '\0'; pos = strrchr(p, '/');