Skip to content

Commit 27c08ea

Browse files
committed
fixup! mingw: emulate write(2) that fails with a SIGPIPE
1 parent 583206e commit 27c08ea

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

compat/mingw.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,23 @@ int mingw_fflush(FILE *stream)
580580
return ret;
581581
}
582582

583+
#undef write
584+
ssize_t mingw_write(int fd, const void *buf, size_t len)
585+
{
586+
ssize_t result = write(fd, buf, len);
587+
588+
if (result < 0 && errno == EINVAL && buf) {
589+
/* check if fd is a pipe */
590+
HANDLE h = (HANDLE) _get_osfhandle(fd);
591+
if (GetFileType(h) == FILE_TYPE_PIPE)
592+
errno = EPIPE;
593+
else
594+
errno = EINVAL;
595+
}
596+
597+
return result;
598+
}
599+
583600
int mingw_access(const char *filename, int mode)
584601
{
585602
wchar_t wfilename[MAX_LONG_PATH];

compat/mingw.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -225,22 +225,7 @@ FILE *mingw_freopen (const char *filename, const char *otype, FILE *stream);
225225
int mingw_fflush(FILE *stream);
226226
#define fflush mingw_fflush
227227

228-
static inline ssize_t mingw_write(int fd, const void *buf, size_t len)
229-
{
230-
ssize_t result = write(fd, buf, len);
231-
232-
if (result < 0 && errno == EINVAL && buf) {
233-
/* check if fd is a pipe */
234-
HANDLE h = (HANDLE) _get_osfhandle(fd);
235-
if (GetFileType(h) == FILE_TYPE_PIPE)
236-
errno = EPIPE;
237-
else
238-
errno = EINVAL;
239-
}
240-
241-
return result;
242-
}
243-
228+
ssize_t mingw_write(int fd, const void *buf, size_t len);
244229
#define write mingw_write
245230

246231
int mingw_access(const char *filename, int mode);

0 commit comments

Comments
 (0)