mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-01 23:13:40 +02:00
Fix #117925 (Dov Grobgeld):
2003-08-16 Tor Lillqvist <tml@iki.fi> Fix #117925 (Dov Grobgeld): * glib/gutils.c (g_find_program_in_path, g_basename, g_path_get_basename, g_path_is_absolute, g_path_skip_root, g_path_get_dirname, g_get_any_init): On Win32, look also for slashes ('/') as pathname separators. * glib/gfileutils.c (g_file_open_tmp): Ditto. If the template contains a pathname separator, include the actual one in the error message, instead of always the canonical one. (g_build_filename): Separate implementation on Win32 that looks for either slash or backslash. Document Unix/Windows differences. * tests/testglib.c * tests/strfunc-test.c: Test above functionality on Win32.
This commit is contained in:
committed by
Tor Lillqvist
parent
ed23bef565
commit
55d624d80c
@@ -441,6 +441,39 @@ main (int argc,
|
||||
TEST (NULL, str_check (g_build_filename (S"x"S, S"y"S, S"z"S, NULL), S"x"S"y"S"z"S));
|
||||
TEST (NULL, str_check (g_build_filename (S S"x"S S, S S"y"S S, S S"z"S S, NULL), S S"x"S"y"S"z"S S));
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
|
||||
/* Test also using the slash as file name separator */
|
||||
#define U "/"
|
||||
TEST (NULL, str_check (g_build_filename (NULL), ""));
|
||||
TEST (NULL, str_check (g_build_filename (U, NULL), U));
|
||||
TEST (NULL, str_check (g_build_filename (U"x", NULL), U"x"));
|
||||
TEST (NULL, str_check (g_build_filename ("x"U, NULL), "x"U));
|
||||
TEST (NULL, str_check (g_build_filename ("", U"x", NULL), U"x"));
|
||||
TEST (NULL, str_check (g_build_filename ("", U"x", NULL), U"x"));
|
||||
TEST (NULL, str_check (g_build_filename (U, "x", NULL), U"x"));
|
||||
TEST (NULL, str_check (g_build_filename (U U, "x", NULL), U U"x"));
|
||||
TEST (NULL, str_check (g_build_filename (U S, "x", NULL), U S"x"));
|
||||
TEST (NULL, str_check (g_build_filename ("x"U, "", NULL), "x"U));
|
||||
TEST (NULL, str_check (g_build_filename ("x"S"y", "z"U"a", NULL), "x"S"y"S"z"U"a"));
|
||||
TEST (NULL, str_check (g_build_filename ("x", U, NULL), "x"U));
|
||||
TEST (NULL, str_check (g_build_filename ("x", U U, NULL), "x"U U));
|
||||
TEST (NULL, str_check (g_build_filename ("x", S U, NULL), "x"S U));
|
||||
TEST (NULL, str_check (g_build_filename (U"x", "y", NULL), U"x"U"y"));
|
||||
TEST (NULL, str_check (g_build_filename ("x", "y"U, NULL), "x"U"y"U));
|
||||
TEST (NULL, str_check (g_build_filename (U"x"U, U"y"U, NULL), U"x"U"y"U));
|
||||
TEST (NULL, str_check (g_build_filename (U"x"U U, U U"y"U, NULL), U"x"U"y"U));
|
||||
TEST (NULL, str_check (g_build_filename ("x", U, "y", NULL), "x"U"y"));
|
||||
TEST (NULL, str_check (g_build_filename ("x", U U, "y", NULL), "x"U"y"));
|
||||
TEST (NULL, str_check (g_build_filename ("x", U S, "y", NULL), "x"S"y"));
|
||||
TEST (NULL, str_check (g_build_filename ("x", S U, "y", NULL), "x"U"y"));
|
||||
TEST (NULL, str_check (g_build_filename ("x", U "y", "z", NULL), "x"U"y"U"z"));
|
||||
TEST (NULL, str_check (g_build_filename ("x", S "y", "z", NULL), "x"S"y"S"z"));
|
||||
TEST (NULL, str_check (g_build_filename ("x", S "y", "z", U, "a", "b", NULL), "x"S"y"S"z"U"a"U"b"));
|
||||
TEST (NULL, str_check (g_build_filename (U"x"U, U"y"U, U"z"U, NULL), U"x"U"y"U"z"U));
|
||||
TEST (NULL, str_check (g_build_filename (U U"x"U U, U U"y"U U, U U"z"U U, NULL), U U"x"U"y"U"z"U U));
|
||||
#endif /* G_OS_WIN32 */
|
||||
|
||||
#undef S
|
||||
|
||||
{
|
||||
|
@@ -336,7 +336,6 @@ main (int argc,
|
||||
gchar *filename;
|
||||
gchar *dirname;
|
||||
} dirname_checks[] = {
|
||||
#ifndef G_OS_WIN32
|
||||
{ "/", "/" },
|
||||
{ "////", "/" },
|
||||
{ ".////", "." },
|
||||
@@ -345,14 +344,16 @@ main (int argc,
|
||||
{ "a/b", "a" },
|
||||
{ "a/b/", "a/b" },
|
||||
{ "c///", "c" },
|
||||
#else
|
||||
#ifdef G_OS_WIN32
|
||||
{ "\\", "\\" },
|
||||
{ ".\\\\\\\\", "." },
|
||||
{ "..\\", ".." },
|
||||
{ "..\\\\\\\\", ".." },
|
||||
{ "a\\b", "a" },
|
||||
{ "a\\b\\", "a\\b" },
|
||||
{ "c\\\\\\", "c" },
|
||||
{ "a\\b/", "a\\b" },
|
||||
{ "a/b\\", "a/b" },
|
||||
{ "c\\\\/", "c" },
|
||||
{ "//\\", "/" },
|
||||
#endif
|
||||
#ifdef G_WITH_CYGWIN
|
||||
{ "//server/share///x", "//server/share" },
|
||||
@@ -367,13 +368,12 @@ main (int argc,
|
||||
gchar *filename;
|
||||
gchar *without_root;
|
||||
} skip_root_checks[] = {
|
||||
#ifndef G_OS_WIN32
|
||||
{ "/", "" },
|
||||
{ "//", "" },
|
||||
{ "/foo", "foo" },
|
||||
{ "//foo", "foo" },
|
||||
{ "a/b", NULL },
|
||||
#else
|
||||
#ifdef G_OS_WIN32
|
||||
{ "\\", "" },
|
||||
{ "\\foo", "foo" },
|
||||
{ "\\\\server\\foo", "" },
|
||||
@@ -448,6 +448,15 @@ main (int argc,
|
||||
g_assert (strcmp (string, "file") == 0);
|
||||
g_free (string);
|
||||
g_print ("ok\n");
|
||||
#ifdef G_OS_WIN32
|
||||
string = g_path_get_basename ("/foo/dir/");
|
||||
g_assert (strcmp (string, "dir") == 0);
|
||||
g_free (string);
|
||||
string = g_path_get_basename ("/foo/file");
|
||||
g_assert (strcmp (string, "file") == 0);
|
||||
g_free (string);
|
||||
g_print ("ok\n");
|
||||
#endif
|
||||
|
||||
g_print ("checking g_path_get_dirname()...");
|
||||
for (i = 0; i < n_dirname_checks; i++)
|
||||
@@ -1171,6 +1180,11 @@ main (int argc,
|
||||
|
||||
g_print ("ok\n");
|
||||
|
||||
if (g_get_charset (&string))
|
||||
g_print ("current charset is UTF-8: %s\n", string);
|
||||
else
|
||||
g_print ("current charset is not UTF-8: %s\n", string);
|
||||
|
||||
#ifdef G_PLATFORM_WIN32
|
||||
g_print ("current locale: %s\n", g_win32_getlocale ());
|
||||
g_print ("GLib DLL name tested for: %s\n", glib_dll);
|
||||
@@ -1235,6 +1249,18 @@ main (int argc,
|
||||
close (fd);
|
||||
g_clear_error (&error);
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
strcpy (template, "zap/barXXXXXX");
|
||||
fd = g_file_open_tmp (template, &name_used, &error);
|
||||
if (fd != -1)
|
||||
g_print ("g_file_open_tmp works even if template contains '/'\n");
|
||||
else
|
||||
g_print ("g_file_open_tmp correctly returns error: %s\n",
|
||||
error->message);
|
||||
close (fd);
|
||||
g_clear_error (&error);
|
||||
#endif
|
||||
|
||||
strcpy (template, "zapXXXXXX");
|
||||
fd = g_file_open_tmp (template, &name_used, &error);
|
||||
if (fd == -1)
|
||||
|
Reference in New Issue
Block a user