Practice ยท 1 of 3
The Refusing Copy
CHALLENGE
Difficulty: advanced+25 XP
ISO C. Implement int safe_copy(char *dst, size_t dstsize, const char *src) โ copy src into dst with NUL-termination only if it fits (including the terminator); return 0 on success, -1 on truncation-or-error (dst NULL, dstsize 0, src NULL, or src longer than dstsize-1). On refusal dst is left untouched. This is snprintf's semantics, hand-rolled.
Press Submit to check your solution.
Back to lesson: Practice: Hardening Drills