bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ABI/API wgetch: indiscernible return (timer/EOF)


From: Leon Winter
Subject: ABI/API wgetch: indiscernible return (timer/EOF)
Date: Tue, 11 Aug 2020 09:09:12 +0200

Hi Thomas,

the function wgetch returns ERR and errno set to zero if the timer expired.
Unfortunately the same the return happens when EOF is reached on stdin :(
(Actually errno is not set to zero but rather not set at all, but best practise
dictates one zeroes it before calling errno-setting functions)

See the following example:

// gcc main.c -lncurses
#include <curses.h>
#include <errno.h>
#include <unistd.h>

void
read_key (WINDOW *const w)
{ errno = 0;
  const int key = wgetch (w);
  if (key == ERR) fprintf (stderr, "wgetch = ERR, errno = %d\n", errno);
}

int
main (int argc, char **argv)
{ initscr ();
  cbreak ();
  noecho ();

  WINDOW *const w = newwin (1, 1, 0, 0);
  keypad (w, true);

  int fd[2];
  if (pipe (fd) == -1) return 1;
  if (dup2 (fd[0], 0) == -1) return 1;

  wtimeout (w, 1);
  read_key (w);

  wtimeout (w, -1);
  close (fd[1]);
  read_key (w);

  endwin ();
  return 0;
}

I would be quite nice for the caller to able to tell them apart.

Regards,
Leon



reply via email to

[Prev in Thread] Current Thread [Next in Thread]