comparison src/util.c @ 7612:3ae88e96dde2

[gaim-migrate @ 8236] This is an attempt to both fix the directory creation permissions and simplify the creation of nested directories from within gaim at the same time. If you need nested directories, simply call gaim_build_dir with the same arguments you would have given to mkdir and it will recursively create the tree for you. I spent way too much time on this. committer: Tailor Script <tailor@pidgin.im>
author Ethan Blanton <elb@pidgin.im>
date Sun, 23 Nov 2003 18:41:11 +0000
parents 54b370f7d9bf
children 48d7eea88598
comparison
equal deleted inserted replaced
7611:92d05dd1047f 7612:3ae88e96dde2
19 * You should have received a copy of the GNU General Public License 19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software 20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */ 22 */
23 #include "internal.h" 23 #include "internal.h"
24
25 #include <errno.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
24 28
25 #include "conversation.h" 29 #include "conversation.h"
26 #include "debug.h" 30 #include "debug.h"
27 #include "prpl.h" 31 #include "prpl.h"
28 #include "prefs.h" 32 #include "prefs.h"
1181 } 1185 }
1182 1186
1183 return NULL; 1187 return NULL;
1184 } 1188 }
1185 1189
1190 int gaim_build_dir (char *path, int mode)
1191 {
1192 struct stat st;
1193 char *dir, **components, delim[] = { G_DIR_SEPARATOR, '\0' };
1194 int cur, len;
1195
1196 if (path == NULL || path[0] != G_DIR_SEPARATOR)
1197 return -1;
1198
1199 dir = g_new0(char, strlen(path) + 1);
1200 components = g_strsplit(path, delim, -1);
1201 len = 0;
1202 for (cur = 0; components[cur] != NULL; cur++) {
1203 dir[len++] = G_DIR_SEPARATOR;
1204 strcpy(dir + len, components[cur]);
1205 len += strlen(components[cur]);
1206 if (stat(dir, &st) == 0) {
1207 if ((st.st_mode & S_IFMT) == S_IFDIR)
1208 continue;
1209 else {
1210 gaim_debug(GAIM_DEBUG_WARNING, "build_dir", "bad path: %s\n", path);
1211 g_strfreev(components);
1212 g_free(dir);
1213 return -1;
1214 }
1215 } else if (errno != ENOENT) {
1216 gaim_debug(GAIM_DEBUG_WARNING, "build_dir", "stat: %s\n", strerror(errno));
1217 g_strfreev(components);
1218 g_free(dir);
1219 return -1;
1220 }
1221
1222 if (mkdir(dir, mode) < 0) {
1223 gaim_debug(GAIM_DEBUG_WARNING, "build_dir", "mkdir: %s\n", strerror(errno));
1224 g_strfreev(components);
1225 g_free(dir);
1226 return -1;
1227 }
1228 }
1229
1230 g_strfreev(components);
1231 g_free(dir);
1232 return 0;
1233 }
1234
1186 /* 1235 /*
1187 * Like mkstemp() but returns a file pointer, uses a pre-set template, 1236 * Like mkstemp() but returns a file pointer, uses a pre-set template,
1188 * uses the semantics of tempnam() for the directory to use and allocates 1237 * uses the semantics of tempnam() for the directory to use and allocates
1189 * the space for the filepath. 1238 * the space for the filepath.
1190 * 1239 *