Browse Source

public: optimize MD5_Print function.

pull/2/head
Andrey Akhmichin 4 years ago committed by Alibek Omarov
parent
commit
23ea7ecbcc
  1. 6
      public/crclib.c
  2. 28
      public/crtlib.c
  3. 2
      public/crtlib.h

6
public/crclib.c

@ -438,16 +438,12 @@ transform hash to hexadecimal printable symbols @@ -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;
}

28
public/crtlib.c

@ -918,6 +918,33 @@ void COM_PathSlashFix( char *path ) @@ -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 @@ -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
}

2
public/crtlib.h

@ -84,6 +84,8 @@ const char *COM_FileWithoutPath( const char *in ); @@ -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 );

Loading…
Cancel
Save