From a85653040477ec4e8a722de3af5afd04ee66bd59 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Mon, 7 Jan 2019 07:54:40 +0000 Subject: win32: implement umask(2) umask() in the Microsoft C runtime takes different arguments to umask(2). Implement a fake umask(2) that remembers the mask and calls the Microsoft umask() with an appropriate value. Since the mask won't be inherited by children use an environment variable to pass any value set by the shell built-in umask. --- libbb/appletlib.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'libbb') diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 8a66b3303..ba52ef581 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -1081,6 +1081,15 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **ar applet_name = name; #if ENABLE_PLATFORM_MINGW32 strcpy(bb_applet_name, applet_name); + + { + const char *vmask; + unsigned int mask; + + vmask = getenv("BB_UMASK"); + if (vmask && sscanf(vmask, "%o", &mask) == 1) + umask((mode_t)(mask&0777)); + } #endif /* Special case. POSIX says "test --help" -- cgit v1.2.3-55-g6feb