use libjson-c-dev
[ptask-pkg-ubuntu.git] / src / pio.c
1 /*
2  * Copyright (C) 2011-2014 jeanfi@gmail.com
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301 USA
18  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <sys/stat.h>
24
25 #include <pio.h>
26
27 /* Directory separator is \ when cross-compiling for MS Windows
28    systems */
29 #if defined(__MINGW32__)
30 #define DIRSEP ('\\')
31 #else
32 #define DIRSEP '/'
33 #endif
34
35 void mkdirs(const char *dirs, mode_t mode)
36 {
37         char *c = (char *)dirs;
38         char *dir = malloc(strlen(dirs) + 1);
39
40         int i = 0;
41         while (*c) {
42                 if ((*c == DIRSEP || *c == '\0') && c != dirs) {
43                         strncpy(dir, dirs, i);
44                         dir[i] = '\0';
45                         mkdir(dir, mode);
46                 }
47
48                 c++;
49                 i++;
50         }
51
52         mkdir(dirs, mode);
53
54         free(dir);
55 }