Make g_file_test() behave on Windows more like as on POSIX
authorCarlo Bramini <carlo.bramix@libero.it>
Tue, 3 Nov 2009 12:26:25 +0000 (14:26 +0200)
committerTor Lillqvist <tml@iki.fi>
Tue, 3 Nov 2009 12:30:16 +0000 (14:30 +0200)
Patch from bug #572252.

glib/gfileutils.c

index fcbd63b..3633753 100644 (file)
@@ -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;