From 1b7259fce2719182e2b557682e40d02807784d1f Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Mon, 30 Dec 2013 19:51:28 +0200 Subject: [PATCH] Fix bug #16299 with assertion violation in set-default-file-modes on Windows. src/w32.c (sys_umask): New function. nt/inc/ms-w32.h (umask) [emacs]: Redirect to sys_umask. --- nt/ChangeLog | 4 ++++ nt/inc/ms-w32.h | 4 +++- src/ChangeLog | 4 ++++ src/w32.c | 29 +++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/nt/ChangeLog b/nt/ChangeLog index feaf2cd783..8eb601d4e3 100644 --- a/nt/ChangeLog +++ b/nt/ChangeLog @@ -1,3 +1,7 @@ +2013-12-30 Eli Zaretskii + + * inc/ms-w32.h (umask) [emacs]: Redirect to sys_umask. (Bug#16299) + 2013-12-23 Eli Zaretskii * README.W32: diff --git a/nt/inc/ms-w32.h b/nt/inc/ms-w32.h index bcccebc13a..735f9a6532 100644 --- a/nt/inc/ms-w32.h +++ b/nt/inc/ms-w32.h @@ -235,6 +235,9 @@ extern struct tm * sys_localtime (const time_t *); extern int sys_unlink (const char *); #undef write #define write sys_write +#undef umask +#define umask sys_umask +extern int sys_umask (int); /* Subprocess calls that are emulated. */ #define spawnve sys_spawnve @@ -276,7 +279,6 @@ typedef int pid_t; #define lseek _lseek #define popen _popen #define pclose _pclose -#define umask _umask #define strdup _strdup #define strupr _strupr #define strnicmp _strnicmp diff --git a/src/ChangeLog b/src/ChangeLog index fd2b6db116..18d00ef764 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2013-12-30 Eli Zaretskii + + * w32.c (sys_umask): New function. (Bug#16299) + 2013-12-30 Martin Rudalics * dispnew.c (change_frame_size_1): Take old width of root window diff --git a/src/w32.c b/src/w32.c index dde74bfcdd..3fdb673b63 100644 --- a/src/w32.c +++ b/src/w32.c @@ -5265,6 +5265,35 @@ utime (const char *name, struct utimbuf *times) return 0; } +/* Emacs expects us to support the traditional octal form of the mode + bits, which is not what msvcrt.dll wants. */ + +#define WRITE_USER 00200 + +int +sys_umask (int mode) +{ + static int current_mask; + int retval, arg = 0; + + /* The only bit we really support is the write bit. Files are + always readable on MS-Windows, and the execute bit does not exist + at all. */ + /* FIXME: if the GROUP and OTHER bits are reset, we should use ACLs + to prevent access by other users on NTFS. */ + if ((mode & WRITE_USER) != 0) + arg |= S_IWRITE; + + retval = _umask (arg); + /* Merge into the return value the bits they've set the last time, + which msvcrt.dll ignores and never returns. Emacs insists on its + notion of mask being identical to what we return. */ + retval |= (current_mask & ~WRITE_USER); + current_mask = mode; + + return retval; +} + /* Symlink-related functions. */ #ifndef SYMBOLIC_LINK_FLAG_DIRECTORY -- 2.20.1