mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-05-03 20:46:53 +02:00
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.
This commit is contained in:
parent
478632418e
commit
acc1c38efe
@ -1,3 +1,9 @@
|
|||||||
|
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>
|
Fri Jul 10 06:33:43 1998 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* glib.h:
|
* glib.h:
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
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>
|
Fri Jul 10 06:33:43 1998 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* glib.h:
|
* glib.h:
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
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>
|
Fri Jul 10 06:33:43 1998 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* glib.h:
|
* glib.h:
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
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>
|
Fri Jul 10 06:33:43 1998 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* glib.h:
|
* glib.h:
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
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>
|
Fri Jul 10 06:33:43 1998 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* glib.h:
|
* glib.h:
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
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>
|
Fri Jul 10 06:33:43 1998 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* glib.h:
|
* glib.h:
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
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>
|
Fri Jul 10 06:33:43 1998 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* glib.h:
|
* glib.h:
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
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>
|
Fri Jul 10 06:33:43 1998 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* glib.h:
|
* glib.h:
|
||||||
|
1
glib.h
1
glib.h
@ -840,6 +840,7 @@ gint g_snprintf (gchar *string,
|
|||||||
...) G_GNUC_PRINTF (3, 4);
|
...) G_GNUC_PRINTF (3, 4);
|
||||||
gchar* g_basename (const gchar *file_name);
|
gchar* g_basename (const gchar *file_name);
|
||||||
gchar* g_getcwd (void);
|
gchar* g_getcwd (void);
|
||||||
|
gchar* g_dirname (const gchar *file_name);
|
||||||
|
|
||||||
|
|
||||||
/* We make the assumption that if memmove isn't available, then
|
/* 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);
|
...) G_GNUC_PRINTF (3, 4);
|
||||||
gchar* g_basename (const gchar *file_name);
|
gchar* g_basename (const gchar *file_name);
|
||||||
gchar* g_getcwd (void);
|
gchar* g_getcwd (void);
|
||||||
|
gchar* g_dirname (const gchar *file_name);
|
||||||
|
|
||||||
|
|
||||||
/* We make the assumption that if memmove isn't available, then
|
/* 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;
|
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*
|
gchar*
|
||||||
g_getcwd (void)
|
g_getcwd (void)
|
||||||
{
|
{
|
||||||
|
22
gutils.c
22
gutils.c
@ -127,6 +127,28 @@ g_basename (const gchar *file_name)
|
|||||||
return (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*
|
gchar*
|
||||||
g_getcwd (void)
|
g_getcwd (void)
|
||||||
{
|
{
|
||||||
|
37
testglib.c
37
testglib.c
@ -112,11 +112,48 @@ main (int argc,
|
|||||||
GRelation *relation;
|
GRelation *relation;
|
||||||
GTuples *tuples;
|
GTuples *tuples;
|
||||||
gint data [1024];
|
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 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 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 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...");
|
g_print ("checking doubly linked lists...");
|
||||||
|
|
||||||
list = NULL;
|
list = NULL;
|
||||||
|
@ -112,11 +112,48 @@ main (int argc,
|
|||||||
GRelation *relation;
|
GRelation *relation;
|
||||||
GTuples *tuples;
|
GTuples *tuples;
|
||||||
gint data [1024];
|
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 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 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 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...");
|
g_print ("checking doubly linked lists...");
|
||||||
|
|
||||||
list = NULL;
|
list = NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user