1
0
mirror of https://github.com/git/git.git synced 2024-09-22 05:31:42 +02:00

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
This commit is contained in:
Junio C Hamano 2024-02-13 14:44:51 -08:00
commit 8d792dcd5a

View File

@ -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;