Thu, 10 Dec 2015 15:58:01 +0100
Manual mode added.
420
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | /***************************************************************************** |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | * Copyright (C) 2014 |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
3 | * |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | * Michiel Broek <mbroek at mbse dot eu> |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | * |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
6 | * This file is part of the mbsePi-apps |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | * |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | * This is free software; you can redistribute it and/or modify it |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
9 | * under the terms of the GNU General Public License as published by the |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | * Free Software Foundation; either version 2, or (at your option) any |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
11 | * later version. |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
12 | * |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | * mbsePi-apps is distributed in the hope that it will be useful, but |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
16 | * General Public License for more details. |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
17 | * |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | * You should have received a copy of the GNU General Public License |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
19 | * along with ThermFerm; see the file COPYING. If not, write to the Free |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
20 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
21 | *****************************************************************************/ |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
22 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
23 | #include "brewpanel.h" |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
24 | #include "futil.h" |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
25 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
26 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
27 | /* |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
28 | * Make directory tree, the name must end with a / |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
29 | */ |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
30 | int mkdirs(char *name, mode_t mode) |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
31 | { |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
32 | char buf[PATH_MAX], *p, *q; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
33 | int last = 0, oldmask; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
34 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
35 | memset(&buf, 0, sizeof(buf)); |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
36 | strncpy(buf, name, sizeof(buf)-1); |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
37 | buf[sizeof(buf)-1] = '\0'; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
38 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
39 | p = buf+1; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
40 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
41 | oldmask = umask(000); |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
42 | while ((q = strchr(p, '/'))) { |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
43 | *q = '\0'; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
44 | mkdir(buf, mode); |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
45 | last = errno; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
46 | *q = '/'; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
47 | p = q+1; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
48 | } |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
49 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
50 | umask(oldmask); |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
51 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
52 | if ((last == 0) || (last == EEXIST)) { |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
53 | return TRUE; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
54 | } else { |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
55 | syslog(LOG_NOTICE, "mkdirs(%s)", name); |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
56 | return FALSE; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
57 | } |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
58 | } |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
59 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
60 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
61 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
62 | /* |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
63 | * Test if the given file exists. The second option is: |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
64 | * R_OK - test for Read rights |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
65 | * W_OK - test for Write rights |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
66 | * X_OK - test for eXecute rights |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
67 | * F_OK - test file presence only |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
68 | */ |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
69 | int file_exist(char *path, int mode) |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
70 | { |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
71 | if (access(path, mode) != 0) |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
72 | return errno; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
73 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
74 | return 0; |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
75 | } |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
76 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
77 | |
644a6106d712
The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
78 |