Loading...
--- Libc/Libc-1725.40.4/util/mkpath_np.c
+++ Libc/Libc-997.90.3/util/mkpath_np.c
@@ -26,10 +26,19 @@
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
-#include <fcntl.h>
-
-static int
-_mkpath(int dfd, const char *path, mode_t omode, const char ** firstdir)
+
+/* This extended version of mkpath_np is provided to help NSFileManager
+ * maintain binary compatibility. If firstdir is not NULL, *firstdir will be
+ * set to the path of the first created directory, and it is the caller's
+ * responsibility to free the returned string. This SPI is subject to removal
+ * once NSFileManager no longer has a need for it, and use in new code is
+ * highly discouraged.
+ *
+ * See: <rdar://problem/9888987>
+ */
+
+int
+_mkpath_np(const char *path, mode_t omode, const char ** firstdir)
{
char *apath = NULL, *opath = NULL, *s, *sn, *sl;
unsigned int depth = 0;
@@ -39,7 +48,7 @@
struct stat sbuf;
/* Try the trivial case first. */
- if (0 == mkdirat(dfd, path, omode)) {
+ if (0 == mkdir(path, omode)) {
if (firstdir) {
*firstdir = strdup(path);
}
@@ -54,7 +63,7 @@
case ENOENT:
break;
case EEXIST:
- if (fstatat(dfd, path, &sbuf, 0) == 0) {
+ if (stat(path, &sbuf) == 0) {
if (S_ISDIR(sbuf.st_mode)) {
retval = EEXIST;
} else {
@@ -98,7 +107,7 @@
}
/* Retry the trivial case after having stripped of trailing /. <rdar://problem/14351794> */
- if (0 == mkdirat(dfd, path, omode)) {
+ if (0 == mkdir(path, omode)) {
if (firstdir) {
*firstdir = strdup(path);
}
@@ -118,7 +127,7 @@
*s = '\0';
depth++;
- if (0 == mkdirat(dfd, apath, S_IRWXU | S_IRWXG | S_IRWXO)) {
+ if (0 == mkdir(apath, S_IRWXU | S_IRWXG | S_IRWXO)) {
/* Found our starting point */
/* POSIX 1003.2:
@@ -131,7 +140,7 @@
*/
struct stat dirstat;
- if (-1 == fstatat(dfd, apath, &dirstat, 0)) {
+ if (-1 == stat(apath, &dirstat)) {
/* Really unfortunate timing ... */
retval = ENOENT;
goto mkpath_exit;
@@ -139,7 +148,7 @@
if ((dirstat.st_mode & (S_IWUSR | S_IXUSR)) != (S_IWUSR | S_IXUSR)) {
chmod_mode = dirstat.st_mode | S_IWUSR | S_IXUSR;
- if (-1 == fchmodat(dfd, apath, chmod_mode, 0)) {
+ if (-1 == chmod(apath, chmod_mode)) {
/* Really unfortunate timing ... */
retval = ENOENT;
goto mkpath_exit;
@@ -155,7 +164,7 @@
* before we did. We will use this as our starting point.
* See: <rdar://problem/10279893>
*/
- if (fstatat(dfd, apath, &sbuf, 0) == 0 &&
+ if (stat(apath, &sbuf) == 0 &&
S_ISDIR(sbuf.st_mode)) {
if (firstdir) {
@@ -178,7 +187,7 @@
*s = '/';
depth--;
- if (-1 == mkdirat(dfd, apath, S_IRWXU | S_IRWXG | S_IRWXO)) {
+ if (-1 == mkdir(apath, S_IRWXU | S_IRWXG | S_IRWXO)) {
/* This handles "." and ".." added to the new section of path */
if (errno == EEXIST)
continue;
@@ -187,7 +196,7 @@
}
if (chmod_mode) {
- if (-1 == fchmodat(dfd, apath, chmod_mode, 0)) {
+ if (-1 == chmod(apath, chmod_mode)) {
/* Really unfortunate timing ... */
retval = ENOENT;
goto mkpath_exit;
@@ -195,10 +204,10 @@
}
}
- if (-1 == mkdirat(dfd, path, omode)) {
+ if (-1 == mkdir(path, omode)) {
retval = errno;
if (errno == EEXIST &&
- fstatat(dfd, path, &sbuf, 0) == 0 &&
+ stat(path, &sbuf) == 0 &&
!S_ISDIR(sbuf.st_mode)) {
retval = ENOTDIR;
}
@@ -212,25 +221,6 @@
return retval;
}
-/* This extended version of mkpath_np is provided to help NSFileManager
- * maintain binary compatibility. If firstdir is not NULL, *firstdir will be
- * set to the path of the first created directory, and it is the caller's
- * responsibility to free the returned string. This SPI is subject to removal
- * once NSFileManager no longer has a need for it, and use in new code is
- * highly discouraged.
- *
- * See: <rdar://problem/9888987>
- */
-
-int
-_mkpath_np(const char *path, mode_t omode, const char ** firstdir) {
- return _mkpath(AT_FDCWD, path, omode, firstdir);
+int mkpath_np(const char *path, mode_t omode) {
+ return _mkpath_np(path, omode, NULL);
}
-
-int mkpath_np(const char *path, mode_t omode) {
- return _mkpath(AT_FDCWD, path, omode, NULL);
-}
-
-int mkpathat_np(int dfd, const char *path, mode_t omode) {
- return _mkpath(dfd, path, omode, NULL);
-}