mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-05 03:24:56 +08:00
public: rewrite Q_strncpy with standard C functions, make it inlined to allow compiler remove unneeded checks
So far, passes all tests.
This commit is contained in:
@@ -134,35 +134,6 @@ size_t Q_strncat( char *dst, const char *src, size_t size )
|
||||
return( dlen + ( s - src )); // count does not include NULL
|
||||
}
|
||||
|
||||
size_t Q_strncpy( char *dst, const char *src, size_t size )
|
||||
{
|
||||
register char *d = dst;
|
||||
register const char *s = src;
|
||||
register size_t n = size;
|
||||
|
||||
if( !dst || !src || !size )
|
||||
return 0;
|
||||
|
||||
// copy as many bytes as will fit
|
||||
if( n != 0 && --n != 0 )
|
||||
{
|
||||
do
|
||||
{
|
||||
if(( *d++ = *s++ ) == 0 )
|
||||
break;
|
||||
} while( --n != 0 );
|
||||
}
|
||||
|
||||
// not enough room in dst, add NULL and traverse rest of src
|
||||
if( n == 0 )
|
||||
{
|
||||
if( size != 0 )
|
||||
*d = '\0'; // NULL-terminate dst
|
||||
while( *s++ );
|
||||
}
|
||||
return ( s - src - 1 ); // count does not include NULL
|
||||
}
|
||||
|
||||
int Q_atoi( const char *str )
|
||||
{
|
||||
int val = 0;
|
||||
|
||||
Reference in New Issue
Block a user