public: slight refactoring

This commit is contained in:
Alibek Omarov 2024-12-17 19:57:27 +03:00
parent ca0c5f929a
commit b4afe390d6

View file

@ -171,14 +171,13 @@ static inline char *Q_strstr( const char *s1, const char *s2 )
// libc extensions, be careful what to enable or what not
static inline size_t Q_strncpy( char *dst, const char *src, size_t size )
{
#if HAVE_STRLCPY
if( unlikely( !dst || !src || !size ))
return 0;
#if HAVE_STRLCPY
return strlcpy( dst, src, size );
#else
{
size_t len;
if( unlikely( !dst || !src || !size ))
return 0;
len = strlen( src );
if( len + 1 > size ) // check if truncate
@ -189,24 +188,23 @@ static inline size_t Q_strncpy( char *dst, const char *src, size_t size )
else memcpy( dst, src, len + 1 );
return len; // count does not include NULL
}
#endif
}
static inline size_t Q_strncat( char *dst, const char *src, size_t size )
{
#if HAVE_STRLCAT
if( unlikely( !dst || !src || !size ))
return 0;
#if HAVE_STRLCAT
return strlcat( dst, src, size );
#else
{
char *d = dst;
const char *s = src;
size_t n = size;
size_t dlen;
if( unlikely( !dst || !src || !size ))
return 0;
// find the end of dst and adjust bytes left but don't go past end
while( n-- != 0 && *d != '\0' ) d++;
dlen = d - dst;
@ -226,6 +224,7 @@ static inline size_t Q_strncat( char *dst, const char *src, size_t size )
*d = '\0';
return( dlen + ( s - src )); // count does not include NULL
}
#endif
}