public: optimize MD5_Print function.

This commit is contained in:
Andrey Akhmichin 2020-09-03 20:58:57 +05:00 committed by Alibek Omarov
parent 5cdb35f508
commit 23ea7ecbcc
3 changed files with 31 additions and 5 deletions

View File

@ -438,16 +438,12 @@ transform hash to hexadecimal printable symbols
char *MD5_Print( byte hash[16] )
{
static char szReturn[64];
char szChunk[10];
int i;
memset( szReturn, 0, 64 );
for( i = 0; i < 16; i++ )
{
Q_snprintf( szChunk, sizeof( szChunk ), "%02X", hash[i] );
Q_strncat( szReturn, szChunk, sizeof( szReturn ));
}
COM_Hex2String( hash[i], &szReturn[i * 2] );
return szReturn;
}

View File

@ -918,6 +918,33 @@ void COM_PathSlashFix( char *path )
Q_strcpy( &path[len], "/" );
}
/*
============
COM_Hex2Char
============
*/
char COM_Hex2Char( uint8_t hex )
{
if( hex >= 0x0 && hex <= 0x9 )
hex += '0';
else if( hex >= 0xA && hex <= 0xF )
hex += '7';
return (char)hex;
}
/*
============
COM_Hex2String
============
*/
void COM_Hex2String( uint8_t hex, char *str )
{
*str++ = COM_Hex2Char( hex >> 4 );
*str++ = COM_Hex2Char( hex & 0x0F );
*str = '\0';
}
int matchpattern( const char *in, const char *pattern, qboolean caseinsensitive )
{
return matchpattern_with_separator( in, pattern, caseinsensitive, "/\\:", false );
@ -983,3 +1010,4 @@ int matchpattern_with_separator( const char *in, const char *pattern, qboolean c
return 0; // reached end of pattern but not end of input
return 1; // success
}

View File

@ -84,6 +84,8 @@ const char *COM_FileWithoutPath( const char *in );
void COM_StripExtension( char *path );
void COM_RemoveLineFeed( char *str );
void COM_PathSlashFix( char *path );
char COM_Hex2Char( uint8_t hex );
void COM_Hex2String( uint8_t hex, char *str );
#define COM_CheckString( string ) ( ( !string || !*string ) ? 0 : 1 )
int matchpattern( const char *in, const char *pattern, qboolean caseinsensitive );
int matchpattern_with_separator( const char *in, const char *pattern, qboolean caseinsensitive, const char *separators, qboolean wildcard_least_one );