Implement strcpy() and a safe bounded copy.
#include <stddef.h>
char *my_strcpy(char *dst, const char *src)
{
char *d = dst;
while ((*d++ = *src++) != '\0') { } /* copies the terminator too */
return dst;
}
/* bounded: always terminates, returns strlen(src) so truncation can be detected (like strlcpy) */
size_t my_strlcpy(char *dst, const char *src, size_t size)
{
size_t n = 0;
while (src[n]) n++;
if (size) {
size_t c = (n >= size) ? size - 1 : n;
for (size_t i = 0; i < c; i++) dst[i] = src[i];
dst[c] = '\0';
}
return n;
}
Points: strcpy has no bounds check (classic overflow); overlapping buffers are undefined; return the original dst. Truncation happened if my_strlcpy(...) >= size.