Removed a malloc and struct from file dir operations.
This commit is contained in:
parent
e02b83d827
commit
4e79b9567d
2 changed files with 16 additions and 22 deletions
|
@ -63,20 +63,19 @@ void fileClose(uint8_t *fd) {
|
||||||
|
|
||||||
#pragma push_macro("close")
|
#pragma push_macro("close")
|
||||||
#undef close
|
#undef close
|
||||||
int16_t fileCloseDir(fileDirT *dir) {
|
int16_t fileCloseDir(char *dir) {
|
||||||
if (!dir) return -1;
|
if (!dir) return -1;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (*dir->stream) {
|
if (*dir) {
|
||||||
kernelArgs->directory.close.stream = *dir->stream;
|
kernelArgs->directory.close.stream = *dir;
|
||||||
kernelCall(Directory.Close);
|
kernelCall(Directory.Close);
|
||||||
if (!kernelError) {
|
if (!kernelError) {
|
||||||
*dir->stream = 0;
|
*dir = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
kernelNextEvent();
|
kernelNextEvent();
|
||||||
if (kernelEventData.type == kernelEvent(directory.CLOSED)) {
|
if (kernelEventData.type == kernelEvent(directory.CLOSED)) {
|
||||||
free(dir);
|
|
||||||
dir = NULL;
|
dir = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -125,10 +124,10 @@ int16_t *fileOpen(char *fname, char *mode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fileDirT *fileOpenDir(char *name) {
|
char *fileOpenDir(char *name) {
|
||||||
char drive;
|
char drive;
|
||||||
char stream;
|
char stream;
|
||||||
fileDirT *dir;
|
char *dir;
|
||||||
|
|
||||||
name = pathWithoutDrive(name, &drive);
|
name = pathWithoutDrive(name, &drive);
|
||||||
|
|
||||||
|
@ -148,8 +147,7 @@ fileDirT *fileOpenDir(char *name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
_dirStream[drive] = stream;
|
_dirStream[drive] = stream;
|
||||||
dir = (fileDirT *)malloc(sizeof(fileDirT));
|
dir = &_dirStream[drive];
|
||||||
dir->stream = &_dirStream[drive];
|
|
||||||
|
|
||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
@ -175,13 +173,13 @@ int16_t fileRead(void *buf, uint16_t nbytes, uint16_t nmemb, uint8_t *fd) {
|
||||||
#pragma push_macro("FILE")
|
#pragma push_macro("FILE")
|
||||||
#undef EOF
|
#undef EOF
|
||||||
#undef FILE
|
#undef FILE
|
||||||
fileDirEntT *fileReadDir(fileDirT *dir) {
|
fileDirEntT *fileReadDir(char *dir) {
|
||||||
static fileDirEntT dirent;
|
static fileDirEntT dirent;
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
|
|
||||||
if (!dir) return NULL;
|
if (!dir) return NULL;
|
||||||
|
|
||||||
kernelArgs->directory.read.stream = *dir->stream;
|
kernelArgs->directory.read.stream = *dir;
|
||||||
kernelCall(Directory.Read);
|
kernelCall(Directory.Read);
|
||||||
if (kernelError) return NULL;
|
if (kernelError) return NULL;
|
||||||
|
|
||||||
|
@ -203,7 +201,7 @@ fileDirEntT *fileReadDir(fileDirT *dir) {
|
||||||
|
|
||||||
case kernelEvent(directory.FREE):
|
case kernelEvent(directory.FREE):
|
||||||
// dirent doesn't care about these types of records.
|
// dirent doesn't care about these types of records.
|
||||||
kernelArgs->directory.read.stream = *dir->stream;
|
kernelArgs->directory.read.stream = *dir;
|
||||||
kernelCall(Directory.Read);
|
kernelCall(Directory.Read);
|
||||||
if (!kernelError) continue;
|
if (!kernelError) continue;
|
||||||
// Fall through.
|
// Fall through.
|
||||||
|
|
|
@ -34,10 +34,6 @@ extern "C"
|
||||||
#include "f256.h"
|
#include "f256.h"
|
||||||
|
|
||||||
|
|
||||||
typedef struct fileDirS {
|
|
||||||
char *stream;
|
|
||||||
} fileDirT;
|
|
||||||
|
|
||||||
typedef struct fileDirEntS {
|
typedef struct fileDirEntS {
|
||||||
unsigned char d_blocks;
|
unsigned char d_blocks;
|
||||||
unsigned char d_type;
|
unsigned char d_type;
|
||||||
|
@ -46,11 +42,11 @@ typedef struct fileDirEntS {
|
||||||
|
|
||||||
|
|
||||||
void fileClose(uint8_t *fd);
|
void fileClose(uint8_t *fd);
|
||||||
int16_t fileCloseDir(fileDirT *dir);
|
int16_t fileCloseDir(char *dir);
|
||||||
int16_t *fileOpen(char *fname, char *mode);
|
int16_t *fileOpen(char *fname, char *mode);
|
||||||
fileDirT *fileOpenDir(char *name);
|
char *fileOpenDir(char *name);
|
||||||
int16_t fileRead(void *buf, uint16_t nbytes, uint16_t nmemb, uint8_t *fd);
|
int16_t fileRead(void *buf, uint16_t nbytes, uint16_t nmemb, uint8_t *fd);
|
||||||
fileDirEntT *fileReadDir(fileDirT *dir);
|
fileDirEntT *fileReadDir(char *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 *fd, uint32_t offset, uint8_t whence);
|
int16_t fileSeek(uint8_t *fd, uint32_t offset, uint8_t whence);
|
||||||
|
@ -68,7 +64,7 @@ int16_t fileWrite(void *buf, uint16_t nbytes, uint16_t nmemb, uint8_t *fd);
|
||||||
#ifndef DIR
|
#ifndef DIR
|
||||||
#define close fileClose
|
#define close fileClose
|
||||||
#define closedir fileCloseDir
|
#define closedir fileCloseDir
|
||||||
#define DIR fileDirT
|
#define DIR char
|
||||||
#define dirent fileDirEntS
|
#define dirent fileDirEntS
|
||||||
#define FILE uint8_t
|
#define FILE uint8_t
|
||||||
#define fopen fileOpen
|
#define fopen fileOpen
|
||||||
|
|
Loading…
Add table
Reference in a new issue