mirror of https://github.com/ARMmbed/mbed-os.git
Stream class should use mbed::fdopen() to attach a stream
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.pull/4119/head
parent
b2408d8a16
commit
09ae609d56
|
@ -15,8 +15,10 @@
|
|||
*/
|
||||
#include "drivers/RawSerial.h"
|
||||
#include "platform/mbed_wait_api.h"
|
||||
#include <stdio.h>
|
||||
#include <cstdarg>
|
||||
|
||||
|
||||
#if DEVICE_SERIAL
|
||||
|
||||
#define STRING_STACK_LIMIT 120
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
#if defined (DEVICE_SERIAL) || defined(DOXYGEN_ONLY)
|
||||
|
||||
#include "Stream.h"
|
||||
#include "Callback.h"
|
||||
#include "serial_api.h"
|
||||
#include "mbed_toolchain.h"
|
||||
|
|
|
@ -22,9 +22,10 @@ namespace mbed {
|
|||
Stream::Stream(const char *name) : FileLike(name), _file(NULL) {
|
||||
// No lock needed in constructor
|
||||
/* open ourselves */
|
||||
char buf[12]; /* :0x12345678 + null byte */
|
||||
std::sprintf(buf, ":%p", this);
|
||||
_file = std::fopen(buf, "w+");
|
||||
_file = fdopen(this, "w+");
|
||||
// fdopen() will make us buffered because Stream::isatty()
|
||||
// wrongly returns zero which is not being changed for
|
||||
// backward compatibility
|
||||
if (_file) {
|
||||
mbed_set_unbuffered_stream(_file);
|
||||
} else {
|
||||
|
|
|
@ -19,15 +19,16 @@
|
|||
#include "platform/platform.h"
|
||||
#include "platform/FileLike.h"
|
||||
#include "platform/FileHandle.h"
|
||||
#include <cstdio>
|
||||
#include <cstdarg>
|
||||
|
||||
namespace mbed {
|
||||
/** \addtogroup platform */
|
||||
/** @{*/
|
||||
|
||||
extern void mbed_set_unbuffered_stream(FILE *_file);
|
||||
extern int mbed_getc(FILE *_file);
|
||||
extern char* mbed_gets(char *s, int size, FILE *_file);
|
||||
extern void mbed_set_unbuffered_stream(std::FILE *_file);
|
||||
extern int mbed_getc(std::FILE *_file);
|
||||
extern char* mbed_gets(char *s, int size, std::FILE *_file);
|
||||
/** @}*/
|
||||
|
||||
/** File stream
|
||||
|
|
Loading…
Reference in New Issue