thermferm/futil.c

changeset 86
3d7a241329e2
child 106
1bd9a16f5061
equal deleted inserted replaced
85:c3cc6e44d1a4 86:3d7a241329e2
1 /*****************************************************************************
2 * Copyright (C) 2014
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 EC-65K; 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 "thermferm.h"
24
25
26 /*
27 * Make directory tree, the name must end with a /
28 */
29 int mkdirs(char *name, mode_t mode)
30 {
31 char buf[PATH_MAX], *p, *q;
32 int last = 0, oldmask;
33
34 memset(&buf, 0, sizeof(buf));
35 strncpy(buf, name, sizeof(buf)-1);
36 buf[sizeof(buf)-1] = '\0';
37
38 p = buf+1;
39
40 oldmask = umask(000);
41 while ((q = strchr(p, '/'))) {
42 *q = '\0';
43 mkdir(buf, mode);
44 last = errno;
45 *q = '/';
46 p = q+1;
47 }
48
49 umask(oldmask);
50
51 if ((last == 0) || (last == EEXIST)) {
52 return TRUE;
53 } else {
54 syslog(LOG_NOTICE, "mkdirs(%s)", name);
55 return FALSE;
56 }
57 }
58
59

mercurial