bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

getumask: Make it work on native Windows


From: Bruno Haible
Subject: getumask: Make it work on native Windows
Date: Thu, 20 Apr 2023 23:29:13 +0200

On native Windows, I see a test failure:

FAIL: test-getumask
===================

../../gltests/test-getumask.c:42: assertion 'mask == 002' failed
FAIL test-getumask.exe (exit status: 3)

There are two problems here:
- The getumask() implementation uses a temporary directory that may not
  exist, falling back to 077, which is not the correct return value.
- Once this is fixed, getumask() always returns 0111, but the unit test
  cannot cope with this.

This patch fixes the function and avoid a test failure.


2023-04-20  Bruno Haible  <bruno@clisp.org>

        getumask: Make it work on native Windows.
        * lib/getumask.c (getumask): When TMPDIR is unset, try TMP and TEMP.
        * tests/test-getumask.c (ASSUME_UMASK_CONSTANT): Define to 1 on native
        Windows.

diff --git a/lib/getumask.c b/lib/getumask.c
index 203d6dc869..e979f9b874 100644
--- a/lib/getumask.c
+++ b/lib/getumask.c
@@ -106,6 +106,16 @@ getumask (void)
     {
       /* Create a temporary file and inspect its access permissions.  */
       const char *tmpdir = getenv ("TMPDIR");
+# if defined _WIN32 && !defined __CYGWIN__
+      if (tmpdir == NULL || *tmpdir == '\0')
+        {
+          /* On native Windows, TMPDIR is typically not set, and /tmp does not
+             exist.  $TMP and $TEMP can be used instead.  */
+          tmpdir = getenv ("TMP");
+          if (tmpdir == NULL || *tmpdir == '\0')
+            tmpdir = getenv ("TEMP");
+        }
+# endif
       if (tmpdir == NULL || *tmpdir == '\0')
         tmpdir = "/tmp";
       size_t tmpdir_length = strlen (tmpdir);
diff --git a/tests/test-getumask.c b/tests/test-getumask.c
index 6ee50836bc..ab1e48ecd9 100644
--- a/tests/test-getumask.c
+++ b/tests/test-getumask.c
@@ -25,6 +25,11 @@ SIGNATURE_CHECK (getumask, mode_t, (void));
 
 #include "macros.h"
 
+#if defined _WIN32 && !defined __CYGWIN__
+/* On native Windows, getumask() always returns 0111.  */
+# define ASSUME_UMASK_CONSTANT 1
+#endif
+
 int
 main (void)
 {






reply via email to

[Prev in Thread] Current Thread [Next in Thread]