Files
frillrun/src/engine/file.c
2024-08-24 00:47:58 -04:00

54 lines
805 B
C

#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;
}