]> Savannah Git Hosting - gnulib.git/commitdiff
getumask: Make it work on native Windows.
authorBruno Haible <bruno@clisp.org>
Thu, 20 Apr 2023 21:21:42 +0000 (23:21 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 20 Apr 2023 21:21:42 +0000 (23:21 +0200)
* 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.

ChangeLog
lib/getumask.c
tests/test-getumask.c

index 7856e350c04182b06ca4503aa284fb7a0b0c48d8..5bdc213a32c4a529268d65071e0e987c29d72b60 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+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.
+
 2023-04-20  Bruno Haible  <bruno@clisp.org>
 
        posixtm tests: Fix link error.
index 203d6dc869746856adb6c7f21e1f33b24f96f9e3..e979f9b874e5414e301c90f4792d4dc972a913f2 100644 (file)
@@ -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);
index 6ee50836bcd1cec437c1c518823514e21c570d2f..ab1e48ecd9708452a1de04c3ea997fd541734e44 100644 (file)
@@ -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)
 {