mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-05 03:24:56 +08:00
public: add Q_memfgets, replacement for COM_MemFgets rewritten using crtlib functions. Add a test
This commit is contained in:
@@ -597,7 +597,6 @@ void COM_HexConvert( const char *pszInput, int nInputLength, byte *pOutput )
|
||||
byte *p = pOutput;
|
||||
int i;
|
||||
|
||||
|
||||
for( i = 0; i < nInputLength; i += 2 )
|
||||
{
|
||||
pIn = &pszInput[i];
|
||||
@@ -606,59 +605,6 @@ void COM_HexConvert( const char *pszInput, int nInputLength, byte *pOutput )
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
=============
|
||||
COM_MemFgets
|
||||
|
||||
=============
|
||||
*/
|
||||
char *GAME_EXPORT COM_MemFgets( byte *pMemFile, int fileSize, int *filePos, char *pBuffer, int bufferSize )
|
||||
{
|
||||
int i, last, stop;
|
||||
|
||||
if( !pMemFile || !pBuffer || !filePos )
|
||||
return NULL;
|
||||
|
||||
if( *filePos >= fileSize )
|
||||
return NULL;
|
||||
|
||||
i = *filePos;
|
||||
last = fileSize;
|
||||
|
||||
// fgets always NULL terminates, so only read bufferSize-1 characters
|
||||
if( last - *filePos > ( bufferSize - 1 ))
|
||||
last = *filePos + ( bufferSize - 1);
|
||||
|
||||
stop = 0;
|
||||
|
||||
// stop at the next newline (inclusive) or end of buffer
|
||||
while( i < last && !stop )
|
||||
{
|
||||
if( pMemFile[i] == '\n' )
|
||||
stop = 1;
|
||||
i++;
|
||||
}
|
||||
|
||||
// if we actually advanced the pointer, copy it over
|
||||
if( i != *filePos )
|
||||
{
|
||||
// we read in size bytes
|
||||
int size = i - *filePos;
|
||||
|
||||
// copy it out
|
||||
memcpy( pBuffer, pMemFile + *filePos, size );
|
||||
|
||||
// If the buffer isn't full, terminate (this is always true)
|
||||
if( size < bufferSize ) pBuffer[size] = 0;
|
||||
|
||||
// update file pointer
|
||||
*filePos = i;
|
||||
return pBuffer;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
=============
|
||||
COM_LoadFileForMe
|
||||
|
||||
@@ -628,7 +628,6 @@ qboolean SV_Active( void );
|
||||
|
||||
==============================================================
|
||||
*/
|
||||
char *COM_MemFgets( byte *pMemFile, int fileSize, int *filePos, char *pBuffer, int bufferSize );
|
||||
void COM_HexConvert( const char *pszInput, int nInputLength, byte *pOutput );
|
||||
byte COM_Nibble( char c );
|
||||
int COM_SaveFile( const char *filename, const void *data, int len );
|
||||
|
||||
Reference in New Issue
Block a user