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:
Alibek Omarov
2023-06-27 04:11:13 +03:00
parent 40e248aa63
commit aee5e46516
2 changed files with 19 additions and 30 deletions

View File

@@ -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;