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 * Return pointer to home directory path using the env variable HOME.
35 * No home, NULL is returned.
37 const char *get_home_dir(void)
39 return ((const char *) getenv("HOME"));
43 * Create recursively directory using the FULL path.
45 int mkdir_recursive(const char *path
, mode_t mode
, uid_t uid
, gid_t gid
)
48 char *p
, tmp
[PATH_MAX
];
52 ret
= snprintf(tmp
, sizeof(tmp
), "%s", path
);
54 perror("snprintf mkdir");
59 if (tmp
[len
- 1] == '/') {
64 for (p
= tmp
+ 1; *p
; p
++) {
67 ret
= mkdir(tmp
, mode
);
69 if (!(errno
== EEXIST
)) {
70 perror("mkdir recursive");
74 } else if (ret
== 0) {
76 * We created the directory. Set its ownership to the
77 * user/group specified.
79 ret
= chown(tmp
, uid
, gid
);
81 perror("chown in mkdir recursive");
90 ret
= mkdir(tmp
, mode
);
93 } else if (ret
== 0) {
95 * We created the directory. Set its ownership to the user/group
98 ret
= chown(tmp
, uid
, gid
);
100 perror("chown in mkdir recursive");
This page took 0.031687 seconds and 4 git commands to generate.