The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
stdio.h File Reference

buffered streams and formatted input/output. More...

#include <sys/types.h>
#include <stdarg.h>

Go to the source code of this file.

Macros

#define NULL   ((void *)0)
#define EOF   (-1)
#define BUFSIZ   1024
#define FILENAME_MAX   256
#define _IOFBF   0
#define _IOLBF   1
#define _IONBF   2
#define SEEK_SET   0
#define SEEK_CUR   1
#define SEEK_END   2

Typedefs

typedef struct stdio_file FILE
typedef off_t fpos_t

Functions

FILE * fopen (const char *path, const char *mode)
FILE * fdopen (int fd, const char *mode)
int fclose (FILE *stream)
int fflush (FILE *stream)
FILE * freopen (const char *path, const char *mode, FILE *stream)
 give a stream another file: the old file is closed, the stream keeps its fd number (so freopen on stdin or stdout changes fd 0 or 1).
FILE * tmpfile (void)
 a new file for reading and writing that goes when it is closed (it is made in /tmp and removed at once).
FILE * popen (const char *command, const char *mode)
 run "sh -c command" with a pipe to its standard output ("r") or from its standard input ("w").
int pclose (FILE *stream)
 close a stream of popen and wait for the command.
int setvbuf (FILE *stream, char *buf, int mode, size_t size)
void setbuf (FILE *stream, char *buf)
int fileno (FILE *stream)
size_t fread (void *ptr, size_t size, size_t count, FILE *stream)
size_t fwrite (const void *ptr, size_t size, size_t count, FILE *stream)
int fgetc (FILE *stream)
int getc (FILE *stream)
int getchar (void)
int ungetc (int c, FILE *stream)
char * fgets (char *buf, int size, FILE *stream)
int fputc (int c, FILE *stream)
int putc (int c, FILE *stream)
int putchar (int c)
int fputs (const char *s, FILE *stream)
int puts (const char *s)
int fseek (FILE *stream, long offset, int whence)
long ftell (FILE *stream)
int fseeko (FILE *stream, off_t offset, int whence)
off_t ftello (FILE *stream)
int fgetpos (FILE *stream, fpos_t *pos)
int fsetpos (FILE *stream, const fpos_t *pos)
void rewind (FILE *stream)
int feof (FILE *stream)
int ferror (FILE *stream)
void clearerr (FILE *stream)
int printf (const char *fmt,...) __attribute__((format(printf
 formatted output.
int int fprintf (FILE *stream, const char *fmt,...) __attribute__((format(printf
int int int dprintf (int fd, const char *fmt,...) __attribute__((format(printf
int int int int sprintf (char *buf, const char *fmt,...) __attribute__((format(printf
int int int int int snprintf (char *buf, size_t size, const char *fmt,...) __attribute__((format(printf
int int int int int int vprintf (const char *fmt, va_list ap)
int vfprintf (FILE *stream, const char *fmt, va_list ap)
int vdprintf (int fd, const char *fmt, va_list ap)
int vsprintf (char *buf, const char *fmt, va_list ap)
int vsnprintf (char *buf, size_t size, const char *fmt, va_list ap)
int sscanf (const char *str, const char *fmt,...)
 formatted input from a string: d i u x o c s %[...] n and %%, with widths and the lengths hh h l ll z.
int rename (const char *old_path, const char *new_path)
 rename a file or directory (on the same filesystem).
int renameat (int old_dirfd, const char *old_path, int new_dirfd, const char *new_path)
int remove (const char *path)
 remove a file or an empty directory.
void perror (const char *s)
 write "s: " (when s is not NULL or empty) and the text of errno to stderr (in errno.c; errno.h declares it too).
void flockfile (FILE *stream)
int ftrylockfile (FILE *stream)
void funlockfile (FILE *stream)
int getc_unlocked (FILE *stream)
int getchar_unlocked (void)
int putc_unlocked (int c, FILE *stream)
int putchar_unlocked (int c)
ssize_t getline (char **line, size_t *size, FILE *stream)
 read a line, with its newline, into *line (made larger with realloc as it needs; *line may be NULL and *size 0 at first).
ssize_t getdelim (char **line, size_t *size, int delimiter, FILE *stream)
 as getline, up to and with delimiter instead of a newline
FILE * fmemopen (void *memory, size_t size, const char *mode)
 a stream on size bytes of memory (or on new memory, freed by fclose, when memory is NULL).

Variables

FILE * stdin
FILE * stdout
FILE * stderr

Detailed Description

buffered streams and formatted input/output.

a FILE buffers the bytes of one file descriptor. a stream on a terminal is written out at the end of every stdio call (so printf and write calls stay in order); other streams are written out when the buffer is full, by fflush, by fclose, and by exit (not by _exit).

Macro Definition Documentation

◆ NULL

#define NULL   ((void *)0)

◆ EOF

#define EOF   (-1)

◆ BUFSIZ

#define BUFSIZ   1024

◆ FILENAME_MAX

#define FILENAME_MAX   256

◆ _IOFBF

#define _IOFBF   0

◆ _IOLBF

#define _IOLBF   1

◆ _IONBF

#define _IONBF   2

◆ SEEK_SET

#define SEEK_SET   0

◆ SEEK_CUR

#define SEEK_CUR   1

◆ SEEK_END

#define SEEK_END   2

Typedef Documentation

◆ FILE

typedef struct stdio_file FILE

◆ fpos_t

typedef off_t fpos_t

Function Documentation

◆ fopen()

FILE * fopen ( const char * path,
const char * mode )

◆ fdopen()

FILE * fdopen ( int fd,
const char * mode )

◆ fclose()

int fclose ( FILE * stream)

◆ fflush()

int fflush ( FILE * stream)

◆ freopen()

FILE * freopen ( const char * path,
const char * mode,
FILE * stream )

give a stream another file: the old file is closed, the stream keeps its fd number (so freopen on stdin or stdout changes fd 0 or 1).

Parameters
paththe new file; NULL keeps the file and changes only the mode.
Returns
stream, or NULL (errno set; the stream is closed).

◆ tmpfile()

FILE * tmpfile ( void )

a new file for reading and writing that goes when it is closed (it is made in /tmp and removed at once).

◆ popen()

FILE * popen ( const char * command,
const char * mode )

run "sh -c command" with a pipe to its standard output ("r") or from its standard input ("w").

Returns
the stream of the pipe, or NULL (errno set).

◆ pclose()

int pclose ( FILE * stream)

close a stream of popen and wait for the command.

Returns
its status as waitpid gives it, or -1.

◆ setvbuf()

int setvbuf ( FILE * stream,
char * buf,
int mode,
size_t size )

◆ setbuf()

void setbuf ( FILE * stream,
char * buf )

◆ fileno()

int fileno ( FILE * stream)

◆ fread()

size_t fread ( void * ptr,
size_t size,
size_t count,
FILE * stream )

◆ fwrite()

size_t fwrite ( const void * ptr,
size_t size,
size_t count,
FILE * stream )

◆ fgetc()

int fgetc ( FILE * stream)

◆ getc()

int getc ( FILE * stream)

◆ getchar()

int getchar ( void )

◆ ungetc()

int ungetc ( int c,
FILE * stream )

◆ fgets()

char * fgets ( char * buf,
int size,
FILE * stream )

◆ fputc()

int fputc ( int c,
FILE * stream )

◆ putc()

int putc ( int c,
FILE * stream )

◆ putchar()

int putchar ( int c)

◆ fputs()

int fputs ( const char * s,
FILE * stream )

◆ puts()

int puts ( const char * s)

◆ fseek()

int fseek ( FILE * stream,
long offset,
int whence )

◆ ftell()

long ftell ( FILE * stream)

◆ fseeko()

int fseeko ( FILE * stream,
off_t offset,
int whence )

◆ ftello()

off_t ftello ( FILE * stream)

◆ fgetpos()

int fgetpos ( FILE * stream,
fpos_t * pos )

◆ fsetpos()

int fsetpos ( FILE * stream,
const fpos_t * pos )

◆ rewind()

void rewind ( FILE * stream)

◆ feof()

int feof ( FILE * stream)

◆ ferror()

int ferror ( FILE * stream)

◆ clearerr()

void clearerr ( FILE * stream)

◆ printf()

int printf ( const char * fmt,
... )

formatted output.

conversions: d i u o x X c s p n f F e E g G %; flags - + space # 0; a width and a precision (also as *); lengths hh h l ll z j t L.

◆ fprintf()

int int fprintf ( FILE * stream,
const char * fmt,
... )

◆ dprintf()

int int int dprintf ( int fd,
const char * fmt,
... )

◆ sprintf()

int int int int sprintf ( char * buf,
const char * fmt,
... )

◆ snprintf()

int int int int int snprintf ( char * buf,
size_t size,
const char * fmt,
... )

◆ vprintf()

int int int int int int vprintf ( const char * fmt,
va_list ap )

◆ vfprintf()

int vfprintf ( FILE * stream,
const char * fmt,
va_list ap )

◆ vdprintf()

int vdprintf ( int fd,
const char * fmt,
va_list ap )

◆ vsprintf()

int vsprintf ( char * buf,
const char * fmt,
va_list ap )

◆ vsnprintf()

int vsnprintf ( char * buf,
size_t size,
const char * fmt,
va_list ap )

◆ sscanf()

int sscanf ( const char * str,
const char * fmt,
... )

formatted input from a string: d i u x o c s %[...] n and %%, with widths and the lengths hh h l ll z.

Returns
the number of fields stored, or EOF at the end of the input.

◆ rename()

int rename ( const char * old_path,
const char * new_path )

rename a file or directory (on the same filesystem).

Returns
0, or -1 (errno set; EXDEV across filesystems).

◆ renameat()

int renameat ( int old_dirfd,
const char * old_path,
int new_dirfd,
const char * new_path )

◆ remove()

int remove ( const char * path)

remove a file or an empty directory.

◆ perror()

void perror ( const char * s)

write "s: " (when s is not NULL or empty) and the text of errno to stderr (in errno.c; errno.h declares it too).

◆ flockfile()

void flockfile ( FILE * stream)

◆ ftrylockfile()

int ftrylockfile ( FILE * stream)

◆ funlockfile()

void funlockfile ( FILE * stream)

◆ getc_unlocked()

int getc_unlocked ( FILE * stream)

◆ getchar_unlocked()

int getchar_unlocked ( void )

◆ putc_unlocked()

int putc_unlocked ( int c,
FILE * stream )

◆ putchar_unlocked()

int putchar_unlocked ( int c)

◆ getline()

ssize_t getline ( char ** line,
size_t * size,
FILE * stream )

read a line, with its newline, into *line (made larger with realloc as it needs; *line may be NULL and *size 0 at first).

Returns
the bytes read, or -1 at the end of the file or for an error.

◆ getdelim()

ssize_t getdelim ( char ** line,
size_t * size,
int delimiter,
FILE * stream )

as getline, up to and with delimiter instead of a newline

◆ fmemopen()

FILE * fmemopen ( void * memory,
size_t size,
const char * mode )

a stream on size bytes of memory (or on new memory, freed by fclose, when memory is NULL).

reads stop at the content's end; writes stop at size and keep a null byte after the content while there is room.

Variable Documentation

◆ stdin

FILE* stdin
extern

◆ stdout

FILE* stdout
extern

◆ stderr

FILE* stderr
extern