brewco/futil.c

changeset 409
cdf68044adaf
child 441
bde74a8f2ad7
equal deleted inserted replaced
408:ec507c1f1df7 409:cdf68044adaf
1 /*****************************************************************************
2 * Copyright (C) 2015
3 *
4 * Michiel Broek <mbroek at mbse dot eu>
5 *
6 * This file is part of the mbsePi-apps
7 *
8 * This is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version.
12 *
13 * mbsePi-apps is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with ThermFerm; see the file COPYING. If not, write to the Free
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *****************************************************************************/
22
23 #include "brewco.h"
24 #include "futil.h"
25
26
27 /*
28 * Make directory tree, the name must end with a /
29 */
30 int mkdirs(char *name, mode_t mode)
31 {
32 char buf[PATH_MAX], *p, *q;
33 int last = 0, oldmask;
34
35 memset(&buf, 0, sizeof(buf));
36 strncpy(buf, name, sizeof(buf)-1);
37 buf[sizeof(buf)-1] = '\0';
38
39 p = buf+1;
40
41 oldmask = umask(000);
42 while ((q = strchr(p, '/'))) {
43 *q = '\0';
44 mkdir(buf, mode);
45 last = errno;
46 *q = '/';
47 p = q+1;
48 }
49
50 umask(oldmask);
51
52 if ((last == 0) || (last == EEXIST)) {
53 return TRUE;
54 } else {
55 syslog(LOG_NOTICE, "mkdirs(%s)", name);
56 return FALSE;
57 }
58 }
59
60

mercurial