From: Paul Eggert Date: Sun, 14 Sep 2025 18:46:28 +0000 (-0700) Subject: cp: improve umask caching X-Git-Tag: v9.8~55 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8339970b155d6d3ed5623325bb577b29b59948d6;p=thirdparty%2Fcoreutils.git cp: improve umask caching * src/copy.c (cached_umask): Avoid syscalls when cached umask is 0. This can also help the compiler’s static analysis. --- diff --git a/src/copy.c b/src/copy.c index e89f376f27..dda914bdb2 100644 --- a/src/copy.c +++ b/src/copy.c @@ -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); }