You are allowed in POSIX / ANSI C to read and write on the same stream, but you
have to do an fseek in between read and write call (getc->fseek->putc)
Thanks @Alex-EEE for sharing the fix: https://github.com/ARMmbed/mbed-os/pull/7749
Added test case for verification of the behavior
mbed::fdopen() is provided in mbed_retarget.cpp which will attach a stream to the
given FileHandle. Removing mbed_set_unbuffered_stream() from stream class as it
is defined in mbed_retarget.cpp. Stream class should not decide whether it wants
to detach buffers from c library or not. mbed::fdopen() will do that based upon
isatty() call. So if a FileHandle is not a tty, i.e., is not a device type, c library
buffering will not be turned off. For device type FileHandles, c library buffering
is turned off.
failing on file allocation / opening during Stream creation.
The consequence was application continues running, but any printf
to the Serial object whose Stream was not properly created
would not show any error (and characters would not show either)
Let's add a check to properly inform user of the error.