Fix Win32 behaviour in some cases where a drive letter is present. For

2004-03-21  Tor Lillqvist  <tml@iki.fi>

	* 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.
This commit is contained in:
Tor Lillqvist
2004-03-21 21:43:13 +00:00
committed by Tor Lillqvist
parent 000085ffa7
commit 421e7fdfad
8 changed files with 117 additions and 3 deletions

View File

@@ -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);