Does fwrite include a buffer on "\ n"?

I have my implementation _open(), _close(), _write(), _read().

My code is:

FILE *f = fopen("0:test", "wb");  // calls _open()
fwrite("hello ", 6, 1, f);
fwrite("world\r\n\0", 8, 1, f); // calls _write(3, "hello world\r\n", 13)
fflush(f);                      // calls _write(3, "\0", 1)
fclose(f);                      // calls _close(3)

BUFSIZE is 1024

Compiler: arm-none-eabi-gcc/ Version:5.4.1

Why does it fwrite()interpret '\n', although I have flags "wb"?

Does fopen()the file name use "0:test"?

+6
source share
1 answer

Why does it fwrite()interpret '\n', although I have flags "wb"?

Because the stream is buffered by line. Whether streams will be buffered or not is not determined by the flags passed to fopen().

, Red Hat newlib, isatty() . isatty() , .

, _isatty(), 0, setvbuf() fopen().

fopen() "0:test"?

, _open().

+4

All Articles