diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/str.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -6,13 +6,18 @@ destsz must be greater than 0. */ size_t str_copy(char *dest, size_t destsz, const char *src) { assert(destsz); + if (!*src) { + *dest = 0; + return 0; + } for (size_t i = 0; i < destsz-1; i++) { + *dest = *src; if (!*src) { *dest = 0; return i; } - *dest++ = *src++; + src++; dest++; } - dest[destsz] = 0; + dest[destsz-1] = 0; return destsz-1; } |