5b8e31b8d0b4e44623360fa68fa67288ba4a923d
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2011 - 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>
35 * Return pointer to home directory path using the env variable HOME.
36 * No home, NULL is returned.
38 const char *get_home_dir(void)
40 return ((const char *) getenv("HOME"));
46 * Create recursively directory using the FULL path.
48 int mkdir_recursive(const char *path
, mode_t mode
, uid_t uid
, gid_t gid
)
51 char *p
, tmp
[PATH_MAX
];
55 ret
= snprintf(tmp
, sizeof(tmp
), "%s", path
);
57 perror("snprintf mkdir");
62 if (tmp
[len
- 1] == '/') {
67 for (p
= tmp
+ 1; *p
; p
++) {
70 ret
= mkdir(tmp
, mode
);
72 if (!(errno
== EEXIST
)) {
73 perror("mkdir recursive");
77 } else if (ret
== 0) {
79 * We created the directory. Set its
80 * ownership to the user/group
83 ret
= chown(tmp
, uid
, gid
);
85 perror("chown in mkdir recursive");
94 ret
= mkdir(tmp
, mode
);
97 } else if (ret
== 0) {
99 * We created the directory. Set its ownership to the
100 * user/group specified.
102 ret
= chown(tmp
, uid
, gid
);
104 perror("chown in mkdir recursive");
This page took 0.034457 seconds and 3 git commands to generate.