4 Copyright (C) Amitay Isaacs 2014
5 Copyright (C) Martin Schwenke 2014
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, see <http://www.gnu.org/licenses/>.
25 int mkdir_p(const char *dir
, int mode
)
31 if (strcmp(dir
, "/") == 0) {
35 if (strcmp(dir
, ".") == 0) {
39 /* Try to create directory */
40 ret
= mkdir(dir
, mode
);
41 /* Succeed if that worked or if it already existed */
42 if (ret
== 0 || errno
== EEXIST
) {
45 /* Fail on anything else except ENOENT */
46 if (errno
!= ENOENT
) {
50 /* Create ancestors */
52 ret
= snprintf(t
, sizeof(t
), "%s", dir
);
58 ret
= mkdir_p(dirname(t
), mode
);
63 /* Create directory */
64 ret
= mkdir(dir
, mode
);
65 if ((ret
== -1) && (errno
== EEXIST
)) {