MyOS Libc
stdio.c File Reference
#include <stdio.h>
#include <serdes.h>
#include <rpc.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include <dbg.h>

Functions

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

Variables

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

Function Documentation

◆ __stdio_init()

void __stdio_init ( )

Initialize stdio. Must not be called by user code.

◆ 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

◆ 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

◆ 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