aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2024-09-24 10:48:28 +1000
committerSteve Bennett <steveb@workware.net.au>2025-03-13 10:26:16 +1000
commit7c1007b013cfb0ae9396e86ef5bafdd5494184c4 (patch)
treee1c50b4dbeb38546f36002457930b61bc322375b
parente7a39825e51592fee34cd4d68ae5b935b2bb50e9 (diff)
downloadjimtcl-7c1007b013cfb0ae9396e86ef5bafdd5494184c4.zip
jimtcl-7c1007b013cfb0ae9396e86ef5bafdd5494184c4.tar.gz
jimtcl-7c1007b013cfb0ae9396e86ef5bafdd5494184c4.tar.bz2
Add os.umask
Fixes #278 Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r--jim-posix.c23
-rw-r--r--jim_tcl.txt8
2 files changed, 29 insertions, 2 deletions
diff --git a/jim-posix.c b/jim-posix.c
index 3a04fdf..c308540 100644
--- a/jim-posix.c
+++ b/jim-posix.c
@@ -45,6 +45,9 @@
#ifdef HAVE_SYS_SYSINFO_H
#include <sys/sysinfo.h>
#endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
static void Jim_PosixSetError(Jim_Interp *interp)
{
@@ -118,6 +121,25 @@ static int Jim_PosixUptimeCommand(Jim_Interp *interp, int argc, Jim_Obj *const *
#endif
return JIM_OK;
}
+
+static int Jim_PosixUmaskCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
+{
+ mode_t oldmask;
+
+ if (argc == 2) {
+ long mask;
+ if (Jim_GetLong(interp, argv[1], &mask) != JIM_OK) {
+ return JIM_ERR;
+ }
+ oldmask = umask(mask);
+ }
+ else {
+ oldmask = umask(0);
+ umask(oldmask);
+ }
+ Jim_SetResultInt(interp, oldmask);
+ return JIM_OK;
+}
#endif /* JIM_BOOTSTRAP */
int Jim_posixInit(Jim_Interp *interp)
@@ -130,6 +152,7 @@ int Jim_posixInit(Jim_Interp *interp)
Jim_RegisterSimpleCmd(interp, "os.gethostname", "", 0, 0, Jim_PosixGethostnameCommand);
Jim_RegisterSimpleCmd(interp, "os.getids", "", 0, 0, Jim_PosixGetidsCommand);
Jim_RegisterSimpleCmd(interp, "os.uptime", "", 0, 0, Jim_PosixUptimeCommand);
+ Jim_RegisterSimpleCmd(interp, "os.umask", "?newmask?", 0, 1, Jim_PosixUmaskCommand);
#endif /* JIM_BOOTSTRAP */
return JIM_OK;
}
diff --git a/jim_tcl.txt b/jim_tcl.txt
index 70222b1..c39b43f 100644
--- a/jim_tcl.txt
+++ b/jim_tcl.txt
@@ -61,6 +61,7 @@ Changes since 0.83
#. New `lsubst` command to create lists using subst-style substitution
#. Add support for `regexp -expanded` and `regsub -expanded`
#. `vwait` now accepts a script argument
+#. Add support for `os.umask`
Changes between 0.82 and 0.83
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -5028,8 +5029,8 @@ what options were selected when Jim Tcl was built.
[[cmd_1]]
-posix: os.fork, os.gethostname, os.getids, os.uptime
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+posix: os.fork, os.gethostname, os.getids, os.uptime, os.umask
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+*os.fork*+::
Invokes 'fork(2)' and returns the result.
@@ -5044,6 +5045,9 @@ posix: os.fork, os.gethostname, os.getids, os.uptime
uid 1000 euid 1000 gid 100 egid 100
----
++*os.umask* ?newmask?+::
+ Set or return the current process 'umask(2)'. Returns the previous umask.
+
+*os.uptime*+::
Returns the number of seconds since system boot. See description of 'uptime' in 'sysinfo(2)'.