2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; only version 2 of the License.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16 * Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include <sys/types.h>
34 * Write to writable pipe used to notify a thread.
36 int notify_thread_pipe(int wpipe
)
40 ret
= write(wpipe
, "!", 1);
42 PERROR("write poll pipe");
49 * Return pointer to home directory path using the env variable HOME.
51 * No home, NULL is returned.
53 const char *get_home_dir(void)
55 return ((const char *) getenv("HOME"));
59 * Create recursively directory using the FULL path.
61 int mkdir_recursive(const char *path
, mode_t mode
, uid_t uid
, gid_t gid
)
64 char *p
, tmp
[PATH_MAX
];
68 ret
= snprintf(tmp
, sizeof(tmp
), "%s", path
);
70 PERROR("snprintf mkdir");
75 if (tmp
[len
- 1] == '/') {
80 for (p
= tmp
+ 1; *p
; p
++) {
83 ret
= mkdir(tmp
, mode
);
85 if (!(errno
== EEXIST
)) {
86 PERROR("mkdir recursive");
90 } else if (ret
== 0) {
92 * We created the directory. Set its ownership to the
93 * user/group specified.
95 ret
= chown(tmp
, uid
, gid
);
97 PERROR("chown in mkdir recursive");
106 ret
= mkdir(tmp
, mode
);
108 if (!(errno
== EEXIST
)) {
109 PERROR("mkdir recursive last piece");
114 } else if (ret
== 0) {
116 * We created the directory. Set its ownership to the user/group
119 ret
= chown(tmp
, uid
, gid
);
121 PERROR("chown in mkdir recursive");
This page took 0.032687 seconds and 5 git commands to generate.