STDIN(3POSIX)

πŸ’– STDIN(3POSIX) πŸ’–

okay bestie, welcome to the POSIX Programmer's Manual, the one and only. this page is literally about stderr, stdin, and stdout, and honestly? they run your entire life, you just don't know it yet. let's get into it 🫢


🌸 PROLOG 🌸

so like, real talk first: this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ β€” so if you're on Linux, go consult the corresponding Linux manual page for the actual deets on Linux behavior. and also? the interface might not even be implemented on Linux at all. not me warning you twice πŸ’€. just check, okay?


✨ NAME ✨

stderr, stdin, stdout β€” the standard I/O streams. the holy trinity. the main characters. πŸ‘‘


πŸŽ€ SYNOPSIS πŸŽ€

#include <stdio.h>

extern FILE *stderr, *stdin, *stdout;

look at them. three little pointers. iconic.


πŸ’… DESCRIPTION πŸ’…

so the functionality described on this reference page is aligned with the ISO C standard. and if there's any conflict between the requirements described here and the ISO C standard? that's unintentional, bestie, no drama intended. this volume of POSIX.1‐2017 defers to the ISO C standard, periodt.

okay now the actual tea β˜•:

a file with associated buffering is called a stream, and it's declared to be a pointer to a defined type FILE. the fopen() function shall create certain descriptive data for a stream and return a pointer to designate the stream in all further transactions. and normally? there are three open streams with constant pointers declared in the <stdio.h> header, and they're associated with the standard open files. three besties, forever linked.

at program start-up, three streams shall be predefined and need not be opened explicitly:

  • standard input β€” for reading conventional input
  • standard output β€” for writing conventional output
  • standard error β€” for writing diagnostic output

and here's the buffering lore you need to know: when opened, the standard error stream is not fully buffered. the standard input and standard output streams are fully buffered if and only if the stream can be determined not to refer to an interactive device. yes, "if and only if" β€” that's a real logic gate, not a vibe. 🧚

the following symbolic values in <unistd.h> define the file descriptors that shall be associated with the C-language stdin, stdout, and stderr when the application is started:

  • STDIN_FILENO β€” standard input value, stdin. its value is 0.
  • STDOUT_FILENO β€” standard output value, stdout. its value is 1.
  • STDERR_FILENO β€” standard error value, stderr. its value is 2.

zero, one, two. that's it. that's the whole numeric identity crisis. πŸ”₯

and one more thing: the stderr stream is expected to be open for reading and writing. both. she contains multitudes. πŸ’œ


⭐ RETURN VALUE ⭐

None. nothing. nada. it returns absolutely nothing, and honestly? relatable.


🌈 ERRORS 🌈

no errors are defined. zero. none. flawless behavior, we love to see it. ✨

heads up: the following sections are informative. that's the official word, not me being shady.

πŸ¦‹ EXAMPLES πŸ¦‹

None. (yes, really. the examples section said "no thoughts, head empty." πŸ™ˆ)


πŸ“ APPLICATION USAGE πŸ“

None. moving on bestie, nothing to see here.


πŸ‘‘ RATIONALE πŸ‘‘

None. the reasoning is simply vibes. (fr fr, that's what it says.)


πŸ’€ FUTURE DIRECTIONS πŸ’€

None. the future is unwritten, and this page is not about to speculate. 😭


🫢 SEE ALSO 🫢

go read these next, they're all in the same friend group:

  • fclose()
  • feof()
  • ferror()
  • fileno()
  • fopen()
  • fprintf()
  • fread()
  • fscanf()
  • fseek()
  • getc()
  • gets()
  • popen()
  • putc()
  • puts()
  • read()
  • setbuf()
  • setvbuf()
  • tmpfile()
  • ungetc()
  • vfprintf()

also the Base Definitions volume of POSIX.1‐2017: <stdio.h>, <unistd.h> β€” the header files themselves, the origin stories. πŸ’–


okay this part is long but it matters, so here it is in full:

portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. the original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. to report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .

so basically: if this page and the official Standard disagree, the Standard wins. no cap. the Standard is the main character here. πŸ’…

and that's the whole page, bestie!! this was brought to you by IEEE/The Open Group, 2017, and the page itself is STDIN(3POSIX) β€” mwah, take care of your streams, they take care of you πŸ’–βœ¨πŸŽ€πŸ¦‹