0054-wcsncpy.c (724B)
1 #include <assert.h> 2 #include <stdio.h> 3 #include <wchar.h> 4 5 #define SIZ 6 6 7 /* 8 output: 9 testing 10 test1 11 test2 12 test3 13 done 14 end: 15 */ 16 17 int 18 main() 19 { 20 wchar_t *s, buf[SIZ]; 21 wchar_t abc[] = {'a', 'b', 'c'}; 22 23 puts("testing"); 24 25 puts("test1"); 26 wmemset(buf, '0', SIZ); 27 s = wcsncpy(buf, abc, SIZ); 28 assert(s == buf); 29 assert(!wmemcmp(s, abc, SIZ)); 30 31 puts("test2"); 32 wmemset(buf, '0', SIZ); 33 s = wcsncpy(buf, (wchar_t[]) {0}, SIZ); 34 assert(s == buf); 35 assert(!wmemcmp(s, (wchar_t[SIZ]) {0}, SIZ)); 36 37 puts("test3"); 38 wmemset(buf, '0', SIZ); 39 s = wcsncpy(buf, (wchar_t[]) {0}, 1); 40 assert(s == buf); 41 assert(!wmemcmp(s, 42 (wchar_t[SIZ]) {'\0', '0', '0', '0', '0', '0'}, 43 SIZ)); 44 45 puts("done"); 46 47 return 0; 48 }