MyOS Libc
stdio.h File Reference
#include <stdarg.h>
#include <stddef.h>
#include <sys/types.h>

Go to the source code of this file.

Data Structures

struct  FILE
 

Macros

#define SEEK_CUR   1
 Seek postition is relative to current position im file.
 
#define SEEK_END   2
 Seek position is relative to end of file.
 
#define SEEK_SET   3
 Seek position is relative to beginning of file.
 
#define EOF   -1
 Represents EOF.
 

Functions

FILEfopen (char *filename, char *mode)
 
int fgetc (FILE *stream)
 
int getc (FILE *stream)
 
char * fgets (char *str, int count, FILE *stream)
 
char * gets (char *str)
 
size_t fread (void *buffer, size_t size, size_t count, FILE *stream)
 
int fputc (int c, FILE *stream)
 
int putc (int c, FILE *stream)
 
int fputs (const char *s, FILE *stream)
 
size_t fwrite (void *buffer_ptr, size_t size, size_t count, FILE *stream)
 
int puts (const char *s)
 
int fprintf (FILE *stream, const char *format,...)
 
int vfprintf (FILE *stream, const char *format, va_list arg)
 
int printf (const char *format,...)
 
int fseek (FILE *stream, long offset, int origin)
 
long ftell (FILE *stream)
 
int fclose (FILE *file)
 
int feof (FILE *stream)
 
int ferror (FILE *stream)
 
int fflush (FILE *stream)
 
void setbuf (FILE *restrict stream, char *restrict buf)
 
void register_fs (const char *name, pid_t pid)
 
int mount (char *file, char *type, char *path)
 

Variables

FILEstdin
 Standard input.
 
FILEstdout
 Standard output.
 
FILEstderr
 Standard error.
 

Function Documentation

◆ fclose()

int fclose ( FILE file)

Closes a file

Parameters
fileThe file to close
Returns
0 on success, EOF on failure

◆ feof()

int feof ( FILE stream)

Returns the EOF indicator for a file

Parameters
streamthe file to check
Returns
the EOF indicator

◆ ferror()

int ferror ( FILE stream)

Returns the error indicator for a file

Parameters
streamthe file to check
Returns
the error indicator

◆ fflush()

int fflush ( FILE stream)

Flushes the buffer on a file

Parameters
streamThe file to flush the buffer of
Returns
0 on success, EOF on failure

◆ fgetc()

int fgetc ( FILE stream)

Gets a character from a file

Parameters
streamThe file to read from
Returns
the read character, or EOF if the read fails

◆ fgets()

char* fgets ( char *  str,
int  count,
FILE stream 
)

Gets a newline delimeted string from a file

Parameters
strThe buffer to read into
countThe maximum size of the string to read
streamThe file to read from
Returns
the buffer

◆ fopen()

FILE* fopen ( char *  filename,
char *  mode 
)

Opens a file with the specified mode

Parameters
filenameThe path to the file to open
modeThe mode to open the file with (r,w,a,r+,w+,a+)
Returns
NULL if the file could not be opened, or a pointer to a FILE struct if the opening was sucessful.

◆ fprintf()

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

Format a string and writte it to a file

Parameters
streamThe fike to write to
formatThe format string
...The arguments for the format string
Returns
The number of bytes written

◆ fputc()

int fputc ( int  c,
FILE stream 
)

Writes a character to a file

Parameters
cThe character to write
streamThe stream to write to
Returns
the written character, or EOF on failure

◆ fputs()

int fputs ( const char *  s,
FILE stream 
)

Writes a string to a file

Parameters
sThe string to write
streamThe file to write to
Returns
0 on success, EOF on failure

◆ fread()

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

Reads from a file

Parameters
bufferThe buffer to read into
sizeThe size of each elemnt to read
countThe number of elements to read
streamThe file to read from
Returns
the number of bytes read, or 0 on failure

◆ fseek()

int fseek ( FILE stream,
long  offset,
int  origin 
)

Seeks to a position in a file

Parameters
streamThe file to seek in
offsetThe offset to seek to
originThe origin of seeking (SEEK_CUR,SEEK_END,SEEK_SET)
Returns
0 on success, -1 on failure

◆ ftell()

long ftell ( FILE stream)

Returns the postion in a file

Parameters
streamThe file to get the position in
Returns
the position on success, -1 on failure

◆ fwrite()

size_t fwrite ( void *  buffer_ptr,
size_t  size,
size_t  count,
FILE stream 
)

Writes to a file

Parameters
buffer_ptrThe buffer to write
sizeThe size of each elemnt to write
countThe number of elements to write
streamThe file to write to
Returns
the number of bytes written, or 0 on failure

◆ getc()

int getc ( FILE stream)

Gets a character from a file

Parameters
streamThe file to read from
Returns
the read character, or EOF if the read fails

◆ gets()

char* gets ( char *  str)

Gets a newline delimeted string from stdin

Parameters
strThe buffer to read into
Returns
the buffer
Deprecated:
Gets is unsafe and vulnerable to a buffer overflow, as there is no bounds checking on the buffer.

◆ mount()

int mount ( char *  file,
char *  type,
char *  path 
)

Mounts a filesystem

Parameters
fileThe file to mount
typeThe type of the filesystem to mount
pathThe path to mount the filesytem at
Returns
0 on success, 1 on failure

◆ printf()

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

Format a string and write it to stdout

Parameters
formatThe format string
...The arguments for the format string
Returns
The number of bytes written

◆ putc()

int putc ( int  c,
FILE stream 
)

Writes a character to a file

Parameters
cThe character to write
streamThe stream to write to
Returns
the written character, or EOF on failure

◆ puts()

int puts ( const char *  s)

Writes a string followed by a newline to stdin

Parameters
sThe string to write
Returns
0 on success, EOF on failure

◆ register_fs()

void register_fs ( const char *  name,
pid_t  pid 
)

Registers a file system type with the VFS

Parameters
nameThe name of the type to register
pidThe PID of the filesytem driver

◆ setbuf()

void setbuf ( FILE *restrict  stream,
char *restrict  buf 
)

Assigns buffering to a file

When the buffer is not a null pointer, the buffer type is set to fully bufferd, and the buffer size is assumed to be at least BUFSIZ.

When the buffer is a null pointer, buffering is removed.

Parameters
streamThe file to assign buffering to
bufThe buffer to use

◆ vfprintf()

int vfprintf ( FILE stream,
const char *  format,
va_list  arg 
)

Format a string and writte it to a file

Parameters
streamThe fike to write to
formatThe format string
argThe arguments for the format string
Returns
The number of bytes written