fseek and rewind added. No support for ftell in the microkernel.

This commit is contained in:
Scott Duensing 2024-01-23 19:31:03 -06:00
parent ea985a42fd
commit 6f51733e92
3 changed files with 30 additions and 14 deletions

View file

@ -183,9 +183,9 @@ struct fs_delete_t {
}; };
struct fs_seek_t { struct fs_seek_t {
uint8_t streak; uint8_t stream;
uint8_t cookie; uint8_t cookie;
uint32_t position; uint32_t offset;
}; };
struct file_t { struct file_t {

View file

@ -279,6 +279,18 @@ void fileReset(void) {
} }
int16_t fileSeek(uint8_t id, uint32_t offset, uint8_t whence) {
if (whence != SEEK_SET) return -1;
kernelArgs->file.seek.stream = id;
kernelArgs->file.seek.offset = offset;
kernelCall(File.Seek);
if (kernelError) return -1;
return 0;
}
int16_t fileUnlink(char *name) { int16_t fileUnlink(char *name) {
char drive; char drive;
char stream; char stream;

View file

@ -53,6 +53,7 @@ int16_t fileRead(void *buf, uint16_t nbytes, uint16_t nmemb, uint8_t fd);
fileDirEntT *fileReadDir(fileDirT *dir); fileDirEntT *fileReadDir(fileDirT *dir);
int16_t fileRename(char *name, char *to); int16_t fileRename(char *name, char *to);
void fileReset(void); void fileReset(void);
int16_t fileSeek(uint8_t id, uint32_t offset, uint8_t whence);
int16_t fileUnlink(char *name); int16_t fileUnlink(char *name);
int16_t fileWrite(void *buf, uint16_t nbytes, uint16_t nmemb, uint8_t fd); int16_t fileWrite(void *buf, uint16_t nbytes, uint16_t nmemb, uint8_t fd);
@ -65,18 +66,21 @@ int16_t fileWrite(void *buf, uint16_t nbytes, uint16_t nmemb, uint8_t fd);
// Aliases to the standard names if they don't exist. // Aliases to the standard names if they don't exist.
#ifndef DIR #ifndef DIR
#define close fileClose #define close fileClose
#define closedir fileCloseDir #define closedir fileCloseDir
#define DIR fileDirT #define DIR fileDirT
#define dirent fileDirEntS #define dirent fileDirEntS
#define FILE uint8_t #define FILE uint8_t
#define fopen fileOpen #define fopen fileOpen
#define fread fileRead #define fread fileRead
#define fwrite fileWrite #define fseek fileSeek
#define opendir fileOpenDir #define fwrite fileWrite
#define readdir fileReadDir #define opendir fileOpenDir
#define rename fileRename #define readdir fileReadDir
#define unlink fileUnlink #define rename fileRename
#define rewind(s) (void)fileSeek(s, 0, SEEK_SET)
#define SEEK_SET 0
#define unlink fileUnlink
#endif #endif