Change LoadFileToMemory's function signature
This commit is contained in:
parent
cf8977207e
commit
b650294b8b
4 changed files with 26 additions and 19 deletions
12
src/Draw.cpp
12
src/Draw.cpp
|
@ -282,10 +282,10 @@ BOOL MakeSurface_File(const char *name, SurfaceID surf_no)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
unsigned char *data;
|
||||
long size = LoadFileToMemory(path, &data);
|
||||
size_t size;
|
||||
unsigned char *data = LoadFileToMemory(path, &size);
|
||||
|
||||
if (size == -1)
|
||||
if (data == NULL)
|
||||
{
|
||||
PrintBitmapError(path, 1);
|
||||
return FALSE;
|
||||
|
@ -373,10 +373,10 @@ BOOL ReloadBitmap_File(const char *name, SurfaceID surf_no)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
unsigned char *data;
|
||||
long size = LoadFileToMemory(path, &data);
|
||||
size_t size;
|
||||
unsigned char *data = LoadFileToMemory(path, &size);
|
||||
|
||||
if (size == -1)
|
||||
if (data == NULL)
|
||||
{
|
||||
PrintBitmapError(path, 1);
|
||||
return FALSE;
|
||||
|
|
24
src/File.cpp
24
src/File.cpp
|
@ -4,9 +4,9 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
long LoadFileToMemory(const char *file_path, unsigned char **file_buffer)
|
||||
unsigned char* LoadFileToMemory(const char *file_path, size_t *file_size)
|
||||
{
|
||||
long returned_size = -1;
|
||||
unsigned char *buffer = NULL;
|
||||
|
||||
FILE *file = fopen(file_path, "rb");
|
||||
|
||||
|
@ -14,17 +14,23 @@ long LoadFileToMemory(const char *file_path, unsigned char **file_buffer)
|
|||
{
|
||||
if (!fseek(file, 0, SEEK_END))
|
||||
{
|
||||
const long file_size = ftell(file);
|
||||
const long _file_size = ftell(file);
|
||||
|
||||
if (file_size >= 0)
|
||||
if (_file_size >= 0)
|
||||
{
|
||||
rewind(file);
|
||||
*file_buffer = (unsigned char*)malloc(file_size);
|
||||
buffer = (unsigned char*)malloc(_file_size);
|
||||
|
||||
if (*file_buffer != NULL)
|
||||
if (buffer != NULL)
|
||||
{
|
||||
if (fread(*file_buffer, file_size, 1, file) == 1)
|
||||
returned_size = file_size;
|
||||
if (fread(buffer, _file_size, 1, file) == 1)
|
||||
{
|
||||
fclose(file);
|
||||
*file_size = (size_t)_file_size;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +38,7 @@ long LoadFileToMemory(const char *file_path, unsigned char **file_buffer)
|
|||
fclose(file);
|
||||
}
|
||||
|
||||
return returned_size;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unsigned short File_ReadBE16(FILE *stream)
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
long LoadFileToMemory(const char *file_path, unsigned char **file_buffer);
|
||||
unsigned char* LoadFileToMemory(const char *file_path, size_t *file_size);
|
||||
|
||||
unsigned short File_ReadBE16(FILE *stream);
|
||||
unsigned long File_ReadBE32(FILE *stream);
|
||||
|
|
|
@ -1098,10 +1098,10 @@ FontObject* LoadFont(const char *font_filename, unsigned int cell_width, unsigne
|
|||
{
|
||||
FontObject *font_object = NULL;
|
||||
|
||||
unsigned char *file_buffer;
|
||||
const long file_size = LoadFileToMemory(font_filename, &file_buffer);
|
||||
size_t file_size;
|
||||
unsigned char *file_buffer = LoadFileToMemory(font_filename, &file_size);
|
||||
|
||||
if (file_size != -1)
|
||||
if (file_buffer != NULL)
|
||||
{
|
||||
font_object = LoadFontFromData(file_buffer, file_size, cell_width, cell_height);
|
||||
free(file_buffer);
|
||||
|
|
Loading…
Add table
Reference in a new issue