|
|
@ -10,13 +10,13 @@ |
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
|
|
|
|
FILE* File::Open(const char* path, const char* mode) { |
|
|
|
FILE* File :: Open(const char* path, const char* mode) { |
|
|
|
ULE_TYPES_H_FTAG; |
|
|
|
return fopen(path, mode); |
|
|
|
} |
|
|
|
FILE* File::Open(const char* path, size_t* outSize, const char* mode) { |
|
|
|
FILE* File :: Open(const char* path, size_t* outSize, const char* mode) { |
|
|
|
ULE_TYPES_H_FTAG; |
|
|
|
FILE* fp = File::Open(path, mode); |
|
|
|
FILE* fp = File :: Open(path, mode); |
|
|
|
|
|
|
|
if (fp == null) { |
|
|
|
return null; |
|
|
@ -29,13 +29,13 @@ FILE* File::Open(const char* path, size_t* outSize, const char* mode) { |
|
|
|
|
|
|
|
return fp; |
|
|
|
} |
|
|
|
void File::Close(FILE* file) { |
|
|
|
void File :: Close(FILE* file) { |
|
|
|
fclose(file); |
|
|
|
} |
|
|
|
|
|
|
|
size_t File::Size(const char* path) { |
|
|
|
size_t File :: Size(const char* path) { |
|
|
|
ULE_TYPES_H_FTAG; |
|
|
|
FILE* fp = File::Open(path); |
|
|
|
FILE* fp = File :: Open(path); |
|
|
|
// get the file's size in bytes
|
|
|
|
fseek(fp, 0, SEEK_END); |
|
|
|
size_t size = ftell(fp); |
|
|
@ -43,7 +43,7 @@ size_t File::Size(const char* path) { |
|
|
|
fclose(fp); |
|
|
|
return size; |
|
|
|
} |
|
|
|
size_t File::Size(FILE* fp) { |
|
|
|
size_t File :: Size(FILE* fp) { |
|
|
|
ULE_TYPES_H_FTAG; |
|
|
|
fseek(fp, 0, SEEK_END); |
|
|
|
size_t size = ftell(fp); |
|
|
@ -51,9 +51,9 @@ size_t File::Size(FILE* fp) { |
|
|
|
return size; |
|
|
|
} |
|
|
|
|
|
|
|
u8* File::Read(const char* path) { |
|
|
|
u8* File :: Read(const char* path) { |
|
|
|
ULE_TYPES_H_FTAG; |
|
|
|
FILE* fp = File::Open(path, "rb"); |
|
|
|
FILE* fp = File :: Open(path, "rb"); |
|
|
|
|
|
|
|
if (fp == null) { |
|
|
|
return null; |
|
|
@ -72,9 +72,9 @@ u8* File::Read(const char* path) { |
|
|
|
|
|
|
|
return (u8*) buffer; |
|
|
|
} |
|
|
|
u8* File::Read(const char* path, size_t* outSize) { |
|
|
|
u8* File :: Read(const char* path, size_t* outSize) { |
|
|
|
ULE_TYPES_H_FTAG; |
|
|
|
FILE* fp = File::Open(path, "rb"); |
|
|
|
FILE* fp = File :: Open(path, "rb"); |
|
|
|
|
|
|
|
if (fp == null) { |
|
|
|
return null; |
|
|
@ -97,7 +97,7 @@ u8* File::Read(const char* path, size_t* outSize) { |
|
|
|
|
|
|
|
return (u8*) buffer; |
|
|
|
} |
|
|
|
size_t File::Read(FILE* fp, void* destination) { |
|
|
|
size_t File :: Read(FILE* fp, void* destination) { |
|
|
|
ULE_TYPES_H_FTAG; |
|
|
|
|
|
|
|
fseek(fp, 0, SEEK_END); |
|
|
@ -107,14 +107,14 @@ size_t File::Read(FILE* fp, void* destination) { |
|
|
|
fread(destination, sizeof (char), size + 1, fp); |
|
|
|
return size; |
|
|
|
} |
|
|
|
size_t File::Read(FILE* fp, void* destination, size_t size) { |
|
|
|
size_t File :: Read(FILE* fp, void* destination, size_t size) { |
|
|
|
ULE_TYPES_H_FTAG; |
|
|
|
return fread(destination, sizeof (char), size + 1, fp); |
|
|
|
} |
|
|
|
|
|
|
|
s32 File::Write(const char* path, char* data, u32 count) { |
|
|
|
s32 File :: Write(const char* path, char* data, u32 count) { |
|
|
|
ULE_TYPES_H_FTAG; |
|
|
|
FILE* fp = File::Open(path, "wb"); |
|
|
|
FILE* fp = File :: Open(path, "wb"); |
|
|
|
|
|
|
|
if (fp == null) { |
|
|
|
return -1; // failed to open the file
|
|
|
@ -133,7 +133,7 @@ s32 File::Write(const char* path, char* data, u32 count) { |
|
|
|
#if _WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
// writes the filenames into the provided array |outFileNames|, must be allocated ahead of time.
|
|
|
|
void File::GetFileNamesInFolder(const char* path, Array<char*>* outFileNames) { |
|
|
|
void File :: GetFileNamesInFolder(const char* path, Array<char*>* outFileNames) { |
|
|
|
ULE_TYPES_H_FTAG; |
|
|
|
massert(path != null, "provided 'null' for path argument"); |
|
|
|
massert(outFileNames != null, "provided 'null' for array argument"); |
|
|
@ -159,7 +159,7 @@ void File::GetFileNamesInFolder(const char* path, Array<char*>* outFileNames) { |
|
|
|
} |
|
|
|
#else
|
|
|
|
#include <dirent.h>
|
|
|
|
void File::GetFileNamesInFolder(const char* path, Array<char*>* outFileNames) { |
|
|
|
void File :: GetFileNamesInFolder(const char* path, Array<char*>* outFileNames) { |
|
|
|
ULE_TYPES_H_FTAG; |
|
|
|
massert(path != null, "provided 'null' for path argument"); |
|
|
|
massert(outFileNames != null, "provided 'null' for array argument"); |
|
|
@ -188,7 +188,7 @@ void File::GetFileNamesInFolder(const char* path, Array<char*>* outFileNames) { |
|
|
|
#define stat _stat
|
|
|
|
#endif
|
|
|
|
|
|
|
|
time_t File::LastModified(const char* path) { |
|
|
|
time_t File :: LastModified(const char* path) { |
|
|
|
ULE_TYPES_H_FTAG; |
|
|
|
struct stat result; |
|
|
|
if (stat(path, &result) == 0) { |
|
|
@ -199,11 +199,26 @@ time_t File::LastModified(const char* path) { |
|
|
|
} |
|
|
|
#undef stat
|
|
|
|
|
|
|
|
s32 File::Rename(const char* oldFilename, const char* newFilename) { |
|
|
|
s32 File :: Rename(const char* oldFilename, const char* newFilename) { |
|
|
|
return rename(oldFilename, newFilename); |
|
|
|
} |
|
|
|
|
|
|
|
s32 File::Remove(const char* path) { |
|
|
|
s32 File :: Remove(const char* path) { |
|
|
|
return remove(path); |
|
|
|
} |
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include <winbase.h>
|
|
|
|
FILE* OpenExclusive(const char* path) { |
|
|
|
HFILE result = OpenFile(path, null, OF_SHARE_EXCLUSIVE); |
|
|
|
if (result == HFILE_ERROR) { |
|
|
|
println("failed"); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
#else
|
|
|
|
FILE* OpenExclusive(const char* path) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
#endif
|
|
|
|
|