Don't call vg_assert inside sync_signalhandler_from_kernel
[valgrind.git] / memcheck / tests / memccpy1.c
blob91855cf4635c478d0c4f1013c63b546a3e0cede2
1 // Example copied from https://en.cppreference.com/w/c/string/byte/memccpy
2 #include <ctype.h>
3 #include <stdio.h>
4 #include <string.h>
6 int main(void)
8 const char src0[] = "Stars: Altair, Sun, Vega.";
9 const char* src = strdup(src0);
10 const char terminal[] = {':', ' ', ',', '.', '!'};
11 char dest[sizeof src0];
12 const char alt = '@';
14 for (size_t i = 0; i != sizeof terminal; ++i)
16 void* to = memccpy(dest, src, terminal[i], sizeof dest);
18 printf("Terminal '%c' (%s):\t\"", terminal[i], to ? "found" : "absent");
20 // if `terminal` character was not found - print the whole `dest`
21 to = to ? to : dest + sizeof dest;
23 for (char* from = dest; from != to; ++from)
24 putchar(isprint(*from) ? *from : alt);
26 puts("\"");
30 puts("\n" "Separate star names from distances (ly):");
31 const char *star_distance[] = {
32 "Arcturus : 37", "Vega : 25", "Capella : 43", "Rigel : 860", "Procyon : 11"
34 char names_only[64];
35 char *first = names_only;
36 char *last = names_only + sizeof names_only;
38 for (size_t t = 0; t != (sizeof star_distance) / (sizeof star_distance[0]); ++t)
40 if (first)
41 first = memccpy(first, star_distance[t], ' ', last - first);
42 else
43 break;
46 if (first)
48 *first = '\0';
49 puts(names_only);
51 else
52 puts("Buffer is too small.");