Browse Source

public: add generic implementation for Q_memmem

pull/2/head
Alibek Omarov 2 years ago
parent
commit
07e622f224
  1. 17
      public/crtlib.c
  2. 1
      public/crtlib.h

17
public/crtlib.c

@ -372,6 +372,23 @@ qboolean Q_stricmpext( const char *pattern, const char *text )
return Q_strnicmpext( pattern, text, ~((size_t)0) ); return Q_strnicmpext( pattern, text, ~((size_t)0) );
} }
const byte *Q_memmem( const byte *haystack, size_t haystacklen, const byte *needle, size_t needlelen )
{
const byte *i;
// quickly find first matching symbol
while( haystacklen && ( i = memchr( haystack, needle[0], haystacklen )))
{
if( !memcmp( i, needle, needlelen ))
return i;
haystacklen -= i - haystack;
haystack = i + 1;
}
return NULL;
}
const char* Q_timestamp( int format ) const char* Q_timestamp( int format )
{ {
static string timestamp; static string timestamp;

1
public/crtlib.h

@ -78,6 +78,7 @@ void Q_atov( float *vec, const char *str, size_t siz );
#define Q_strrchr strrchr #define Q_strrchr strrchr
qboolean Q_stricmpext( const char *pattern, const char *text ); qboolean Q_stricmpext( const char *pattern, const char *text );
qboolean Q_strnicmpext( const char *pattern, const char *text, size_t minimumlen ); qboolean Q_strnicmpext( const char *pattern, const char *text, size_t minimumlen );
const byte *Q_memmem( const byte *haystack, size_t haystacklen, const byte *needle, size_t needlelen );
const char *Q_timestamp( int format ); const char *Q_timestamp( int format );
#define Q_vsprintf( buffer, format, args ) Q_vsnprintf( buffer, 99999, format, args ) #define Q_vsprintf( buffer, format, args ) Q_vsnprintf( buffer, 99999, format, args )
int Q_vsnprintf( char *buffer, size_t buffersize, const char *format, va_list args ); int Q_vsnprintf( char *buffer, size_t buffersize, const char *format, va_list args );

Loading…
Cancel
Save