diff options
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -57,3 +57,19 @@ strncmp(const char *p, const char *q, uint n) else return (int) ((uchar) *p - (uchar) *q); } + +// Like strncpy but guaranteed to NUL-terminate. +char* +safestrcpy(char *s, const char *t, int n) +{ + char *os; + + os = s; + if(n <= 0) + return os; + while(--n > 0 && (*s++ = *t++) != 0) + ; + *s = 0; + return os; +} + |