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. --- win32/mingw.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'win32') diff --git a/win32/mingw.c b/win32/mingw.c index 8d1da5199..c72a306ac 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -318,6 +318,20 @@ static inline int get_file_attr(const char *fname, WIN32_FILE_ATTRIBUTE_DATA *fd } } +#undef umask +mode_t mingw_umask(mode_t new_mode) +{ + static mode_t old_mode = DEFAULT_UMASK; + mode_t tmp_mode; + + tmp_mode = old_mode; + old_mode = new_mode; + + umask((new_mode & S_IWUSR) ? _S_IWRITE : 0); + + return tmp_mode; +} + /* * Examine a file's contents to determine if it can be executed. This * should be a last resort: in most cases it's much more efficient to -- cgit v1.2.3-55-g6feb