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=acaffdc9181cfb9d1ea22a1da1ace59ae314faec;hb=a7e2961c0f6dfb50bed2c66f30c4be16cadfa088;hpb=1aa1e24848903d11780db1ade355be73ad61a937 diff --git a/udev_utils_file.c b/udev_utils_file.c index acaffdc91..ba70b6b39 100644 --- a/udev_utils_file.c +++ b/udev_utils_file.c @@ -1,6 +1,4 @@ /* - * udev_utils_file.c - files operations - * * Copyright (C) 2004-2005 Kay Sievers * * This program is free software; you can redistribute it and/or modify it @@ -14,7 +12,7 @@ * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., - * 675 Mass Ave, Cambridge, MA 02139, USA. + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ @@ -38,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); - if (stat (p, &stats) == 0 && (stats.st_mode & S_IFMT) == S_IFDIR) + if (stat(p, &stats) == 0 && (stats.st_mode & S_IFMT) == S_IFDIR) return 0; if (create_path (p) != 0) 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) @@ -67,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, '/');