This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

fgets and _IONBF - bug?

Hi all,

I'm implementing an stdio-uart bridge based on TivaWare. The structure is pretty much this:

UART -> Hardware FIFO -> uDMA -> Ring buffer -> stdio

I used the add_device functionality of the TI C library to provide the functionality, and it seems to be working for both inputs and outputs.

But when I disable buffering at the stdio level (using setvbuf and _IONBF), fgets no longer works "as advertised". It stops honouring the size parameter, instead going on until '\n' is reached, no matter how far that is. Checking the source code for fgets, it's apparent why this is so:

From FGETS.C v5.1.1, line 135

      } while (*fpos++ != '\n'); 

There is no checking for how many bytes have been read, only for the newline. Is this intended, or am I missing something?