From 071638794a12e905f88147f4806110c712596616 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sat, 17 Dec 2022 23:17:32 +0300 Subject: [PATCH] public: redefine Q_strpbrk to C standard version, add Q_strchrnul --- public/crtlib.c | 16 ---------------- public/crtlib.h | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/public/crtlib.c b/public/crtlib.c index 34972978..25af49de 100644 --- a/public/crtlib.c +++ b/public/crtlib.c @@ -496,22 +496,6 @@ int Q_sprintf( char *buffer, const char *format, ... ) return result; } -char *Q_strpbrk(const char *s, const char *accept) -{ - for( ; *s; s++ ) - { - const char *k; - - for( k = accept; *k; k++ ) - { - if( *s == *k ) - return (char*)s; - } - } - - return NULL; -} - void COM_StripColors( const char *in, char *out ) { while ( *in ) diff --git a/public/crtlib.h b/public/crtlib.h index f3013a8f..6296930d 100644 --- a/public/crtlib.h +++ b/public/crtlib.h @@ -83,7 +83,7 @@ const char *Q_timestamp( int format ); int Q_vsnprintf( char *buffer, size_t buffersize, const char *format, va_list args ); int Q_snprintf( char *buffer, size_t buffersize, const char *format, ... ) _format( 3 ); int Q_sprintf( char *buffer, const char *format, ... ) _format( 2 ); -char *Q_strpbrk(const char *s, const char *accept); +#define Q_strpbrk strpbrk void COM_StripColors( const char *in, char *out ); #define Q_memprint( val ) Q_pretifymem( val, 2 ) char *Q_pretifymem( float value, int digitsafterdecimal ); @@ -161,6 +161,20 @@ static inline char *Q_stristr( const char *s1, const char *s2 ) char *Q_stristr( const char *s1, const char *s2 ); #endif // defined( HAVE_STRCASESTR ) +#if defined( HAVE_STRCHRNUL ) +#define Q_strchrnul strchrnul +#else +static inline const char *Q_strchrnul( const char *s, int c ) +{ + const char *p = Q_strchr( s, c ); + + if( p ) + return p; + + return s + Q_strlen( s ); +} +#endif + #ifdef __cplusplus } #endif