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
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; only version 2
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #include <sys/types.h>
33 * Write to writable pipe used to notify a thread.
35 int notify_thread_pipe(int wpipe
)
39 ret
= write(wpipe
, "!", 1);
41 perror("write poll pipe");
48 * Return pointer to home directory path using the env variable HOME.
50 * No home, NULL is returned.
52 const char *get_home_dir(void)
54 return ((const char *) getenv("HOME"));
58 * Create recursively directory using the FULL path.
60 int mkdir_recursive(const char *path
, mode_t mode
, uid_t uid
, gid_t gid
)
63 char *p
, tmp
[PATH_MAX
];
67 ret
= snprintf(tmp
, sizeof(tmp
), "%s", path
);
69 perror("snprintf mkdir");
74 if (tmp
[len
- 1] == '/') {
79 for (p
= tmp
+ 1; *p
; p
++) {
82 ret
= mkdir(tmp
, mode
);
84 if (!(errno
== EEXIST
)) {
85 perror("mkdir recursive");
89 } else if (ret
== 0) {
91 * We created the directory. Set its ownership to the
92 * user/group specified.
94 ret
= chown(tmp
, uid
, gid
);
96 perror("chown in mkdir recursive");
105 ret
= mkdir(tmp
, mode
);
108 } else if (ret
== 0) {
110 * We created the directory. Set its ownership to the user/group
113 ret
= chown(tmp
, uid
, gid
);
115 perror("chown in mkdir recursive");
This page took 0.031961 seconds and 5 git commands to generate.