Standard Libraries
Posted: Sun Nov 25, 2012 11:37 pm
In one of my other topics, I complained about the messiness and complexity of all the libraries we use today, so I've decided that for my operating system I'm going to create all libraries entirely from scratch. I'll be posting my concepts here and would like your opinions and constructive criticism.
Keep in mind that it's incomplete.
Memory Management Functions
Filesystem IO Functions
Keep in mind that it's incomplete.
Memory Management Functions
Code: Select all
void *alloc(u64 size)
Allocates memory, returns pointer to data.
void *realloc(void *data, u64 size);
Allocates or reallocates memory, returns pointer to data.
void free(void *data)
Frees memory.
Code: Select all
u32 mount(Device *device, char *mntpoint, char *path)
Mounts a device, at mntpoint, returns a value stating if it's
successful or an error code.
void unmount(Device *device)
Unmounts a device
u32 openDirectory(Directory *dir, char *path)
Opens a directory, returns a value stating if it's
successful or not.
void closeDirectory(Directory *dir)
Closes a directory.
u32 endOfDirectory(Directory *dir)
Returns whether or not the end of the directory has been
reached.
u32 firstFile(Directory *dir, DirectoryEntry *entry)
Returns the information for the first entry in a directory.
u32 nextFile(Directory *dir, DirectoryEntry *entry)
Returns the information for the next entry in a directory.
u32 fileExists(char *path)
Returns whether or not a file or directory exists.
u32 copyFile(char *srcpath, char *dstpath)
Copies a file or directory, returning if it's successful.
u32 moveFile(char *srcpath, char *dstpath)
Moves a file or directory, returning if it's successful.
u32 renameFile(char *path, char *newName)
Renames a file or directory, returning if it's successful.
void deleteFile(char *path)
Deletes a file or directory.
u32 openFile(File *file, char *path, u32 flags)
Opens a file, returns a value stating if it's successful or
an error code.
void closeFile(File *file)
Closes a file.
u32 endOfFile(File *file)
Returns whether or not the end of the file has been reached.
u64 filePosition(File *file)
Returns the position of the file.
u64 fileSeek(File *file, u64 pos, u32 seekStart)
Seeks to a position in a file.
u64 fileRead(File *file, void *buffer, u64 size)
Reads bytes from a file into a buffer, returning the number
of bytes actually read.
u64 fileWrite(File *file, void *buffer, u64 size)
Writes bytes to a file from a buffer, returning the number
of bytes actually written.
char *fileReadLine(File *file, void *buffer, u32 length)
Reads a line from a file, returns a pointer to the string.
u8 fileReadByte(File *file)
Reads a byte from a file, returning the value.
void fileReadHWBE(File *file, void *buffer)
Reads a halfword (16-bits) from a file in big endian.
void fileReadHWLE(File *file, void *buffer)
Reads a halfword (16-bits) from a file in little endian.
void fileReadWBE(File *file, void *buffer)
Reads a word (32-bits) from a file in big endian.
void fileReadWLE(File *file, void *buffer)
Reads a word (32-bits) from a file in little endian.
void fileReadDWBE(File *file, void *buffer)
Reads a doubleword (64-bits) from a file in big endian.
void fileReadDWLE(File *file, void *buffer)
Reads a doubleword (64-bits) from a file in little endian.
void filePrintf(File *file, char *format, ...)
Prints formatted text to a file.
void fileWriteLine(File *file, void *buffer, u32 length)
Writes a line from a file.
void fileWriteByte(File *file, u8 byte)
Writes a byte to a file.
void fileWriteHWBE(File *file, void *buffer)
Writes a halfword (16-bits) to a file in big endian.
void fileWriteHWLE(File *file, void *buffer)
Writes a halfword (16-bits) to a file in little endian.
void fileWriteWBE(File *file, void *buffer)
Writes a word (32-bits) to a file in big endian.
void fileWriteWLE(File *file, void *buffer)
Writes a word (32-bits) to a file in little endian.
void fileWriteDWBE(File *file, void *buffer)
Writes a doubleword (64-bits) to a file in big endian.
void fileWriteDWLE(File *file, void *buffer)
Writes a doubleword (64-bits) to a file in little endian.