I was wondering the difference between stdout
and STDOUT_FILENO
in Linux C.
After some searching work, I draw the following conclusion. Could you help me review it and correct any mistake in it? Thanks
stdout
belongs to standard I/O stream of C language; whose type is FILE* and defined in stdio.h
STDOUT_FILENO
, possessing an int type, is defined at unistd.h
. It's a file descriptor of LINUX system. In unistd.h
, it's explained as below:
The following symbolic constants shall be defined for file streams: STDERR_FILENO File number of stderr; 2. STDIN_FILENO File number of stdin; 0. STDOUT_FILENO File number of stdout; 1.
So, in my opinion, the STDOUT_FILENO
belongs system-level calling and, to some extent, like a system API. STDOUT_FILENO
can be used to describe any device in system.
The stdout
locates in a higher level (user level?) and actually encapsulate the details of STDOUT_FILENO
. stdout
has I/O buffer.
That's my understand about their difference. Any comment or correction is appreciated, thanks.