This commit is contained in:
Lyon 2023-10-26 20:15:33 +08:00
commit 3e77f423db

View File

@ -11,8 +11,8 @@ int __fmodeflags(const char* mode);
#define PIKA_FATFS_ENABLE 1 #define PIKA_FATFS_ENABLE 1
#endif #endif
#if PIKA_FATFS_ENABLE
FILE* fatfs_fopen(const char* filename, const char* modes) { FILE* pika_platform_fopen(const char* filename, const char* modes) {
FRESULT res; FRESULT res;
int flags; int flags;
@ -37,28 +37,28 @@ FILE* fatfs_fopen(const char* filename, const char* modes) {
return (FILE *)_f; return (FILE *)_f;
} }
size_t fatfs_fwrite(const void* ptr, size_t size, size_t n, FILE* stream) { size_t pika_platform_fwrite(const void* ptr, size_t size, size_t n, FILE* stream) {
_INNER_FILE* _f = (_INNER_FILE*)stream; _INNER_FILE* _f = (_INNER_FILE*)stream;
size_t len = 0; size_t len = 0;
f_write(_f, ptr, n * size, &len); f_write(_f, ptr, n * size, &len);
return len; return len;
} }
size_t fatfs_fread(void* ptr, size_t size, size_t n, FILE* stream) { size_t pika_platform_fread(void* ptr, size_t size, size_t n, FILE* stream) {
_INNER_FILE* _f = (_INNER_FILE*)stream; _INNER_FILE* _f = (_INNER_FILE*)stream;
size_t len = 0; size_t len = 0;
f_read(_f, ptr, n * size, &len); f_read(_f, ptr, n * size, &len);
return len; return len;
} }
int fatfs_fclose(FILE* stream) { int pika_platform_fclose(FILE* stream) {
_INNER_FILE* _f = (_INNER_FILE*)stream; _INNER_FILE* _f = (_INNER_FILE*)stream;
f_close(_f); f_close(_f);
free(_f); free(_f);
return 0; return 0;
} }
int fatfs_fseek(FILE* stream, long offset, int whence) { int pika_platform_fseek(FILE* stream, long offset, int whence) {
_INNER_FILE* _f = (_INNER_FILE*)stream; _INNER_FILE* _f = (_INNER_FILE*)stream;
DWORD fatfs_offset; DWORD fatfs_offset;
switch (whence) { switch (whence) {
@ -81,7 +81,7 @@ int fatfs_fseek(FILE* stream, long offset, int whence) {
} }
} }
long fatfs_ftell(FILE* stream) { long pika_platform_ftell(FILE* stream) {
_INNER_FILE* _f = (_INNER_FILE*)stream; _INNER_FILE* _f = (_INNER_FILE*)stream;
return f_tell(_f); return f_tell(_f);
} }
@ -106,7 +106,7 @@ int __fmodeflags(const char* mode) {
return flags; return flags;
} }
char* fatfs_getcwd(char* buf, size_t size) { char* pika_platform_getcwd(char* buf, size_t size) {
// FatFS doesn't directly provide a getcwd function. You might need // FatFS doesn't directly provide a getcwd function. You might need
// to manage the current directory yourself or return a default if it's // to manage the current directory yourself or return a default if it's
// not crucial for your application. // not crucial for your application.
@ -114,29 +114,29 @@ char* fatfs_getcwd(char* buf, size_t size) {
return buf; return buf;
} }
int fatfs_chdir(const char* path) { int pika_platform_chdir(const char* path) {
// FatFS doesn't directly provide a chdir function. You might need // FatFS doesn't directly provide a chdir function. You might need
// to manage the current directory yourself. // to manage the current directory yourself.
return -1; // Not implemented return -1; // Not implemented
} }
int fatfs_rmdir(const char* pathname) { int pika_platform_rmdir(const char* pathname) {
return f_unlink(pathname); return f_unlink(pathname);
} }
int fatfs_mkdir(const char* pathname, int mode) { int pika_platform_mkdir(const char* pathname, int mode) {
return f_mkdir(pathname); return f_mkdir(pathname);
} }
int fatfs_remove(const char* pathname) { int pika_platform_remove(const char* pathname) {
return f_unlink(pathname); return f_unlink(pathname);
} }
int fatfs_rename(const char* oldpath, const char* newpath) { int pika_platform_rename(const char* oldpath, const char* newpath) {
return f_rename(oldpath, newpath); return f_rename(oldpath, newpath);
} }
char** fatfs_listdir(const char* path, int* count) { char** pika_platform_listdir(const char* path, int* count) {
DIR dir; DIR dir;
static FILINFO fno; static FILINFO fno;
FRESULT res; FRESULT res;
@ -184,26 +184,4 @@ char** fatfs_listdir(const char* path, int* count) {
return filelist; return filelist;
} }
#if PIKA_FATFS_ENABLE
char* pika_platform_getcwd(char* buf, size_t size) {
return fatfs_getcwd(buf, size);
}
int pika_platform_chdir(const char* path) {
return fatfs_chdir(path);
}
int pika_platform_rmdir(const char* pathname) {
return fatfs_rmdir(pathname);
}
int pika_platform_mkdir(const char* pathname, int mode) {
return fatfs_mkdir(pathname, mode);
}
int pika_platform_remove(const char* pathname) {
return fatfs_remove(pathname);
}
int pika_platform_rename(const char* oldpath, const char* newpath) {
return fatfs_rename(oldpath, newpath);
}
char** pika_platform_listdir(const char* path, int* count) {
return fatfs_listdir(path, count);
}
#endif #endif