Skip to content

Commit 2edfbb4

Browse files
committed
Add os.umask
Fixes #278 Signed-off-by: Steve Bennett <[email protected]>
1 parent d593124 commit 2edfbb4

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

jim-posix.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
#ifdef HAVE_SYS_SYSINFO_H
4646
#include <sys/sysinfo.h>
4747
#endif
48+
#ifdef HAVE_SYS_STAT_H
49+
#include <sys/stat.h>
50+
#endif
4851

4952
static void Jim_PosixSetError(Jim_Interp *interp)
5053
{
@@ -118,6 +121,25 @@ static int Jim_PosixUptimeCommand(Jim_Interp *interp, int argc, Jim_Obj *const *
118121
#endif
119122
return JIM_OK;
120123
}
124+
125+
static int Jim_PosixUmaskCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
126+
{
127+
mode_t oldmask;
128+
129+
if (argc == 2) {
130+
long mask;
131+
if (Jim_GetLong(interp, argv[1], &mask) != JIM_OK) {
132+
return JIM_ERR;
133+
}
134+
oldmask = umask(mask);
135+
}
136+
else {
137+
oldmask = umask(0);
138+
umask(oldmask);
139+
}
140+
Jim_SetResultInt(interp, oldmask);
141+
return JIM_OK;
142+
}
121143
#endif /* JIM_BOOTSTRAP */
122144

123145
int Jim_posixInit(Jim_Interp *interp)
@@ -130,6 +152,7 @@ int Jim_posixInit(Jim_Interp *interp)
130152
Jim_RegisterSimpleCmd(interp, "os.gethostname", "", 0, 0, Jim_PosixGethostnameCommand);
131153
Jim_RegisterSimpleCmd(interp, "os.getids", "", 0, 0, Jim_PosixGetidsCommand);
132154
Jim_RegisterSimpleCmd(interp, "os.uptime", "", 0, 0, Jim_PosixUptimeCommand);
155+
Jim_RegisterSimpleCmd(interp, "os.umask", "?newmask?", 0, 1, Jim_PosixUmaskCommand);
133156
#endif /* JIM_BOOTSTRAP */
134157
return JIM_OK;
135158
}

jim_tcl.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5047,8 +5047,8 @@ what options were selected when Jim Tcl was built.
50475047

50485048

50495049
[[cmd_1]]
5050-
posix: os.fork, os.gethostname, os.getids, os.uptime
5051-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5050+
posix: os.fork, os.gethostname, os.getids, os.uptime, os.umask
5051+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
50525052
+*os.fork*+::
50535053
Invokes 'fork(2)' and returns the result.
50545054

@@ -5063,6 +5063,9 @@ posix: os.fork, os.gethostname, os.getids, os.uptime
50635063
uid 1000 euid 1000 gid 100 egid 100
50645064
----
50655065

5066+
+*os.umask* ?newmask?+::
5067+
Set or return the current process 'umask(2)'. Returns the previous umask.
5068+
50665069
+*os.uptime*+::
50675070
Returns the number of seconds since system boot. See description of 'uptime' in 'sysinfo(2)'.
50685071

0 commit comments

Comments
 (0)