diff options
author | Junio C Hamano <gitster@pobox.com> | 2024-02-06 14:31:21 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-02-06 14:31:21 -0800 |
commit | 1f9d2745fab473fda916642e535e7922cda421ca (patch) | |
tree | e05c0dac6023b1d23ab6f18e0a1506829560f0fd | |
parent | 46b5d75c084d910e8939b495dbcdc211f23eb6a2 (diff) | |
parent | 19ed0dff8f3f19fc15e79d188d7bcaadf26f2f11 (diff) | |
download | git-1f9d2745fab473fda916642e535e7922cda421ca.tar.gz |
Merge branch 'js/win32-retry-pipe-write-on-enospc'
Update to the code that writes to pipes on Windows.
* js/win32-retry-pipe-write-on-enospc:
win32: special-case `ENOSPC` when writing to a pipe
-rw-r--r-- | compat/mingw.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/compat/mingw.c b/compat/mingw.c index 238a84ddba..320fb99a90 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -707,13 +707,24 @@ 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) { + if (result < 0 && (errno == EINVAL || errno == ENOSPC) && buf) { + int orig = errno; + /* check if fd is a pipe */ HANDLE h = (HANDLE) _get_osfhandle(fd); - if (GetFileType(h) == FILE_TYPE_PIPE) + if (GetFileType(h) != FILE_TYPE_PIPE) + errno = orig; + else if (orig == EINVAL) errno = EPIPE; - else - errno = EINVAL; + else { + DWORD buf_size; + + if (!GetNamedPipeInfo(h, NULL, NULL, &buf_size, NULL)) + buf_size = 4096; + if (len > buf_size) + return write(fd, buf, buf_size); + errno = orig; + } } return result; |