Skip to content

Commit

Permalink
ash: allow HISTFILE=/dev/null to work as intended
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
rmyorston committed Jun 19, 2024
1 parent 0914f11 commit 91226ce
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions win32/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 91226ce

Please # to comment.