]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cp: improve umask caching
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 14 Sep 2025 18:46:28 +0000 (11:46 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 15 Sep 2025 23:15:10 +0000 (16:15 -0700)
* src/copy.c (cached_umask): Avoid syscalls when cached umask is 0.
This can also help the compiler’s static analysis.

src/copy.c

index e89f376f2774219318a32eabf1a15efcc2a019de..dda914bdb2d7ab5a560e3546e3a3f7cf4fe2eb5e 100644 (file)
@@ -3456,9 +3456,11 @@ owner_failure_ok (struct cp_options const *x)
 extern mode_t
 cached_umask (void)
 {
-  static mode_t mask = (mode_t) -1;
-  if (mask == (mode_t) -1)
+  static mode_t mask;
+  static bool cached;
+  if (!cached)
     {
+      cached = true;
       mask = umask (0);
       umask (mask);
     }