From 91226ced0a04302dfe04227aff062cade476a930 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Wed, 19 Jun 2024 11:07:47 +0100 Subject: ash: allow HISTFILE=/dev/null to work as intended It was noted that setting HISTFILE=/dev/null in upstream BusyBox prevented shell history from being saved to a history file. This failed in busybox-w32 with an error from lseek(2). The lseek(2) wrapper was rather conservative in the file types it accepted. Allowing FILE_TYPE_CHAR makes it possible to seek on /dev/null, thus avoiding the issue with HISTFILE. In addition, the wrapper for open(2) now converts the Unix-style mode argument to Windows-style. (GitHub issue #425) --- win32/mingw.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/win32/mingw.c b/win32/mingw.c index 98254fdbe..4398f5462 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -225,7 +225,7 @@ static int mingw_is_directory(const char *path); int mingw_open (const char *filename, int oflags, ...) { va_list args; - unsigned mode; + int pmode, mode = 0666; int fd; int special = (oflags & O_SPECIAL); int dev = get_dev_type(filename); @@ -243,7 +243,10 @@ int mingw_open (const char *filename, int oflags, ...) mode = va_arg(args, int); va_end(args); - fd = open(filename, oflags&~O_SPECIAL, mode); + pmode = ((mode & S_IWUSR) ? _S_IWRITE : 0) | + ((mode & S_IRUSR) ? _S_IREAD : 0); + + fd = open(filename, oflags&~O_SPECIAL, pmode); if (fd >= 0) { update_special_fd(dev, fd); } @@ -2189,12 +2192,14 @@ size_t FAST_FUNC remove_cr(char *p, size_t len) off_t mingw_lseek(int fd, off_t offset, int whence) { + DWORD ftype; HANDLE h = (HANDLE)_get_osfhandle(fd); if (h == INVALID_HANDLE_VALUE) { errno = EBADF; return -1; } - if (GetFileType(h) != FILE_TYPE_DISK) { + ftype = GetFileType(h); + if (ftype != FILE_TYPE_DISK && ftype != FILE_TYPE_CHAR) { errno = ESPIPE; return -1; } -- cgit v1.2.3-55-g6feb