interaction of _read on fd 0 in terminal #20799

Open
opened 2026-01-31 07:24:25 +00:00 by claunia · 0 comments
Owner

Originally created by @spk121 on GitHub (Nov 12, 2023).

Originally assigned to: @lhecker on GitHub.

Windows Terminal version

1.19.2682.0

Windows build number

Version 10.0.22621.2428

Other Software

No response

Steps to reproduce

Compile the attached, run, and press enter multiple times. Behavior is the same with MSVC in Visual studio 2022 and with latest MinGW with GCC using 64-bit UCRT.

#include <io.h>
#include <stdio.h>
#include <errno.h>


int main()
{
  int fd = 0;
  printf("fd = %d\n", fd);

  int ret;
  char buf[128];

  while (1)
    {
      errno = 0;
      ret = _read (fd, buf, 1);
      printf("ret = %d, errno = %d, char = %u\n", ret, errno, buf[0]);
    }
  return 0;
}

Expected Behavior

I expected the behavior found on MinGW's mintty, when I press the enter key multiple times.

fd = 0

ret = 1, errno = 0, char = 10

ret = 1, errno = 0, char = 10

ret = 1, errno = 0, char = 10

ret = 1, errno = 0, char = 10

Actual Behavior

This is what happens in Terminal when I press the enter key multiple times on a recent Terminal

fd = 0


ret = 1, errno = 0, char = 13
ret = -1, errno = 13, char = 13


ret = 1, errno = 0, char = 13
ret = -1, errno = 13, char = 13


ret = 1, errno = 0, char = 13
ret = -1, errno = 13, char = 13


ret = 1, errno = 0, char = 13
ret = -1, errno = 13, char = 13
Originally created by @spk121 on GitHub (Nov 12, 2023). Originally assigned to: @lhecker on GitHub. ### Windows Terminal version 1.19.2682.0 ### Windows build number Version 10.0.22621.2428 ### Other Software _No response_ ### Steps to reproduce Compile the attached, run, and press enter multiple times. Behavior is the same with MSVC in Visual studio 2022 and with latest MinGW with GCC using 64-bit UCRT. ``` #include <io.h> #include <stdio.h> #include <errno.h> int main() { int fd = 0; printf("fd = %d\n", fd); int ret; char buf[128]; while (1) { errno = 0; ret = _read (fd, buf, 1); printf("ret = %d, errno = %d, char = %u\n", ret, errno, buf[0]); } return 0; } ``` ### Expected Behavior I expected the behavior found on MinGW's mintty, when I press the enter key multiple times. ``` fd = 0 ret = 1, errno = 0, char = 10 ret = 1, errno = 0, char = 10 ret = 1, errno = 0, char = 10 ret = 1, errno = 0, char = 10 ``` ### Actual Behavior This is what happens in Terminal when I press the enter key multiple times on a recent Terminal ``` fd = 0 ret = 1, errno = 0, char = 13 ret = -1, errno = 13, char = 13 ret = 1, errno = 0, char = 13 ret = -1, errno = 13, char = 13 ret = 1, errno = 0, char = 13 ret = -1, errno = 13, char = 13 ret = 1, errno = 0, char = 13 ret = -1, errno = 13, char = 13 ```
claunia added the Issue-BugIn-PRArea-InputNeeds-Tag-FixArea-Server labels 2026-01-31 07:24:25 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#20799