mbed library sources
Dependents: STM32F103C8T6-RangoTec STM32-103C8_Plantilla_USB
Diff: common/retarget.cpp
- Revision:
- 432:255afbe6270c
- Parent:
- 285:31249416b6f9
diff -r d406b7919023 -r 255afbe6270c common/retarget.cpp --- a/common/retarget.cpp Tue Dec 09 14:30:09 2014 +0000 +++ b/common/retarget.cpp Tue Dec 09 14:45:08 2014 +0000 @@ -480,3 +480,55 @@ return (caddr_t) prev_heap; } #endif + + +namespace mbed { + +void mbed_set_unbuffered_stream(FILE *_file) { +#if defined (__ICCARM__) + char buf[2]; + std::setvbuf(_file,buf,_IONBF,NULL); +#else + setbuf(_file, NULL); +#endif +} + +int mbed_getc(FILE *_file){ +#if defined (__ICCARM__) + /*This is only valid for unbuffered streams*/ + int res = std::fgetc(_file); + if (res>=0){ + _file->_Mode = (unsigned short)(_file->_Mode & ~ 0x1000);/* Unset read mode */ + _file->_Rend = _file->_Wend; + _file->_Next = _file->_Wend; + } + return res; +#else + return std::fgetc(_file); +#endif +} + +char* mbed_gets(char*s, int size, FILE *_file){ +#if defined (__ICCARM__) + /*This is only valid for unbuffered streams*/ + char *str = fgets(s,size,_file); + if (str!=NULL){ + _file->_Mode = (unsigned short)(_file->_Mode & ~ 0x1000);/* Unset read mode */ + _file->_Rend = _file->_Wend; + _file->_Next = _file->_Wend; + } + return str; +#else + return std::fgets(s,size,_file); +#endif +} + +} // namespace mbed + + + + + + + +