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.
This commit is contained in:
Paul Eggert committed 2025-09-15 16:15:10 -07:00
1 parent f4dcc2a495
commit 8339970b15
1 file changed
+4 -2
+4 -2
View 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);
}