X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udev_utils_file.c;h=0ceefe17200c68bab8e08a20b0d3be2dc60834ee;hp=e4d5802ff899824b6960a7369e150108c6d66dd9;hb=9138bcba99ebf0498a43b106100cb0ffd3dc222e;hpb=27d4bf1817259873b0a1e118d03978f0d2f2595e diff --git a/udev_utils_file.c b/udev_utils_file.c index e4d5802ff..0ceefe172 100644 --- a/udev_utils_file.c +++ b/udev_utils_file.c @@ -36,25 +36,29 @@ 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); + dbg("stat '%s'", p); if (stat(p, &stats) == 0 && (stats.st_mode & S_IFMT) == S_IFDIR) return 0; - if (create_path (p) != 0) + if (create_path(p) != 0) return -1; - dbg("mkdir '%s'\n", p); - return mkdir(p, 0755); + dbg("mkdir '%s'", p); + 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)