STDIO.H(7) Miscellaneous Information Manual STDIO.H(7)

stdio.hstandard buffered input/output

#include <stdio.h>

[CX] Some of the functionality described on this reference page extends the ISO C standard. Applications shall define the appropriate feature test macro (see XSH V2_chap02(3)) to enable the visibility of these symbols in this header.

The <stdio.h> header shall define the following data types through :

A type containing information about a file. The FILE type may be an incomplete type.
A complete object type, other than an array type, capable of recording all the information needed to specify uniquely every position within a file.
As described in <sys/types.h> .
As described in <stddef.h> .
[CX] As described in <sys/types.h> .
[CX] As described in <stdarg.h> .

The <stdio.h> header shall define the following macros which shall expand to integer constant expressions:

Size of <stdio.h> buffers. [CX] This shall expand to a positive value.
[CX] Maximum size of character array to hold () output.
[OB] Maximum size of character array to hold tmpnam () output.

The <stdio.h> header shall define the following macros which shall expand to integer constant expressions with distinct values:

Input/output fully buffered.
Input/output line buffered.
Input/output unbuffered.

The <stdio.h> header shall define the following macros which shall expand to integer constant expressions with distinct values:

Seek relative to current position.
Seek relative to end-of-file.
Seek relative to start-of-file.

The <stdio.h> header shall define the following macros which shall expand to integer constant expressions denoting implementation limits:

Maximum size in bytes of the longest pathname that the implementation guarantees can be opened.
Number of streams which the implementation guarantees can be open simultaneously. The value is at least eight.
[OB] Minimum number of unique filenames generated by tmpnam () . Maximum number of times an application can call tmpnam () reliably. The value of {TMP_MAX} is at least 25.

On XSI-conformant systems, the value of {TMP_MAX} is at least 10000.

The <stdio.h> header shall define the following macro which shall expand to an integer constant expression with type and a negative value:

End-of-file return value.

The <stdio.h> header shall define NULL as described in <stddef.h>.

The <stdio.h> header shall define the following macros which shall expand to expressions of type "pointer to FILE " that point to the FILE objects associated, respectively, with the standard error, input, and output streams:

Standard error output stream.
Standard input stream.
Standard output stream.

The following shall be declared as functions and may also be defined as macros. Function prototypes shall be provided.

void     clearerr(FILE *);
[CX]
char    *ctermid(char *);
int      dprintf(int, const char *restrict, ...)

int      fclose(FILE *);
[CX]
FILE    *fdopen(int, const char *);

int      feof(FILE *);
int      ferror(FILE *);
int      fflush(FILE *);
int      fgetc(FILE *);
int      fgetpos(FILE *restrict, fpos_t *restrict);
char    *fgets(char *restrict, int, FILE *restrict);
[CX]
int      fileno(FILE *);
void     flockfile(FILE *);
FILE    *fmemopen(void *restrict, size_t, const char *restrict);

FILE    *fopen(const char *restrict, const char *restrict);
int      fprintf(FILE *restrict, const char *restrict, ...);
int      fputc(int, FILE *);
int      fputs(const char *restrict, FILE *restrict);
size_t   fread(void *restrict, size_t, size_t, FILE *restrict);
FILE    *freopen(const char *restrict, const char *restrict,
             FILE *restrict);
int      fscanf(FILE *restrict, const char *restrict, ...);
int      fseek(FILE *, long, int);
[CX]
int      fseeko(FILE *, off_t, int);

int      fsetpos(FILE *, const fpos_t *);
long     ftell(FILE *);
[CX]
off_t    ftello(FILE *);
int      ftrylockfile(FILE *);
void     funlockfile(FILE *);

size_t   fwrite(const void *restrict, size_t, size_t, FILE *restrict);
int      getc(FILE *);
int      getchar(void);
[CX]
int      getc_unlocked(FILE *);
int      getchar_unlocked(void);
ssize_t  getdelim(char **restrict, size_t *restrict, int,
             FILE *restrict);
ssize_t  getline(char **restrict, size_t *restrict, FILE *restrict);
FILE    *open_memstream(char **, size_t *);
int      pclose(FILE *);

void     perror(const char *);
[CX]
FILE    *popen(const char *, const char *);

int      printf(const char *restrict, ...);
int      putc(int, FILE *);
int      putchar(int);
[CX]
int      putc_unlocked(int, FILE *);
int      putchar_unlocked(int);

int      puts(const char *);
int      remove(const char *);
int      rename(const char *, const char *);
[CX]
int      renameat(int, const char *, int, const char *);

void     rewind(FILE *);
int      scanf(const char *restrict, ...);
void     setbuf(FILE *restrict, char *restrict);
int      setvbuf(FILE *restrict, char *restrict, int, size_t);
int      snprintf(char *restrict, size_t, const char *restrict, ...);
int      sprintf(char *restrict, const char *restrict, ...);
int      sscanf(const char *restrict, const char *restrict, ...);
FILE    *tmpfile(void);
[OB]
char    *tmpnam(char *);

int      ungetc(int, FILE *);
[CX]
int      vdprintf(int, const char *restrict, va_list);

int      vfprintf(FILE *restrict, const char *restrict, va_list);
int      vfscanf(FILE *restrict, const char *restrict, va_list);
int      vprintf(const char *restrict, va_list);
int      vscanf(const char *restrict, va_list);
int      vsnprintf(char *restrict, size_t, const char *restrict,
             va_list);
int      vsprintf(char *restrict, const char *restrict, va_list);
int      vsscanf(const char *restrict, const char *restrict, va_list);

[CX] Inclusion of the <stdio.h> header may also make visible all symbols from <stddef.h>.

Since standard I/O streams may use an underlying file descriptor to access the file associated with a stream, application developers need to be aware that {FOPEN_MAX} streams may not be available if file descriptors are being used to access files that are not associated with streams.

Since the latest revision of the ISO C standard allows FILE to be an incomplete type (and POSIX also allows it), portable applications can no longer allocate or copy an object of type FILE; only pointers to objects of type FILE can be allocated.

None.

None.

<stdarg.h>, <stddef.h>, <sys/types.h>

XSH V2_chap02(3), clearerr(3), ctermid(3), fclose(3), fdopen(3), feof(3), ferror(3), fflush(3), fgetc(3), fgetpos(3), fgets(3), fileno(3), flockfile(3), fmemopen(3), fopen(3), fprintf(3), fputc(3), fputs(3), fread(3), freopen(3), fscanf(3), fseek(3), fsetpos(3), ftell(3), fwrite(3), getc(3), getchar(3), getc_unlocked(3), getdelim(3), getopt(3), open_memstream(3), pclose(3), perror(3), popen(3), putc(3), putchar(3), puts(3), remove(3), rename(3), rewind(3), setbuf(3), setvbuf(3), stdin(3), system(3), tmpfile(3), tmpnam(3), ungetc(3), vfprintf(3), vfscanf(3)

First released in Issue 1. Derived from Issue 1 of the SVID.

The DESCRIPTION is updated for alignment with the POSIX Threads Extension.

Large File System extensions are added.

The constant L_cuserid and the external variables optarg, opterr, optind, and optopt are marked as extensions and LEGACY.

The cuserid () and getopt () functions are marked LEGACY.

The constant L_cuserid and the external variables optarg, opterr, optind, and optopt are removed as they were previously marked LEGACY.

The cuserid (), getopt (), and () functions are removed as they were previously marked LEGACY.

Several functions are marked as part of the Thread-Safe Functions option.

This reference page is updated to align with the ISO/IEC 9899:1999 (“ISO C99”) standard. Note that the description of the fpos_t type is now explicitly updated to exclude array types.

Extensions beyond the ISO C standard are marked.

Austin Group Interpretation 1003.1-2001 #172 is applied, adding rationale about a conflict for the definition of {TMP_MAX} with the ISO C standard.

SD5-XBD-ERN-99 is applied, adding APPLICATION USAGE.

The dprintf(3), fmemopen(3), getdelim(3), getline(3), open_memstream(3), and vdprintf(3) functions are added from The Open Group Technical Standard, 2006, Extended API Set Part 1.

The renameat(3) function is added from The Open Group Technical Standard, 2006, Extended API Set Part 2.

The (), tmpnam(3), and () functions and the L_tmpnam macro are marked obsolescent.

This reference page is clarified with respect to macros and symbolic constants, and a declaration for the off_t type is added.

POSIX.1-2008, Technical Corrigendum 1, XBD/TC1-2008/0065 [291,427] is applied.

Austin Group Defect 1054 is applied, allowing FILE to be an incomplete type.

Austin Group Defect 1302 is applied, aligning this header with the ISO/IEC 9899:2018 standard.

Austin Group Defect 1330 is applied, removing obsolescent interfaces.

June 14, 2024 posix.fail