FreeBSD regtest: add fakes for older versions in scalar
[valgrind.git] / memcheck / tests / memccpy2.c
blob947324581715a7cb52fff98f72ebe05d4182c183
1 #include <ctype.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <assert.h>
5 #include <stdlib.h>
7 int main(void)
9 char* astring = strdup("this is a string # with something to seek");
10 size_t len = strlen(astring);
11 memccpy(astring+10, astring, '#', len-10);
12 sprintf(astring, "this is a string # with something to seek");
13 memccpy(astring, astring+10, '#', len);
15 sprintf(astring, "this is a string # with something to seek");
17 * space is earlier than len, no overlap
18 * "this " gets copied (up to and including the first ' ')
19 * and it overwrites the destination starting with the 's' of "string"
20 * so res will point to the 'g' of "string"
22 char* res = memccpy(astring+10, astring, ' ', len-10);
23 assert(res && *res == 'g');
24 sprintf(astring, "this is a string # with something to seek");
25 /* length is 0, nothing copied, returns NULL */
26 res = memccpy(astring, "abcdefhhijklmnopqrstuvwxy", 'z', 0);
27 assert(NULL == res);
28 /* 'z' not found so 20 bytes copied, returns NULL */
29 res = memccpy(astring, "abcdefhhijklmnopqrstuvwxy", 'z', 20);
30 assert(NULL == res);
31 free(astring);