From a16253f78cea60a6a9696f20c8839f80f105c29f Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 15 Mar 2017 19:45:43 -0700 Subject: umask: arg optional, return old value. * sysif.c (umask_wrap): Return the prior value of the umask rather than the symbol t. If the argument is missing, then just return the current value without altering the umask. Unfortunately, this is implemented by temporarily changing the umask and then putting it back. (sysif_init): Change registration of umask to reflect optional argument. --- sysif.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sysif.c b/sysif.c index 67e31ac4..9be964ed 100644 --- a/sysif.c +++ b/sysif.c @@ -718,8 +718,12 @@ val statf(val stream) static val umask_wrap(val mask) { - (void) umask(c_num(mask)); - return t; + if (missingp(mask)) { + mode_t m = umask(0777); + (void) umask(m); + return num(m); + } + return num(umask(c_num(mask))); } #endif @@ -1755,7 +1759,7 @@ void sysif_init(void) #endif #if HAVE_SYS_STAT - reg_fun(intern(lit("umask"), user_package), func_n1(umask_wrap)); + reg_fun(intern(lit("umask"), user_package), func_n1o(umask_wrap, 0)); #endif #if HAVE_FNMATCH -- cgit v1.2.3