Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char *Q_strncpyz( char *dst, const char *src, size_t len ) {
- if ( len == 0 ) {
- abort();
- }
- strncpy( dst, src, len );
- dst[ len -1 ] = '\0';
- return dst;
- }
- char *Q_strcat( char *dst, size_t dlen, const char *src ) {
- size_t n = strlen( dst );
- if ( n > dlen ) {
- abort(); /* buffer overflow */
- }
- return Q_strncpyz( dst + n, src, dlen - n );
- }
- char *Q_strncat( char *dst, size_t dlen, const char *src, size_t slen ) {
- size_t n = strlen( dst );
- if ( n > dlen ) {
- abort(); /* buffer overflow */
- }
- // hack +1, that extra char outside slen will be rewritten by \0 by Q_strncpyz even if there is already a \0
- // and if it's not a \0, we do not want to copy it but since it will be rewritten by \0 it's ok.
- return Q_strncpyz( dst + n, src, MIN( slen + 1, dlen - n ) );
- }
Add Comment
Please, Sign In to add comment