mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2025-02-09 01:01:07 +00:00
Host_Loadgame_f: fix for arrow characters appearing in multiline messages
on Windows, a regression introduced in the Host_Loadgame_f rewrite r1398 git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@1405 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
parent
3d3d46887a
commit
c827ccaa66
3 changed files with 16 additions and 8 deletions
|
@ -1872,13 +1872,17 @@ byte *COM_LoadMallocFile (const char *path, unsigned int *path_id)
|
|||
return COM_LoadFile (path, LOADFILE_MALLOC, path_id);
|
||||
}
|
||||
|
||||
byte *COM_LoadMallocFile_OSPath (const char *path, long *len_out)
|
||||
byte *COM_LoadMallocFile_TextMode_OSPath (const char *path, long *len_out)
|
||||
{
|
||||
FILE *f;
|
||||
byte *data;
|
||||
long len;
|
||||
long len, actuallen;
|
||||
|
||||
f = fopen (path, "rb");
|
||||
// ericw -- this is used by Host_Loadgame_f. Translate CRLF to LF on load games,
|
||||
// othewise multiline messages have a garbage character at the end of each line.
|
||||
// TODO: could handle in a way that allows loading CRLF savegames on mac/linux
|
||||
// without the junk characters appearing.
|
||||
f = fopen (path, "rt");
|
||||
if (f == NULL)
|
||||
return NULL;
|
||||
|
||||
|
@ -1889,15 +1893,18 @@ byte *COM_LoadMallocFile_OSPath (const char *path, long *len_out)
|
|||
data = (byte *) malloc (len + 1);
|
||||
if (data == NULL)
|
||||
return NULL;
|
||||
if (fread (data, 1, len, f) != len)
|
||||
|
||||
// (actuallen < len) if CRLF to LF translation was performed
|
||||
actuallen = fread (data, 1, len, f);
|
||||
if (ferror(f))
|
||||
{
|
||||
free (data);
|
||||
return NULL;
|
||||
}
|
||||
data[len] = '\0';
|
||||
data[actuallen] = '\0';
|
||||
|
||||
if (len_out != NULL)
|
||||
*len_out = len;
|
||||
*len_out = actuallen;
|
||||
return data;
|
||||
}
|
||||
|
||||
|
|
|
@ -257,7 +257,8 @@ byte *COM_LoadMallocFile (const char *path, unsigned int *path_id);
|
|||
|
||||
// Opens the given path directly, ignoring search paths.
|
||||
// Returns NULL on failure, or else a '\0'-terminated malloc'ed buffer.
|
||||
byte *COM_LoadMallocFile_OSPath (const char *path, long *len_out);
|
||||
// Loads in "t" mode so CRLF to LF translation is performed on Windows.
|
||||
byte *COM_LoadMallocFile_TextMode_OSPath (const char *path, long *len_out);
|
||||
|
||||
// Attempts to parse an int, followed by a newline.
|
||||
// Returns advanced buffer position.
|
||||
|
|
|
@ -1147,7 +1147,7 @@ void Host_Loadgame_f (void)
|
|||
if (start != NULL)
|
||||
free (start);
|
||||
|
||||
start = (char *) COM_LoadMallocFile_OSPath(name, NULL);
|
||||
start = (char *) COM_LoadMallocFile_TextMode_OSPath(name, NULL);
|
||||
if (start == NULL)
|
||||
{
|
||||
Con_Printf ("ERROR: couldn't open.\n");
|
||||
|
|
Loading…
Reference in a new issue