comparison src/util.c @ 7632:925c3ad6531b

[gaim-migrate @ 8257] if this doesn't work, I think I might cry committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Tue, 25 Nov 2003 18:56:30 +0000
parents ea2d07ad05a9
children ee6c31982350
comparison
equal deleted inserted replaced
7631:ea2d07ad05a9 7632:925c3ad6531b
1187 return NULL; 1187 return NULL;
1188 } 1188 }
1189 1189
1190 int gaim_build_dir (const char *path, int mode) 1190 int gaim_build_dir (const char *path, int mode)
1191 { 1191 {
1192 struct stat st;
1193 char *dir, **components, delim[] = { G_DIR_SEPARATOR, '\0' }; 1192 char *dir, **components, delim[] = { G_DIR_SEPARATOR, '\0' };
1194 int cur, len; 1193 int cur, len;
1195 1194
1196 if (path == NULL || path[0] != G_DIR_SEPARATOR) 1195 g_return_val_if_fail(path != NULL, -1);
1197 return -1;
1198 1196
1199 dir = g_new0(char, strlen(path) + 1); 1197 dir = g_new0(char, strlen(path) + 1);
1200 components = g_strsplit(path, delim, -1); 1198 components = g_strsplit(path, delim, -1);
1201 len = 0; 1199 len = 0;
1202 for (cur = 0; components[cur] != NULL; cur++) { 1200 for (cur = 0; components[cur] != NULL; cur++) {
1203 if(*components[cur] == '\0')
1204 continue;
1205 if(cur != 0)
1206 dir[len++] = G_DIR_SEPARATOR;
1207 strcpy(dir + len, components[cur]); 1201 strcpy(dir + len, components[cur]);
1208 len += strlen(components[cur]); 1202 len += strlen(components[cur]);
1209 if (stat(dir, &st) == 0) { 1203 dir[len++] = G_DIR_SEPARATOR;
1210 if ((st.st_mode & S_IFMT) == S_IFDIR) 1204
1211 continue; 1205 if(g_file_test(dir, G_FILE_TEST_IS_DIR)) {
1212 else { 1206 continue;
1213 gaim_debug(GAIM_DEBUG_WARNING, "build_dir", "bad path: %s\n", path); 1207 } else if(g_file_test(dir, G_FILE_TEST_EXISTS)) {
1214 g_strfreev(components); 1208 gaim_debug(GAIM_DEBUG_WARNING, "build_dir", "bad path: %s\n", path);
1215 g_free(dir);
1216 return -1;
1217 }
1218 } else if (errno != ENOENT) {
1219 gaim_debug(GAIM_DEBUG_WARNING, "build_dir", "stat: %s\n", strerror(errno));
1220 g_strfreev(components); 1209 g_strfreev(components);
1221 g_free(dir); 1210 g_free(dir);
1222 return -1; 1211 return -1;
1223 } 1212 }
1224 1213