Skip to content

Commit

Permalink
Merge pull request cc65#2464 from SvenMichaelKlose/stpcpy
Browse files Browse the repository at this point in the history
Add stpcpy().
  • Loading branch information
mrdudz authored Jul 15, 2024
2 parents 6551d45 + aed94d2 commit 03d824e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ char* __fastcall__ strlower (char* s);
char* __fastcall__ strupr (char* s);
char* __fastcall__ strupper (char* s);
char* __fastcall__ strqtok (char* s1, const char* s2);
char* __fastcall__ stpcpy (char* dest, const char* src);
#endif

const char* __fastcall__ __stroserror (unsigned char errcode);
Expand Down
7 changes: 7 additions & 0 deletions libsrc/common/stpcpy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <string.h>

char * __fastcall__ stpcpy (char * dst, const char * src)
{
strcpy (dst, src);
return dst + strlen (src);
}
44 changes: 44 additions & 0 deletions test/val/stpcpy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 2024-07-15 Sven Michael Klose <pixel@hugbox.org>

#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#define STR_SHORT "Hello, World!"
#define STR_LONG "This is a longer test string for stpcpy."

int
main ()
{
char dest[50];
const char *src_empty;
const char *src_short;
const char *src_long;
char *end;

src_empty = "";
end = stpcpy (dest, src_empty);
assert(!strcmp (dest, src_empty));
assert(!*end);
assert(end == dest);
printf ("Test 1 passed.\n");

src_short = STR_SHORT;
end = stpcpy (dest, src_short);
assert(!strcmp (dest, src_short));
assert(!*end);
assert(end == &dest[sizeof (STR_SHORT) - 1]);
printf ("Test 2 passed.\n");

src_long = STR_LONG;
end = stpcpy (dest, src_long);
assert(!strcmp (dest, src_long));
assert(!*end);
assert(end == &dest[sizeof (STR_LONG) - 1]);
printf ("Test 3 passed.\n");

printf ("All tests passed.\n");
return EXIT_SUCCESS;
}

0 comments on commit 03d824e

Please sign in to comment.