Skip to content

fgets() returns prematurely in non-canonical input mode #140

@Galfurian

Description

@Galfurian

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:

  1. Disable ICANON and ECHO in a user process.
  2. Call fgets(buf, size, STDIN_FILENO).
  3. 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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions