37 int mkdir_r(
const char *
const pathname)
46 if (strlen(pathname) >= PATH_MAX - 2)
49 strncpy(tmp, pathname,
sizeof(tmp) - 1);
50 tmp[PATH_MAX - 1] =
'\0';
52 const int len =
CAST_S32(strlen(tmp));
54 if (len < 1 || len >= INT_MAX)
58 if (tmp[len - 1] !=
'/')
64 for (p = tmp; *p; p++)
66 if (*p ==
'/' || *p ==
'\\')
77 char *p2 = tmp2 + strlen(tmp2) - 1;
78 if (*p2 ==
'/' || *p2 ==
'\\')
82 if (!stat(tmp2, &statbuf))
84 if (S_ISDIR(statbuf.st_mode))
93 if (!CreateDirectory(tmp2,
nullptr))
97 if (!(strlen(tmp2) == 2 && !strcmp(tmp2 + 1,
":")))
111 if (pathname ==
nullptr)
114 const size_t len =
CAST_SIZE(strlen(pathname));
115 char *tmp =
new char[len + 2];
118 strcpy(tmp, pathname);
121 if (tmp[len - 1] !=
'/')
127 for (p = tmp; *p != 0; p++)
141 if (stat(tmp, &statbuf) == 0)
143 if (S_ISDIR(statbuf.st_mode))
155 if (
mkdir(tmp, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
int mkdir_r(const char *const pathname)
Create a directory, making leading components first if necessary.
bool mkdir(const std::string &dirname)