From b64ee1f02098d229ff16df9dfebdc3e3f3d76687 Mon Sep 17 00:00:00 2001 From: Carlo Bramini Date: Tue, 3 Nov 2009 14:26:25 +0200 Subject: [PATCH] Make g_file_test() behave on Windows more like as on POSIX Patch from bug #572252. --- glib/gfileutils.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/glib/gfileutils.c b/glib/gfileutils.c index fcbd63b1..3633753a 100644 --- a/glib/gfileutils.c +++ b/glib/gfileutils.c @@ -204,19 +204,26 @@ g_file_test (const gchar *filename, return TRUE; if (test & G_FILE_TEST_IS_REGULAR) - return (attributes & (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_DEVICE)) == 0; + { + if ((attributes & (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_DEVICE)) == 0) + return TRUE; + } if (test & G_FILE_TEST_IS_DIR) - return (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0; + { + if ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0) + return TRUE; + } - if (test & G_FILE_TEST_IS_EXECUTABLE) + /* "while" so that we can exit this "loop" with a simple "break" */ + while (test & G_FILE_TEST_IS_EXECUTABLE) { const gchar *lastdot = strrchr (filename, '.'); const gchar *pathext = NULL, *p; int extlen; if (lastdot == NULL) - return FALSE; + break; if (_stricmp (lastdot, ".exe") == 0 || _stricmp (lastdot, ".cmd") == 0 || @@ -228,7 +235,7 @@ g_file_test (const gchar *filename, pathext = g_getenv ("PATHEXT"); if (pathext == NULL) - return FALSE; + break; pathext = g_utf8_casefold (pathext, -1); @@ -256,7 +263,7 @@ g_file_test (const gchar *filename, g_free ((gchar *) pathext); g_free ((gchar *) lastdot); - return FALSE; + break; } return FALSE; -- 2.34.1