- fixed: The demo buffer was allocated with conflicting methods, because M_ReadFile used new whereas the rest of the demo code assumed malloc. Added a new M_ReadFileMalloc function to handle this case without rewriting other things.

This commit is contained in:
Christoph Oelckers 2014-11-25 17:00:17 +01:00
commit 29ecbac963
3 changed files with 28 additions and 1 deletions

View file

@ -137,6 +137,32 @@ int M_ReadFile (char const *name, BYTE **buffer)
return length;
}
//
// M_ReadFile (same as above but use malloc instead of new to allocate the buffer.)
//
int M_ReadFileMalloc (char const *name, BYTE **buffer)
{
int handle, count, length;
struct stat fileinfo;
BYTE *buf;
handle = open (name, O_RDONLY | O_BINARY, 0666);
if (handle == -1)
I_Error ("Couldn't read file %s", name);
if (fstat (handle,&fileinfo) == -1)
I_Error ("Couldn't read file %s", name);
length = fileinfo.st_size;
buf = (BYTE*)M_Malloc(length);
count = read (handle, buf, length);
close (handle);
if (count < length)
I_Error ("Couldn't read file %s", name);
*buffer = buf;
return length;
}
//---------------------------------------------------------------------------
//
// PROC M_FindResponseFile