diff options
author | Ron Yorston <rmy@pobox.com> | 2024-06-19 11:07:47 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2024-06-19 11:07:47 +0100 |
commit | 91226ced0a04302dfe04227aff062cade476a930 (patch) | |
tree | 53d75a835d677428713a6444575d7d21a06a5160 | |
parent | 0914f116c06d4724f25e23b685279024f809f434 (diff) | |
download | busybox-w32-91226ced0a04302dfe04227aff062cade476a930.tar.gz busybox-w32-91226ced0a04302dfe04227aff062cade476a930.tar.bz2 busybox-w32-91226ced0a04302dfe04227aff062cade476a930.zip |
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)
-rw-r--r-- | win32/mingw.c | 11 |
1 files 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); | |||
225 | int mingw_open (const char *filename, int oflags, ...) | 225 | int mingw_open (const char *filename, int oflags, ...) |
226 | { | 226 | { |
227 | va_list args; | 227 | va_list args; |
228 | unsigned mode; | 228 | int pmode, mode = 0666; |
229 | int fd; | 229 | int fd; |
230 | int special = (oflags & O_SPECIAL); | 230 | int special = (oflags & O_SPECIAL); |
231 | int dev = get_dev_type(filename); | 231 | int dev = get_dev_type(filename); |
@@ -243,7 +243,10 @@ int mingw_open (const char *filename, int oflags, ...) | |||
243 | mode = va_arg(args, int); | 243 | mode = va_arg(args, int); |
244 | va_end(args); | 244 | va_end(args); |
245 | 245 | ||
246 | fd = open(filename, oflags&~O_SPECIAL, mode); | 246 | pmode = ((mode & S_IWUSR) ? _S_IWRITE : 0) | |
247 | ((mode & S_IRUSR) ? _S_IREAD : 0); | ||
248 | |||
249 | fd = open(filename, oflags&~O_SPECIAL, pmode); | ||
247 | if (fd >= 0) { | 250 | if (fd >= 0) { |
248 | update_special_fd(dev, fd); | 251 | update_special_fd(dev, fd); |
249 | } | 252 | } |
@@ -2189,12 +2192,14 @@ size_t FAST_FUNC remove_cr(char *p, size_t len) | |||
2189 | 2192 | ||
2190 | off_t mingw_lseek(int fd, off_t offset, int whence) | 2193 | off_t mingw_lseek(int fd, off_t offset, int whence) |
2191 | { | 2194 | { |
2195 | DWORD ftype; | ||
2192 | HANDLE h = (HANDLE)_get_osfhandle(fd); | 2196 | HANDLE h = (HANDLE)_get_osfhandle(fd); |
2193 | if (h == INVALID_HANDLE_VALUE) { | 2197 | if (h == INVALID_HANDLE_VALUE) { |
2194 | errno = EBADF; | 2198 | errno = EBADF; |
2195 | return -1; | 2199 | return -1; |
2196 | } | 2200 | } |
2197 | if (GetFileType(h) != FILE_TYPE_DISK) { | 2201 | ftype = GetFileType(h); |
2202 | if (ftype != FILE_TYPE_DISK && ftype != FILE_TYPE_CHAR) { | ||
2198 | errno = ESPIPE; | 2203 | errno = ESPIPE; |
2199 | return -1; | 2204 | return -1; |
2200 | } | 2205 | } |