···33#include "../errno.h"
44#include <linux-syscalls/linux.h>
55#include "../bsdthread/cancelable.h"
66+#include "../misc/ioctl.h"
77+#include "../duct_errno.h"
88+99+#define LINUX_TCGETA 0x5405
610711long sys_read(int fd, void* mem, int len)
812{
···16201721 ret = LINUX_SYSCALL3(__NR_read, fd, mem, len);
1822 if (ret < 0)
2323+ {
2424+ // When the slave side of a PTY is closed, Linux produces -EIO on the master side.
2525+ // macOS produces an EOF.
2626+ if (ret == -LINUX_EIO)
2727+ {
2828+ // Not making this static makes everything go boom. Do we have a too small stack somewhere?
2929+ static char dummy[18];
3030+ if (__real_ioctl(fd, LINUX_TCGETA, dummy) == 0) // "isatty(fd)"
3131+ return 0;
3232+ }
1933 return errno_linux_to_bsd(ret);
3434+ }
20352136 return ret;
2237}