summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-03-15 19:45:43 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-03-15 19:45:43 -0700
commitc7d406ee564a2072ec4c9f91138d21fed6727238 (patch)
tree159ea5c4c2b4fdd4439e2f16396776d320716690
parent510caa23aa66e783e967e991623a7327fd2e58c4 (diff)
downloadtxr-c7d406ee564a2072ec4c9f91138d21fed6727238.tar.gz
txr-c7d406ee564a2072ec4c9f91138d21fed6727238.tar.bz2
txr-c7d406ee564a2072ec4c9f91138d21fed6727238.zip
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.
-rw-r--r--sysif.c10
1 files 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