mbedmicro/mbed — pull request #770 by GustavWi (2014-12-08 12:21:36+00:00)
Title: Fixed IAR serial fgets fgetc

IAR's Dlib has some problems with unbuffered stream, however I found a workaround. setvbuf with these params generate a buffer with size 1.
+ _file->_Mode = (unsigned short)(_file->_Mode & ~ 0x1000);/* Unset read mode */
Is to remove read mode from _file after read because writes will otherwise be blocked.
+ _file->_Rend = _file->_Wend;
+ _file->_Next = _file->_Wend;
If this is not set the last char from fgets will be rewritten next time (saved in buffer). So for instance if you send a \n to end a string sequence it would be a double new line. The other new line would be written as start of the next string.