fgets() returns prematurely in non-canonical input mode
Description:
When fgets() is used with STDIN_FILENO and the process has ICANON disabled in its termios configuration, the function may return immediately without blocking for a full line, even if no input is available. This violates the expected behavior of fgets(), which should block until a full line is available (ending with \n) or EOF is reached.
Steps to Reproduce:
- Disable
ICANON and ECHO in a user process.
- Call
fgets(buf, size, STDIN_FILENO).
- Observe that the call returns immediately with a possibly empty or partial string.
Expected Behavior:
fgets() should block until a full line is available, even in non-canonical mode, or otherwise simulate canonical behavior.
Suggested Fix:
Either:
- Force
fgets() to block and accumulate until \n is read, regardless of terminal mode, or
- Document that
fgets() must be used in canonical mode only.
fgets() returns prematurely in non-canonical input mode
Description:
When
fgets()is used withSTDIN_FILENOand the process hasICANONdisabled in itstermiosconfiguration, the function may return immediately without blocking for a full line, even if no input is available. This violates the expected behavior offgets(), which should block until a full line is available (ending with\n) or EOF is reached.Steps to Reproduce:
ICANONandECHOin a user process.fgets(buf, size, STDIN_FILENO).Expected Behavior:
fgets()should block until a full line is available, even in non-canonical mode, or otherwise simulate canonical behavior.Suggested Fix:
Either:
fgets()to block and accumulate until\nis read, regardless of terminal mode, orfgets()must be used in canonical mode only.