forked from Aeplexi/hbc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Aeplexi#13 from Aeplexi/main
bump
- Loading branch information
Showing
11 changed files
with
470 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <malloc.h> | ||
|
||
#include "fileops.h" | ||
|
||
static struct stat st; | ||
|
||
bool FSOPFileExists(const char* file) | ||
{ | ||
return !stat(file, &st) && !S_ISDIR(st.st_mode); | ||
} | ||
|
||
bool FSOPFolderExists(const char* path) | ||
{ | ||
return !stat(path, &st) && S_ISDIR(st.st_mode); | ||
} | ||
|
||
size_t FSOPGetFileSizeBytes(const char* path) | ||
{ | ||
if (stat(path, &st) < 0) return 0; | ||
|
||
return st.st_size; | ||
} | ||
|
||
void FSOPDeleteFile(const char* file) | ||
{ | ||
if (FSOPFileExists(file)) | ||
remove(file); | ||
} | ||
|
||
void FSOPMakeFolder(const char* path) | ||
{ | ||
if (FSOPFolderExists(path)) | ||
return; | ||
|
||
char* pos = strchr(path, '/'); | ||
s32 current = pos - path; | ||
current++; | ||
pos = strchr(path + current, '/'); | ||
|
||
while (pos) | ||
{ | ||
*pos = 0; | ||
mkdir(path, S_IREAD | S_IWRITE); | ||
*pos = '/'; | ||
|
||
current = pos - path; | ||
current++; | ||
pos = strchr(path + current, '/'); | ||
} | ||
|
||
mkdir(path, S_IREAD | S_IWRITE); | ||
} | ||
|
||
s32 FSOPReadOpenFile(FILE* fp, void* buffer, u32 offset, u32 length) | ||
{ | ||
fseek(fp, offset, SEEK_SET); | ||
return fread(buffer, length, 1, fp); | ||
} | ||
|
||
s32 FSOPReadOpenFileA(FILE* fp, void** buffer, u32 offset, u32 length) | ||
{ | ||
*buffer = memalign(32, length); | ||
if (!*buffer) | ||
return -1; | ||
|
||
s32 ret = FSOPReadOpenFile(fp, *buffer, offset, length); | ||
if (ret <= 0) | ||
{ | ||
free(*buffer); | ||
*buffer = NULL; | ||
} | ||
|
||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef __FILEOPS_H__ | ||
#define __FILEOPS_H__ | ||
|
||
#include <sys/stat.h> | ||
#include <dirent.h> | ||
#include <ogcsys.h> | ||
|
||
bool FSOPFileExists(const char* file); | ||
bool FSOPFolderExists(const char* path); | ||
size_t FSOPGetFileSizeBytes(const char* path); | ||
|
||
void FSOPDeleteFile(const char* file); | ||
void FSOPMakeFolder(const char* path); | ||
|
||
s32 FSOPReadOpenFile(FILE* fp, void* buffer, u32 offset, u32 length); | ||
s32 FSOPReadOpenFileA(FILE* fp, void** buffer, u32 offset, u32 length); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.