gst/gstregistryxml.c: Copy g_mkdir_with_parent() from glib, because we don't require glib-2.8.

Original commit message from CVS:
* gst/gstregistryxml.c: Copy g_mkdir_with_parent() from glib,
because we don't require glib-2.8.
This commit is contained in:
David Schleef 2005-09-15 00:35:11 +00:00
parent c4304be0ef
commit faeaea4498
2 changed files with 62 additions and 23 deletions

View file

@ -1,3 +1,8 @@
2005-09-14 David Schleef <ds@schleef.org>
* gst/gstregistryxml.c: Copy g_mkdir_with_parent() from glib,
because we don't require glib-2.8.
2005-09-14 David Schleef <ds@schleef.org> 2005-09-14 David Schleef <ds@schleef.org>
* gst/gstregistryxml.c: Added. Essentially moved out of the * gst/gstregistryxml.c: Added. Essentially moved out of the

View file

@ -130,34 +130,68 @@ get_time (const char *path, gboolean * is_dir)
} }
#endif #endif
static gboolean /* The following function was copied from GLIB-2.8. When the glib
make_dir (gchar * filename) * requirement gets bumped to an appropriate level, this can be
* removed. */
/* gfileutils.c - File utility functions
*
* Copyright 2000 Red Hat, Inc.
*
* LGPL
*/
static int
private_g_mkdir_with_parents (const gchar * pathname, int mode)
{ {
struct stat dirstat; gchar *fn, *p;
gchar *dirname;
if (strrchr (filename, '/') == NULL) if (pathname == NULL || *pathname == '\0') {
return FALSE; errno = EINVAL;
return -1;
dirname = g_strndup (filename, strrchr (filename, '/') - filename);
if (stat (dirname, &dirstat) == -1 && errno == ENOENT) {
if (g_mkdir (dirname, 0755) != 0) {
if (make_dir (dirname) != TRUE) {
g_free (dirname);
return FALSE;
} else {
if (g_mkdir (dirname, 0755) != 0) {
return FALSE;
}
}
}
} }
g_free (dirname); fn = g_strdup (pathname);
return TRUE;
if (g_path_is_absolute (fn))
p = (gchar *) g_path_skip_root (fn);
else
p = fn;
do {
while (*p && !G_IS_DIR_SEPARATOR (*p))
p++;
if (!*p)
p = NULL;
else
*p = '\0';
if (!g_file_test (fn, G_FILE_TEST_EXISTS)) {
if (g_mkdir (fn, mode) == -1) {
int errno_save = errno;
g_free (fn);
errno = errno_save;
return -1;
}
} else if (!g_file_test (fn, G_FILE_TEST_IS_DIR)) {
g_free (fn);
errno = ENOTDIR;
return -1;
}
if (p) {
*p++ = G_DIR_SEPARATOR;
while (*p && G_IS_DIR_SEPARATOR (*p))
p++;
}
}
while (p);
g_free (fn);
return 0;
} }
#if 0 #if 0
static void static void
gst_registry_xml_get_perms_func (GstRegistry * registry) gst_registry_xml_get_perms_func (GstRegistry * registry)
@ -989,7 +1023,7 @@ gst_registry_xml_write_cache (GstRegistry * registry, const char *location)
/* oops, I bet the directory doesn't exist */ /* oops, I bet the directory doesn't exist */
dir = g_path_get_dirname (location); dir = g_path_get_dirname (location);
g_mkdir_with_parents (dir, 0777); private_g_mkdir_with_parents (dir, 0777);
g_free (dir); g_free (dir);
registry->cache_file = fopen (tmp_location, "w"); registry->cache_file = fopen (tmp_location, "w");