1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include "string.h" #include "stdlib.h" int main( void ) { char *s = "test_string"; char d[8]; size_t n; // copy into too small string n = strlcpy( d, s, 4 ); if( n != 11 ) exit( 1 ); if( strcmp( d, "tes" ) ) exit( 1 ); exit( 0 ); }