2020-08-23 08:22:14 -05:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
*/
|
2020-07-26 14:39:08 -05:00
|
|
|
#ifndef STDIO_H
|
|
|
|
#define STDIO_H
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
2020-08-23 08:22:14 -05:00
|
|
|
#include <sys/types.h>
|
2020-07-26 14:39:08 -05:00
|
|
|
|
2020-08-23 08:22:14 -05:00
|
|
|
#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
|
2020-07-26 14:39:08 -05:00
|
|
|
|
2020-08-23 08:22:14 -05:00
|
|
|
/**
|
|
|
|
* Represents an open file
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
pid_t fs_pid; //!< PID of the filesytem drive for this file
|
|
|
|
void* fs_data; //!< Pointer given by the filesytem driver to its info about the file.
|
|
|
|
int pos; //!< Positiom in the file
|
|
|
|
} FILE;
|
2020-07-26 14:39:08 -05:00
|
|
|
|
2020-08-23 08:22:14 -05:00
|
|
|
extern FILE* stdin; //!< Standard input
|
|
|
|
extern FILE* stdout; //!< Standard output
|
|
|
|
extern FILE* stderr; //!< Standard error
|
2020-07-26 14:39:08 -05:00
|
|
|
|
2020-08-23 08:22:14 -05:00
|
|
|
/**
|
|
|
|
* Opens a file with the specified mode
|
|
|
|
* \param filename The path to the file to open
|
|
|
|
* \param mode The 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.
|
|
|
|
*/
|
2020-07-26 14:39:08 -05:00
|
|
|
FILE* fopen(char* filename,char* mode);
|
2020-08-23 08:22:14 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a character from a file
|
|
|
|
* \param stream The file to read from
|
|
|
|
* \returns the read character, or EOF if the read fails
|
|
|
|
*/
|
2020-07-26 14:39:08 -05:00
|
|
|
int fgetc(FILE* stream);
|
2020-08-23 08:22:14 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a character from a file
|
|
|
|
* \param stream The file to read from
|
|
|
|
* \returns the read character, or EOF if the read fails
|
|
|
|
*/
|
2020-07-26 14:39:08 -05:00
|
|
|
int getc(FILE* stream);
|
2020-08-23 08:22:14 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a newline delimeted string from a file
|
|
|
|
* \param str The buffer to read into
|
|
|
|
* \param count The maximum size of the string to read
|
|
|
|
* \param stream The file to read from
|
|
|
|
* \returns the buffer
|
|
|
|
*/
|
2020-07-26 14:39:08 -05:00
|
|
|
char* fgets(char* str,int count,FILE* stream);
|
2020-08-23 08:22:14 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a newline delimeted string from stdin
|
|
|
|
* \param str The 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.
|
|
|
|
*/
|
2020-07-26 14:39:08 -05:00
|
|
|
char* gets(char* str);
|
2020-08-23 08:22:14 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads from a file
|
|
|
|
* \param buffer The buffer to read into
|
|
|
|
* \param size The size of each elemnt to read
|
|
|
|
* \param count The number of elements to read
|
|
|
|
* \param stream The file to read from
|
|
|
|
* \returns the number of bytes read, or 0 on failure
|
|
|
|
*/
|
2020-07-26 14:39:08 -05:00
|
|
|
size_t fread(void* buffer,size_t size,size_t count,FILE* stream);
|
2020-08-23 08:22:14 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes a character to a file
|
|
|
|
* \param c The character to write
|
|
|
|
* \param stream The stream to write to
|
|
|
|
* \returns the written character, or EOF on failure
|
|
|
|
*/
|
2020-07-26 14:39:08 -05:00
|
|
|
int fputc(int c,FILE* stream);
|
2020-08-23 08:22:14 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes a character to a file
|
|
|
|
* \param c The character to write
|
|
|
|
* \param stream The stream to write to
|
|
|
|
* \returns the written character, or EOF on failure
|
|
|
|
*/
|
|
|
|
int putc(int c,FILE* stream);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes a string to a file
|
|
|
|
* \param s The string to write
|
|
|
|
* \param stream The file to write to
|
|
|
|
* \returns 0 on success, EOF on failure
|
|
|
|
*/
|
2020-07-26 14:39:08 -05:00
|
|
|
int fputs(const char* s,FILE* stream);
|
2020-08-23 08:22:14 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes to a file
|
|
|
|
* \param buffer_ptr The buffer to write
|
|
|
|
* \param size The size of each elemnt to write
|
|
|
|
* \param count The number of elements to write
|
|
|
|
* \param stream The file to write to
|
|
|
|
* \returns the number of bytes written, or 0 on failure
|
|
|
|
*/
|
2020-07-26 14:39:08 -05:00
|
|
|
size_t fwrite(void* buffer_ptr,size_t size,size_t count,FILE* stream);
|
2020-08-23 08:22:14 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes a string followed by a newline to stdin
|
|
|
|
* \param s The string to write
|
|
|
|
* \returns 0 on success, EOF on failure
|
|
|
|
*/
|
2020-07-26 14:39:08 -05:00
|
|
|
int puts(const char* s);
|
2020-08-23 08:22:14 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Format a string and writte it to a file
|
|
|
|
* \param stream The fike to write to
|
|
|
|
* \param format The format string
|
|
|
|
* \param ... The arguments for the format string
|
|
|
|
* \returns The number of bytes written
|
|
|
|
*/
|
2020-07-26 14:39:08 -05:00
|
|
|
int fprintf(FILE* stream,const char* format,...);
|
2020-08-23 08:22:14 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Format a string and writte it to a file
|
|
|
|
* \param stream The fike to write to
|
|
|
|
* \param format The format string
|
|
|
|
* \param arg The arguments for the format string
|
|
|
|
* \returns The number of bytes written
|
|
|
|
*/
|
2020-07-26 14:39:08 -05:00
|
|
|
int vfprintf(FILE* stream,const char* format,va_list arg);
|
2020-08-23 08:22:14 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Format a string and write it to stdout
|
|
|
|
* \param format The format string
|
|
|
|
* \param ... The arguments for the format string
|
|
|
|
* \returns The number of bytes written
|
|
|
|
*/
|
2020-07-26 14:39:08 -05:00
|
|
|
int printf(const char* format,...);
|
2020-08-23 08:22:14 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Seeks to a position in a file
|
|
|
|
* \param stream The file to seek in
|
|
|
|
* \param offset The offset to seek to
|
|
|
|
* \param origin The origin of seeking (SEEK_CUR,SEEK_END,SEEK_SET)
|
|
|
|
* \returns 0 on success, -1 on failure
|
|
|
|
*/
|
2020-07-26 14:39:08 -05:00
|
|
|
int fseek(FILE* stream,long offset,int origin);
|
2020-08-23 08:22:14 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the postion in a file
|
|
|
|
* \param stream The file to get the position in
|
|
|
|
* \returns the position on success, -1 on failure
|
|
|
|
*/
|
2020-07-26 14:39:08 -05:00
|
|
|
long ftell(FILE* stream);
|
2020-08-23 08:22:14 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes a file
|
|
|
|
* \param file The file to close
|
|
|
|
* \returns 0 on success, EOF on failure
|
|
|
|
*/
|
2020-07-26 14:39:08 -05:00
|
|
|
int fclose(FILE* file);
|
2020-08-23 08:22:14 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the EOF indicator for a file
|
|
|
|
* \param stream the file to check
|
|
|
|
* \returns the EOF indicator
|
|
|
|
*/
|
2020-07-26 14:39:08 -05:00
|
|
|
int feof(FILE* stream);
|
2020-08-23 08:22:14 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the error indicator for a file
|
|
|
|
* \param stream the file to check
|
|
|
|
* \returns the error indicator
|
|
|
|
*/
|
2020-07-26 14:39:08 -05:00
|
|
|
int ferror(FILE* stream);
|
2020-08-23 08:22:14 -05:00
|
|
|
|
|
|
|
/** Flushes the buffer on a file
|
|
|
|
* \param stream The file to flush the buffer of
|
|
|
|
* \returns 0 on success, EOF on failure
|
|
|
|
*/
|
|
|
|
int fflush(FILE *stream);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
* \param stream The file to assign buffering to
|
|
|
|
* \param buf The buffer to use
|
|
|
|
*/
|
|
|
|
void setbuf(FILE *restrict stream, char *restrict buf);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers a file system type with the VFS
|
|
|
|
* \param name The name of the type to register
|
|
|
|
* \param pid The PID of the filesytem driver
|
|
|
|
*/
|
|
|
|
void register_fs(const char* name,pid_t pid);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mounts a filesystem
|
|
|
|
* \param file The file to mount
|
|
|
|
* \param type The type of the filesystem to mount
|
|
|
|
* \param path The path to mount the filesytem at
|
|
|
|
* \returns 0 on success, 1 on failure
|
|
|
|
*/
|
|
|
|
int mount(char* file,char* type,char* path);
|
2020-07-26 14:39:08 -05:00
|
|
|
|
|
|
|
#endif
|