+Tue Jul 14 09:05:18 1998 Tim Janik <timj@gtk.org>
+
+ * glib.h:
+ * gutils.c: new fuction g_dirname() which returns a newlly
+ allocated string.
+
Fri Jul 10 06:33:43 1998 Tim Janik <timj@gtk.org>
* glib.h:
+Tue Jul 14 09:05:18 1998 Tim Janik <timj@gtk.org>
+
+ * glib.h:
+ * gutils.c: new fuction g_dirname() which returns a newlly
+ allocated string.
+
Fri Jul 10 06:33:43 1998 Tim Janik <timj@gtk.org>
* glib.h:
+Tue Jul 14 09:05:18 1998 Tim Janik <timj@gtk.org>
+
+ * glib.h:
+ * gutils.c: new fuction g_dirname() which returns a newlly
+ allocated string.
+
Fri Jul 10 06:33:43 1998 Tim Janik <timj@gtk.org>
* glib.h:
+Tue Jul 14 09:05:18 1998 Tim Janik <timj@gtk.org>
+
+ * glib.h:
+ * gutils.c: new fuction g_dirname() which returns a newlly
+ allocated string.
+
Fri Jul 10 06:33:43 1998 Tim Janik <timj@gtk.org>
* glib.h:
+Tue Jul 14 09:05:18 1998 Tim Janik <timj@gtk.org>
+
+ * glib.h:
+ * gutils.c: new fuction g_dirname() which returns a newlly
+ allocated string.
+
Fri Jul 10 06:33:43 1998 Tim Janik <timj@gtk.org>
* glib.h:
+Tue Jul 14 09:05:18 1998 Tim Janik <timj@gtk.org>
+
+ * glib.h:
+ * gutils.c: new fuction g_dirname() which returns a newlly
+ allocated string.
+
Fri Jul 10 06:33:43 1998 Tim Janik <timj@gtk.org>
* glib.h:
+Tue Jul 14 09:05:18 1998 Tim Janik <timj@gtk.org>
+
+ * glib.h:
+ * gutils.c: new fuction g_dirname() which returns a newlly
+ allocated string.
+
Fri Jul 10 06:33:43 1998 Tim Janik <timj@gtk.org>
* glib.h:
+Tue Jul 14 09:05:18 1998 Tim Janik <timj@gtk.org>
+
+ * glib.h:
+ * gutils.c: new fuction g_dirname() which returns a newlly
+ allocated string.
+
Fri Jul 10 06:33:43 1998 Tim Janik <timj@gtk.org>
* glib.h:
...) G_GNUC_PRINTF (3, 4);
gchar* g_basename (const gchar *file_name);
gchar* g_getcwd (void);
+gchar* g_dirname (const gchar *file_name);
/* We make the assumption that if memmove isn't available, then
...) G_GNUC_PRINTF (3, 4);
gchar* g_basename (const gchar *file_name);
gchar* g_getcwd (void);
+gchar* g_dirname (const gchar *file_name);
/* We make the assumption that if memmove isn't available, then
}
gchar*
+g_dirname (const gchar *file_name)
+{
+ register gchar *base;
+ register guint len;
+
+ g_return_val_if_fail (file_name != NULL, NULL);
+
+ base = strrchr (file_name, '/');
+ if (!base)
+ return g_strdup (".");
+ while (base > file_name && *base == '/')
+ base--;
+ len = (guint) 1 + base - file_name;
+
+ base = g_new (gchar, len + 1);
+ g_memmove (base, file_name, len);
+ base[len] = 0;
+
+ return base;
+}
+
+gchar*
g_getcwd (void)
{
static gchar g_getcwd_buf[MAXPATHLEN + 1] = { 0 };
}
gchar*
+g_dirname (const gchar *file_name)
+{
+ register gchar *base;
+ register guint len;
+
+ g_return_val_if_fail (file_name != NULL, NULL);
+
+ base = strrchr (file_name, '/');
+ if (!base)
+ return g_strdup (".");
+ while (base > file_name && *base == '/')
+ base--;
+ len = (guint) 1 + base - file_name;
+
+ base = g_new (gchar, len + 1);
+ g_memmove (base, file_name, len);
+ base[len] = 0;
+
+ return base;
+}
+
+gchar*
g_getcwd (void)
{
static gchar g_getcwd_buf[MAXPATHLEN + 1] = { 0 };
GRelation *relation;
GTuples *tuples;
gint data [1024];
+ struct {
+ gchar *filename;
+ gchar *dirname;
+ } dirname_checks[] = {
+ { "/", "/" },
+ { "////", "/" },
+ { ".////", "." },
+ { ".", "." },
+ { "..", "." },
+ { "../", ".." },
+ { "..////", ".." },
+ { "", "." },
+ { "a/b", "a" },
+ { "a/b/", "a/b" },
+ { "c///", "c" },
+ };
+ guint n_dirname_checks = sizeof (dirname_checks) / sizeof (dirname_checks[0]);
+
g_print ("checking size of gint8...%ld (should be 1)\n", (glong)sizeof (gint8));
g_print ("checking size of gint16...%ld (should be 2)\n", (glong)sizeof (gint16));
g_print ("checking size of gint32...%ld (should be 4)\n", (glong)sizeof (gint32));
+ g_print ("checking g_dirname()...");
+ for (i = 0; i < n_dirname_checks; i++)
+ {
+ gchar *dirname;
+
+ dirname = g_dirname (dirname_checks[i].filename);
+ if (strcmp (dirname, dirname_checks[i].dirname) != 0)
+ {
+ g_print ("failed for \"%s\"==\"%s\" (returned: \"%s\")\n",
+ dirname_checks[i].filename,
+ dirname_checks[i].dirname,
+ dirname);
+ n_dirname_checks = 0;
+ }
+ g_free (dirname);
+ }
+ if (n_dirname_checks)
+ g_print ("ok\n");
+
g_print ("checking doubly linked lists...");
list = NULL;
GRelation *relation;
GTuples *tuples;
gint data [1024];
+ struct {
+ gchar *filename;
+ gchar *dirname;
+ } dirname_checks[] = {
+ { "/", "/" },
+ { "////", "/" },
+ { ".////", "." },
+ { ".", "." },
+ { "..", "." },
+ { "../", ".." },
+ { "..////", ".." },
+ { "", "." },
+ { "a/b", "a" },
+ { "a/b/", "a/b" },
+ { "c///", "c" },
+ };
+ guint n_dirname_checks = sizeof (dirname_checks) / sizeof (dirname_checks[0]);
+
g_print ("checking size of gint8...%ld (should be 1)\n", (glong)sizeof (gint8));
g_print ("checking size of gint16...%ld (should be 2)\n", (glong)sizeof (gint16));
g_print ("checking size of gint32...%ld (should be 4)\n", (glong)sizeof (gint32));
+ g_print ("checking g_dirname()...");
+ for (i = 0; i < n_dirname_checks; i++)
+ {
+ gchar *dirname;
+
+ dirname = g_dirname (dirname_checks[i].filename);
+ if (strcmp (dirname, dirname_checks[i].dirname) != 0)
+ {
+ g_print ("failed for \"%s\"==\"%s\" (returned: \"%s\")\n",
+ dirname_checks[i].filename,
+ dirname_checks[i].dirname,
+ dirname);
+ n_dirname_checks = 0;
+ }
+ g_free (dirname);
+ }
+ if (n_dirname_checks)
+ g_print ("ok\n");
+
g_print ("checking doubly linked lists...");
list = NULL;