fgets always returns NULL on stdin

tedwood
Posts: 11
Joined: Thu Mar 16, 2017 2:02 pm

fgets always returns NULL on stdin

Postby tedwood » Mon Mar 20, 2017 12:36 pm

I'm trying to use fgets to read from a terminal on stdin. Rather than waiting for a return, a full buffer or an EOF it always returns NULL.
When I type a characters in it gets it - sometimes more than one character. Is there a timeout somewhere that I'm not aware of?

Code looks like this n(i.e. it always returns NO_INPUT)

int getLine (char *prmpt, char *buff, size_t sz) {
int ch, extra;

// Get line with buffer overrun protection.
if (prmpt != NULL)
{
printf ("%s", prmpt);
fflush (stdout);
}

if (fgets (buff, sz,stdin) == NULL)
{
return NO_INPUT;
}

if (buff[strlen(buff)-1] != '\n') {
extra = 0;
while (((ch = getchar()) != '\n') && (ch != EOF))
extra = 1;
return (extra == 1) ? TOO_LONG : OK;
}

buff[strlen(buff)-1] = '\0';
return OK;
}

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: fgets always returns NULL on stdin

Postby ESP_igrr » Mon Mar 20, 2017 5:03 pm

reads from stdin currently behave as O_NONBLOCK, which is mentioned here:
http://esp-idf.readthedocs.io/en/latest ... out-stderr
The function which reads from the UART gets all the characters present in the FIFO and returns. Blocking reads support is something which needs to be implemented.

Who is online

Users browsing this forum: No registered users and 196 guests