diff options
author | Steve Bennett <steveb@workware.net.au> | 2024-09-24 10:48:28 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2025-07-16 09:34:08 +1000 |
commit | 2edfbb49f2fe6d878a3bf16f9bab8f921d635592 (patch) | |
tree | 9c380735a007b3b3c918cdcdd1aa4b10198cca27 | |
parent | d5931248b6cf9a627ea8e2547c150c1dd791ddcc (diff) | |
download | jimtcl-2edfbb49f2fe6d878a3bf16f9bab8f921d635592.zip jimtcl-2edfbb49f2fe6d878a3bf16f9bab8f921d635592.tar.gz jimtcl-2edfbb49f2fe6d878a3bf16f9bab8f921d635592.tar.bz2 |
Add os.umask
Fixes #278
Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r-- | jim-posix.c | 23 | ||||
-rw-r--r-- | jim_tcl.txt | 7 |
2 files changed, 28 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 097cd84..4d48fef 100644 --- a/jim_tcl.txt +++ b/jim_tcl.txt @@ -5047,8 +5047,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. @@ -5063,6 +5063,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)'. |