The Open Group Base Specifications Issue 7, 2018 edition
IEEE Std 1003.1-2017 (Revision of IEEE Std 1003.1-2008)
Copyright © 2001-2018 IEEE and The Open Group

NAME

stdio.h - standard buffered input/output

SYNOPSIS

#include <stdio.h>

DESCRIPTION

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

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

FILE
A structure containing information about a file.
fpos_t
A non-array type containing all information needed to specify uniquely every position within a file.
off_t
As described in <sys/types.h>.
size_t
As described in <stddef.h>.
ssize_t
[CX] [Option Start] As described in <sys/types.h>. [Option End]
va_list
[CX] [Option Start] As described in <stdarg.h>. [Option End]

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

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

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

_IOFBF
Input/output fully buffered.
_IOLBF
Input/output line buffered.
_IONBF
Input/output unbuffered.

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

SEEK_CUR
Seek relative to current position.
SEEK_END
Seek relative to end-of-file.
SEEK_SET
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:

{FILENAME_MAX}
Maximum size in bytes of the longest pathname that the implementation guarantees can be opened.
{FOPEN_MAX}
Number of streams which the implementation guarantees can be open simultaneously. The value is at least eight.
{TMP_MAX}
[OB] [Option Start] 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. [Option End]

[OB XSI] [Option Start] On XSI-conformant systems, the value of {TMP_MAX} is at least 10000. [Option End]

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

EOF
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 macro which shall expand to a string constant:

P_tmpdir
[OB XSI] [Option Start] Default directory prefix for tempnam(). [Option End]

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:

stderr
Standard error output stream.
stdin
Standard input stream.
stdout
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][Option Start]
char    *ctermid(char *);
int      dprintf(int, const char *restrict, ...)
[Option End]
int      fclose(FILE *);
[CX][Option Start]
FILE    *fdopen(int, const char *);
[Option End]
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][Option Start]
int      fileno(FILE *);
void     flockfile(FILE *);
FILE    *fmemopen(void *restrict, size_t, const char *restrict);
[Option End]
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][Option Start]
int      fseeko(FILE *, off_t, int);
[Option End]
int      fsetpos(FILE *, const fpos_t *);
long     ftell(FILE *);
[CX][Option Start]
off_t    ftello(FILE *);
int      ftrylockfile(FILE *);
void     funlockfile(FILE *);
[Option End]
size_t   fwrite(const void *restrict, size_t, size_t, FILE *restrict);
int      getc(FILE *);
int      getchar(void);
[CX][Option Start]
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);
[Option End]
[OB][Option Start]
char    *gets(char *);
[Option End]
[CX][Option Start]
FILE    *open_memstream(char **, size_t *);
int      pclose(FILE *);
[Option End]
void     perror(const char *);
[CX][Option Start]
FILE    *popen(const char *, const char *);
[Option End]
int      printf(const char *restrict, ...);
int      putc(int, FILE *);
int      putchar(int);
[CX][Option Start]
int      putc_unlocked(int, FILE *);
int      putchar_unlocked(int);
[Option End]
int      puts(const char *);
int      remove(const char *);
int      rename(const char *, const char *);
[CX][Option Start]
int      renameat(int, const char *, int, const char *);
[Option End]
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, ...);
[OB XSI][Option Start]
char    *tempnam(const char *, const char *);
[Option End]
FILE    *tmpfile(void);
[OB][Option Start]
char    *tmpnam(char *);
[Option End]
int      ungetc(int, FILE *);
[CX][Option Start]
int      vdprintf(int, const char *restrict, va_list);
[Option End]
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] [Option Start] Inclusion of the <stdio.h> header may also make visible all symbols from <stddef.h>. [Option End]


The following sections are informative.

APPLICATION USAGE

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.

RATIONALE

There is a conflict between the ISO C standard and the POSIX definition of the {TMP_MAX} macro that is addressed by ISO/IEC 9899:1999 standard, Defect Report 336. The POSIX standard is in alignment with the public record of the response to the Defect Report. This change has not yet been published as part of the ISO C standard.

FUTURE DIRECTIONS

None.

SEE ALSO

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

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

CHANGE HISTORY

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

Issue 5

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.

Issue 6

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 getw() 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 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.

Issue 7

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(), fmemopen(), getdelim(), getline(), open_memstream(), and vdprintf() functions are added from The Open Group Technical Standard, 2006, Extended API Set Part 1.

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

The gets(), tmpnam(), and tempnam() 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.

End of informative text.

 

return to top of page

UNIX ® is a registered Trademark of The Open Group.
POSIX ™ is a Trademark of The IEEE.
Copyright © 2001-2018 IEEE and The Open Group, All Rights Reserved
[ Main Index | XBD | XSH | XCU | XRAT ]