first commit
This commit is contained in:
53
src/engine/file.c
Normal file
53
src/engine/file.c
Normal file
@ -0,0 +1,53 @@
|
||||
#include "file.h"
|
||||
|
||||
bool
|
||||
file_read(const char* path, void* buffer, size_t size, const char* mode)
|
||||
{
|
||||
SDL_RWops* io;
|
||||
|
||||
printf(STRING_FILE_READ_OPEN, path);
|
||||
|
||||
io = SDL_RWFromFile(path, mode);
|
||||
|
||||
if (!io)
|
||||
{
|
||||
printf(STRING_FILE_READ_ERROR, path);
|
||||
return false;
|
||||
}
|
||||
|
||||
SDL_RWread(io, buffer, size, 1);
|
||||
|
||||
printf(STRING_FILE_READ_SUCCESS, path);
|
||||
|
||||
SDL_RWclose(io);
|
||||
|
||||
printf(STRING_FILE_CLOSED, path);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
file_write(const char* path, void* data, size_t size, const char* mode)
|
||||
{
|
||||
SDL_RWops* io;
|
||||
|
||||
printf(STRING_FILE_WRITE_OPEN, path);
|
||||
|
||||
io = SDL_RWFromFile(path, mode);
|
||||
|
||||
if (!io)
|
||||
{
|
||||
printf(STRING_FILE_WRITE_ERROR, path);
|
||||
return false;
|
||||
}
|
||||
|
||||
SDL_RWwrite(io, data, size, 1);
|
||||
|
||||
printf(STRING_FILE_WRITE_SUCCESS, path);
|
||||
|
||||
SDL_RWclose(io);
|
||||
|
||||
printf(STRING_FILE_CLOSED, path);
|
||||
|
||||
return true;
|
||||
}
|
Reference in New Issue
Block a user