diff options
author | Kay Sievers <kay.sievers@vrfy.org> | 2007-04-12 18:55:59 +0200 |
---|---|---|
committer | Kay Sievers <kay.sievers@vrfy.org> | 2007-04-12 18:55:59 +0200 |
commit | 3a6704cba7f0e37bcb957f836fa1d5f873f20dae (patch) | |
tree | 7b7482860163ef6490c80f3ce41e2410c937dc2f | |
parent | 878645dca35c0297f1a997b6084d26534086ad35 (diff) |
create_path: don't fail if something else created the directory
Thanks to Jeremy for the patch.
-rw-r--r-- | udev_utils_file.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/udev_utils_file.c b/udev_utils_file.c index e4d5802ff8..ba70b6b395 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) |