summaryrefslogtreecommitdiffstats
path: root/sysif.c
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
commita16253f78cea60a6a9696f20c8839f80f105c29f (patch)
tree159ea5c4c2b4fdd4439e2f16396776d320716690 /sysif.c
parentccb946d7e3a64dd501f21e5859de81fc127f816b (diff)
downloadtxr-a16253f78cea60a6a9696f20c8839f80f105c29f.tar.gz
txr-a16253f78cea60a6a9696f20c8839f80f105c29f.tar.bz2
txr-a16253f78cea60a6a9696f20c8839f80f105c29f.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.
Diffstat (limited to 'sysif.c')
-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