From: Tor Lillqvist Date: Sun, 21 Mar 2004 21:43:13 +0000 (+0000) Subject: Fix Win32 behaviour in some cases where a drive letter is present. For X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=421e7fdfadb5a63908a446e3166f81e82fcd45ea;p=dana%2Fcg-glib.git Fix Win32 behaviour in some cases where a drive letter is present. For 2004-03-21 Tor Lillqvist * glib/gutils.c (g_path_get_dirname): Fix Win32 behaviour in some cases where a drive letter is present. For 'a:' or 'a:foo', return 'a:.'. This is mostly just for consistency with the behaviour without a drive letter. But very important is to for 'a:\foo' or 'a:\', return 'a:\', and not 'a:'. (Ditto for forward slashes instead of backslashes.) (#137316) * tests/dirname-test.c (main): More complete testing on Win32. If a test fails, include expected and actual result in error message. --- diff --git a/ChangeLog b/ChangeLog index 782d76d4..87bf51d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2004-03-21 Tor Lillqvist + + * glib/gutils.c (g_path_get_dirname): Fix Win32 behaviour in some + cases where a drive letter is present. For 'a:' or 'a:foo', return + 'a:.'. This is mostly just for consistency with the behaviour + without a drive letter. But very important is to for 'a:\foo' or + 'a:\', return 'a:\', and not 'a:'. (Ditto for forward slashes + instead of backslashes.) (#137316) + + * tests/dirname-test.c (main): More complete testing on Win32. If + a test fails, include expected and actual result in error message. + Fri Mar 19 15:21:09 2004 Owen Taylor * glib/gmain.c: Fix the accidental revert of the diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 782d76d4..87bf51d2 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,15 @@ +2004-03-21 Tor Lillqvist + + * glib/gutils.c (g_path_get_dirname): Fix Win32 behaviour in some + cases where a drive letter is present. For 'a:' or 'a:foo', return + 'a:.'. This is mostly just for consistency with the behaviour + without a drive letter. But very important is to for 'a:\foo' or + 'a:\', return 'a:\', and not 'a:'. (Ditto for forward slashes + instead of backslashes.) (#137316) + + * tests/dirname-test.c (main): More complete testing on Win32. If + a test fails, include expected and actual result in error message. + Fri Mar 19 15:21:09 2004 Owen Taylor * glib/gmain.c: Fix the accidental revert of the diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 782d76d4..87bf51d2 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,15 @@ +2004-03-21 Tor Lillqvist + + * glib/gutils.c (g_path_get_dirname): Fix Win32 behaviour in some + cases where a drive letter is present. For 'a:' or 'a:foo', return + 'a:.'. This is mostly just for consistency with the behaviour + without a drive letter. But very important is to for 'a:\foo' or + 'a:\', return 'a:\', and not 'a:'. (Ditto for forward slashes + instead of backslashes.) (#137316) + + * tests/dirname-test.c (main): More complete testing on Win32. If + a test fails, include expected and actual result in error message. + Fri Mar 19 15:21:09 2004 Owen Taylor * glib/gmain.c: Fix the accidental revert of the diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 782d76d4..87bf51d2 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,15 @@ +2004-03-21 Tor Lillqvist + + * glib/gutils.c (g_path_get_dirname): Fix Win32 behaviour in some + cases where a drive letter is present. For 'a:' or 'a:foo', return + 'a:.'. This is mostly just for consistency with the behaviour + without a drive letter. But very important is to for 'a:\foo' or + 'a:\', return 'a:\', and not 'a:'. (Ditto for forward slashes + instead of backslashes.) (#137316) + + * tests/dirname-test.c (main): More complete testing on Win32. If + a test fails, include expected and actual result in error message. + Fri Mar 19 15:21:09 2004 Owen Taylor * glib/gmain.c: Fix the accidental revert of the diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 782d76d4..87bf51d2 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,15 @@ +2004-03-21 Tor Lillqvist + + * glib/gutils.c (g_path_get_dirname): Fix Win32 behaviour in some + cases where a drive letter is present. For 'a:' or 'a:foo', return + 'a:.'. This is mostly just for consistency with the behaviour + without a drive letter. But very important is to for 'a:\foo' or + 'a:\', return 'a:\', and not 'a:'. (Ditto for forward slashes + instead of backslashes.) (#137316) + + * tests/dirname-test.c (main): More complete testing on Win32. If + a test fails, include expected and actual result in error message. + Fri Mar 19 15:21:09 2004 Owen Taylor * glib/gmain.c: Fix the accidental revert of the diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 782d76d4..87bf51d2 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,15 @@ +2004-03-21 Tor Lillqvist + + * glib/gutils.c (g_path_get_dirname): Fix Win32 behaviour in some + cases where a drive letter is present. For 'a:' or 'a:foo', return + 'a:.'. This is mostly just for consistency with the behaviour + without a drive letter. But very important is to for 'a:\foo' or + 'a:\', return 'a:\', and not 'a:'. (Ditto for forward slashes + instead of backslashes.) (#137316) + + * tests/dirname-test.c (main): More complete testing on Win32. If + a test fails, include expected and actual result in error message. + Fri Mar 19 15:21:09 2004 Owen Taylor * glib/gmain.c: Fix the accidental revert of the diff --git a/glib/gutils.c b/glib/gutils.c index 82227d39..98c952cd 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -585,9 +585,31 @@ g_path_get_dirname (const gchar *file_name) } #endif if (!base) + { +#ifdef G_OS_WIN32 + if (g_ascii_isalpha (file_name[0]) && file_name[1] == ':') + { + gchar drive_colon_dot[4]; + + drive_colon_dot[0] = file_name[0]; + drive_colon_dot[1] = ':'; + drive_colon_dot[2] = '.'; + drive_colon_dot[3] = '\0'; + + return g_strdup (drive_colon_dot); + } +#endif return g_strdup ("."); + } + while (base > file_name && G_IS_DIR_SEPARATOR (*base)) base--; + +#ifdef G_OS_WIN32 + if (base == file_name + 1 && g_ascii_isalpha (file_name[0]) && file_name[1] == ':') + base++; +#endif + len = (guint) 1 + base - file_name; base = g_new (gchar, len + 1); diff --git a/tests/dirname-test.c b/tests/dirname-test.c index 7e7d33e6..0c8753c7 100644 --- a/tests/dirname-test.c +++ b/tests/dirname-test.c @@ -60,7 +60,6 @@ main (int argc, gchar *filename; gchar *dirname; } dirname_checks[] = { -#ifndef G_OS_WIN32 { "/", "/" }, { "////", "/" }, { ".////", "." }, @@ -72,17 +71,35 @@ main (int argc, { "a/b", "a" }, { "a/b/", "a/b" }, { "c///", "c" }, -#else + { "/a/b", "/a" }, + { "/a/b/", "/a/b" }, +#ifdef G_OS_WIN32 { "\\", "\\" }, { ".\\\\\\\\", "." }, + { ".\\/\\/", "." }, { ".", "." }, { "..", "." }, { "..\\", ".." }, { "..\\\\\\\\", ".." }, + { "..\\//\\", ".." }, { "", "." }, { "a\\b", "a" }, { "a\\b\\", "a\\b" }, + { "\\a\\b", "\\a" }, + { "\\a\\b\\", "\\a\\b" }, { "c\\\\\\", "c" }, + { "c/\\\\", "c" }, + { "a:", "a:." }, + { "a:foo", "a:." }, + { "a:foo\\bar", "a:foo" }, + { "a:/foo", "a:/" }, + { "a:/foo/bar", "a:/foo" }, + { "a:/", "a:/" }, + { "a://", "a:/" }, + { "a:\\foo", "a:\\" }, + { "a:\\", "a:\\" }, + { "a:\\\\", "a:\\" }, + { "a:\\/", "a:\\" }, #endif }; guint n_dirname_checks = sizeof (dirname_checks) / sizeof (dirname_checks[0]); @@ -92,7 +109,10 @@ main (int argc, gchar *dirname; dirname = g_path_get_dirname (dirname_checks[i].filename); - g_assert (strcmp (dirname, dirname_checks[i].dirname) == 0); + if (strcmp (dirname, dirname_checks[i].dirname) != 0) + g_error ("%s returned %s, should return %s", + dirname_checks[i].filename, dirname, + dirname_checks[i].dirname); g_free (dirname); }