1 /* vi: set sw=4 ts=4: */
3 * Mini make_directory implementation for busybox
5 * Copyright (C) 2001 Matt Kraai.
8 * Copyright (C) 2002 Glenn McGrath
9 * Copyright (C) 2002 Vladimir N. Oleynik
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include <sys/types.h>
37 /* Create the directory PATH with mode MODE, or the default if MODE is -1.
38 * Also create parent directories as necessary if flags contains
41 int make_directory (char *path, long mode, int flags)
45 if (flags == FILEUTILS_RECUR) {
46 char *pp = strrchr(path, '/');
47 if ((pp) && (pp != path)) {
49 make_directory(path, -1, flags);
56 char *pp = strrchr(path, '/');
58 statbuf.st_mode = 0777;
60 /* stat the directory */
61 if ((pp) && (pp != path)) {
67 mode = statbuf.st_mode;
70 ret = mkdir(path, mode);
72 if ((flags == FILEUTILS_RECUR) && (errno == EEXIST)) {
75 perror_msg_and_die("Cannot create directory '%s'", path);