Optimize stpcpy's size and speed

This commit is contained in:
Colin Leroy-Mira
2024-09-04 22:52:52 +02:00
parent 5e5dd1d6c4
commit 55d3a6ea39
4 changed files with 38 additions and 11 deletions

View File

@@ -8,10 +8,12 @@
#define STR_SHORT "Hello, World!"
#define STR_LONG "This is a longer test string for stpcpy."
char dest[512];
char multi_page[300];
int
main ()
{
char dest[50];
const char *src_empty;
const char *src_short;
const char *src_long;
@@ -38,7 +40,14 @@ main ()
assert(end == &dest[sizeof (STR_LONG) - 1]);
printf ("Test 3 passed.\n");
memset(multi_page, 'a', sizeof(multi_page)-1);
multi_page[sizeof(multi_page)-1] = '\0';
end = stpcpy (dest, multi_page);
assert(!strcmp (dest, multi_page));
assert(!*end);
assert(end == &dest[sizeof (multi_page) - 1]);
printf ("Test 4 passed.\n");
printf ("All tests passed.\n");
return EXIT_SUCCESS;
}