]>
git.saurik.com Git - apple/libc.git/blob - tests/strlcat.c
2 #include <mach/mach_types.h>
6 static const char* qbf
= "The quick brown fox jumps over the lazy dog";
7 static const char* lynx
= "Lynx c.q. vos prikt bh: dag zwemjuf!";
12 test_start("strlcat");
14 void *ptr
= mmap(NULL
, PAGE_SIZE
*2, PROT_READ
|PROT_WRITE
, MAP_ANON
|MAP_PRIVATE
, -1, 0);
15 test_ptr_not("mmap", ptr
, MAP_FAILED
);
17 test_errno("mprotect", mprotect(ptr
+PAGE_SIZE
, PAGE_SIZE
, PROT_READ
), 0);
19 off_t offset
= strlen(qbf
)+strlen(lynx
)+1;
20 char *dst
= (ptr
+PAGE_SIZE
)-offset
;
23 size_t res
= strlcat(dst
, lynx
, offset
);
24 test_long("strlcat", res
, offset
-1);
25 test_long("memcmp", memcmp(dst
, qbf
, strlen(qbf
)), 0);
26 test_long("memcmp", memcmp(dst
+strlen(qbf
), lynx
, strlen(lynx
)), 0);
27 test_long("null-term", dst
[offset
], 0);
29 memset(ptr
, '\0', PAGE_SIZE
);
31 offset
= strlen(qbf
)+(strlen(lynx
)/2)+1;
32 dst
= (ptr
+PAGE_SIZE
)-offset
;
35 res
= strlcat(dst
, lynx
, offset
);
36 test_long("strlcat", res
, strlen(qbf
)+strlen(lynx
));
37 test_long("memcmp", memcmp(dst
, qbf
, strlen(qbf
)), 0);
38 test_long("memcmp", memcmp(dst
+strlen(qbf
), lynx
, offset
-strlen(qbf
)-1), 0);
39 test_long("overrun", *(char*)(ptr
+PAGE_SIZE
), 0);
40 test_long("null-term", dst
[offset
], 0);
42 memset(ptr
, '\0', PAGE_SIZE
);
44 offset
= strlen(qbf
)-4;
45 dst
= (ptr
+PAGE_SIZE
)-offset
;
46 strncpy(dst
, qbf
, offset
);
48 res
= strlcat(dst
, lynx
, offset
);
49 test_long("strlcat", res
, offset
+strlen(lynx
));
50 test_long("memcmp", memcmp(dst
, qbf
, offset
), 0);
51 test_long("overrun", *(char*)(ptr
+PAGE_SIZE
), 0);
52 test_long("null-term", dst
[offset
], 0);