summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'string.c')
-rw-r--r--string.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/string.c b/string.c
index 540a7d4..dc73266 100644
--- a/string.c
+++ b/string.c
@@ -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;
+}
+