stdin(3)


NAME

   stdin, stdout, stderr - standard I/O streams

SYNOPSIS

   #include <stdio.h>

   extern FILE *stdin;
   extern FILE *stdout;
   extern FILE *stderr;

DESCRIPTION

   Under  normal circumstances every UNIX program has three streams opened
   for it when it starts up, one for input, one for output,  and  one  for
   printing diagnostic or error messages.  These are typically attached to
   the user's terminal (see tty(4) but might instead  refer  to  files  or
   other  devices,  depending  on what the parent process chose to set up.
   (See also the "Redirection" section of sh(1).)

   The input stream is referred to as "standard input"; the output  stream
   is  referred  to as "standard output"; and the error stream is referred
   to as "standard error".   These  terms  are  abbreviated  to  form  the
   symbols used to refer to these files, namely stdin, stdout, and stderr.

   Each  of these symbols is a stdio(3) macro of type pointer to FILE, and
   can be used with functions like fprintf(3) or fread(3).

   Since FILEs are a buffering wrapper around UNIX file  descriptors,  the
   same  underlying  files  may  also  be accessed using the raw UNIX file
   interface, that is, the functions like read(2) and lseek(2).

   On program startup, the integer file descriptors  associated  with  the
   streams  stdin,  stdout, and stderr are 0, 1, and 2, respectively.  The
   preprocessor symbols STDIN_FILENO, STDOUT_FILENO, and STDERR_FILENO are
   defined  with  these values in <unistd.h>.  (Applying freopen(3) to one
   of these streams can change the file descriptor number associated  with
   the stream.)

   Note  that  mixing  use  of  FILEs and raw file descriptors can produce
   unexpected  results  and  should  generally  be  avoided.    (For   the
   masochistic  among you: POSIX.1, section 8.2.3, describes in detail how
   this interaction is supposed to work.)  A general  rule  is  that  file
   descriptors  are  handled in the kernel, while stdio is just a library.
   This means for example, that after an exec(3), the child  inherits  all
   open file descriptors, but all old streams have become inaccessible.

   Since the symbols stdin, stdout, and stderr are specified to be macros,
   assigning to them is nonportable.  The standard streams can be made  to
   refer  to different files with help of the library function freopen(3),
   specially introduced to make it possible to reassign stdin, stdout, and
   stderr.   The  standard  streams are closed by a call to exit(3) and by
   normal program termination.

CONFORMING TO

   The stdin, stdout, and stderr macros conform to C89 and  this  standard
   also  stipulates  that  these  three  streams  shall be open at program
   startup.

NOTES

   The stream stderr is unbuffered.  The stream  stdout  is  line-buffered
   when  it  points  to  a  terminal.  Partial lines will not appear until
   fflush(3) or exit(3) is called, or a  newline  is  printed.   This  can
   produce  unexpected  results,  especially  with  debugging output.  The
   buffering mode of the standard streams (or any  other  stream)  can  be
   changed  using  the  setbuf(3)  or  setvbuf(3) call.  Note that in case
   stdin is associated with a terminal, there may also be input  buffering
   in   the  terminal  driver,  entirely  unrelated  to  stdio  buffering.
   (Indeed, normally terminal input is line buffered in the kernel.)  This
   kernel  input  handling  can be modified using calls like tcsetattr(3);
   see also stty(1), and termios(3).

SEE ALSO

   csh(1), sh(1), open(2), fopen(3), stdio(3)

COLOPHON

   This page is part of release 4.09 of the Linux  man-pages  project.   A
   description  of  the project, information about reporting bugs, and the
   latest    version    of    this    page,    can     be     found     at
   https://www.kernel.org/doc/man-pages/.





Opportunity


Personal Opportunity - Free software gives you access to billions of dollars of software at no cost. Use this software for your business, personal use or to develop a profitable skill. Access to source code provides access to a level of capabilities/information that companies protect though copyrights. Open source is a core component of the Internet and it is available to you. Leverage the billions of dollars in resources and capabilities to build a career, establish a business or change the world. The potential is endless for those who understand the opportunity.

Business Opportunity - Goldman Sachs, IBM and countless large corporations are leveraging open source to reduce costs, develop products and increase their bottom lines. Learn what these companies know about open source and how open source can give you the advantage.





Free Software


Free Software provides computer programs and capabilities at no cost but more importantly, it provides the freedom to run, edit, contribute to, and share the software. The importance of free software is a matter of access, not price. Software at no cost is a benefit but ownership rights to the software and source code is far more significant.


Free Office Software - The Libre Office suite provides top desktop productivity tools for free. This includes, a word processor, spreadsheet, presentation engine, drawing and flowcharting, database and math applications. Libre Office is available for Linux or Windows.





Free Books


The Free Books Library is a collection of thousands of the most popular public domain books in an online readable format. The collection includes great classical literature and more recent works where the U.S. copyright has expired. These books are yours to read and use without restrictions.


Source Code - Want to change a program or know how it works? Open Source provides the source code for its programs so that anyone can use, modify or learn how to write those programs themselves. Visit the GNU source code repositories to download the source.





Education


Study at Harvard, Stanford or MIT - Open edX provides free online courses from Harvard, MIT, Columbia, UC Berkeley and other top Universities. Hundreds of courses for almost all major subjects and course levels. Open edx also offers some paid courses and selected certifications.


Linux Manual Pages - A man or manual page is a form of software documentation found on Linux/Unix operating systems. Topics covered include computer programs (including library and system calls), formal standards and conventions, and even abstract concepts.