aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-02-13 14:44:51 -0800
committerJunio C Hamano <gitster@pobox.com>2024-02-13 14:44:51 -0800
commit8d792dcd5aa8a412670bd12f07cdc8290e3b9a68 (patch)
tree3a9920300ca6054b47165b24a60187cd55db8735
parent08b7e46bb1a6d02b906efce9a52fc29f0d8e1bce (diff)
parent19ed0dff8f3f19fc15e79d188d7bcaadf26f2f11 (diff)
downloadgit-8d792dcd5aa8a412670bd12f07cdc8290e3b9a68.tar.gz
Merge branch 'js/win32-retry-pipe-write-on-enospc' into maint-2.43
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.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/compat/mingw.c b/compat/mingw.c
index 42053c1f65..4bcbccf01a 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;