rendered paste body#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#undef sizeof
#define sizeof( ptr ) \
( ( __builtin_object_size( ptr, 0 ) == -1 ) ? 0 : __builtin_object_size( ptr, 0 ) )
#if 1
#undef strcpy
#define strcpy( dst, src ) \
strncpy( dst, src, sizeof( dst ) - 1 ); \
dst[ sizeof( dst ) - 1 ] = 0
#undef strcat
#define strcat( dst, src ) \
strncat( dst, src, sizeof( dst ) - strlen( dst ) - 1 )
#undef sprintf
#define sprintf( dst, fmt, args ... ) \
snprintf( dst, sizeof( dst ), fmt, ## args )
#undef vsprintf
#define vsprintf( dst, fmt, args ) \
vsnprintf( dst, sizeof( dst ), fmt, args )
#else
#undef strcpy
#define strcpy()
#undef strcat
#define strcat()
#undef sprintf
#define sprintf()
#undef vsprintf
#define vsprintf()
#endif
char buf[ 20 ], *txt;
void vsprintf_test( char *fmt, ... );
int main( int argc, char *argv[] ) {
txt = "zu langer test string";
printf( "sizeof( buf ): %d\n", sizeof( buf ) );
printf( "sizeof( buf + 1 ): %d\n", sizeof( buf + 1 ) );
strcpy( buf, "12345678901234567890" );
printf( "buf = %s\n", buf );
strcpy( buf, "2. " );
strcat( buf, txt );
printf( "buf = %s\n", buf );
sprintf( buf, "%d. %s", 3, txt );
printf( "buf = %s\n", buf );
vsprintf_test( "%d. %s", 4, txt );
printf( "buf = %s\n", buf );
return 0;
}
void vsprintf_test( char *fmt, ... ) {
va_list args;
va_start( args, fmt );
vsprintf( buf, fmt, args );
va_end( args );
}