diff options
Diffstat (limited to 'compat/mingw.c')
-rw-r--r-- | compat/mingw.c | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/compat/mingw.c b/compat/mingw.c index f74da235f5..5edea29508 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -394,6 +394,23 @@ int mingw_fflush(FILE *stream) return ret; } +#undef write +ssize_t mingw_write(int fd, const void *buf, size_t len) +{ + ssize_t result = write(fd, buf, len); + + if (result < 0 && errno == EINVAL && buf) { + /* check if fd is a pipe */ + HANDLE h = (HANDLE) _get_osfhandle(fd); + if (GetFileType(h) == FILE_TYPE_PIPE) + errno = EPIPE; + else + errno = EINVAL; + } + + return result; +} + int mingw_access(const char *filename, int mode) { wchar_t wfilename[MAX_PATH]; @@ -2131,11 +2148,13 @@ void mingw_startup() int uname(struct utsname *buf) { - DWORD v = GetVersion(); + unsigned v = (unsigned)GetVersion(); memset(buf, 0, sizeof(*buf)); - strcpy(buf->sysname, "Windows"); - sprintf(buf->release, "%u.%u", v & 0xff, (v >> 8) & 0xff); + xsnprintf(buf->sysname, sizeof(buf->sysname), "Windows"); + xsnprintf(buf->release, sizeof(buf->release), + "%u.%u", v & 0xff, (v >> 8) & 0xff); /* assuming NT variants only.. */ - sprintf(buf->version, "%u", (v >> 16) & 0x7fff); + xsnprintf(buf->version, sizeof(buf->version), + "%u", (v >> 16) & 0x7fff); return 0; } |