Commit acc1c38e authored by Tim Janik's avatar Tim Janik Committed by Tim Janik

new fuction g_dirname() which returns a newlly allocated string.

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.
parent 47863241
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:
......
......@@ -840,6 +840,7 @@ gint g_snprintf (gchar *string,
...) 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
......
......@@ -840,6 +840,7 @@ gint g_snprintf (gchar *string,
...) 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
......
......@@ -127,6 +127,28 @@ g_basename (const gchar *file_name)
return (gchar*) file_name;
}
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)
{
......
......@@ -127,6 +127,28 @@ g_basename (const gchar *file_name)
return (gchar*) file_name;
}
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)
{
......
......@@ -112,11 +112,48 @@ main (int argc,
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;
......
......@@ -112,11 +112,48 @@ main (int argc,
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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment