Mirror of git://git.busybox.net/busybox with our patches on top
Source
/* vi: set sw=4 ts=4: */
/*
* parse_mode implementation for busybox
*
* Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org>
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* Mar 5, 2003 Manuel Novoa III
*
* This is the main work function for the 'mkdir' applet. As such, it
* strives to be SUSv3 compliant in it's behaviour when recursively
* making missing parent dirs, and in it's mode setting of the final
* directory 'path'.
*
* To recursively build all missing intermediate directories, make
* sure that (flags & FILEUTILS_RECUR) is non-zero. Newly created
* intermediate directories will have at least u+wx perms.
*
* To set specific permissions on 'path', pass the appropriate 'mode'
* val. Otherwise, pass -1 to get default permissions.
*/
/* This function is used from NOFORK applets. It must not allocate anything */
int FAST_FUNC bb_make_directory(char *path, long mode, int flags)
{
mode_t cur_mask;
mode_t org_mask;
const char *fail_msg;
char *s;
char c;
struct stat st;
/* "path" can be a result of dirname().
* dirname("no_slashes") returns ".", possibly read-only.
* musl dirname() can return read-only "/" too.
* We need writable string. And for "/", "." (and ".."?)
* nothing needs to be created anyway.
*/
if (LONE_CHAR(path, '/'))
return 0;
if (path[0] == '.') {
if (path[1] == '\0')
return 0; /* "." */
// if (path[1] == '.' && path[2] == '\0')
// return 0; /* ".." */
}
org_mask = cur_mask = (mode_t)-1L;
s = path;
while (1) {
c = '\0';
if (flags & FILEUTILS_RECUR) { /* Get the parent */
/* Bypass leading non-'/'s and then subsequent '/'s */
while (*s) {
if (*s == '/') {
do {
++s;