summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorrsc <rsc>2007-08-24 21:00:02 +0000
committerrsc <rsc>2007-08-24 21:00:02 +0000
commit766ba5cc06b45439cd3987aa782147041dab65c4 (patch)
tree0155e02e14ab2aa9b0b113e178a787d8d6c2d969 /string.c
parentaa6824ab64be037bfce9b0d991e6692282f8c1ab (diff)
downloadxv6-labs-766ba5cc06b45439cd3987aa782147041dab65c4.tar.gz
xv6-labs-766ba5cc06b45439cd3987aa782147041dab65c4.tar.bz2
xv6-labs-766ba5cc06b45439cd3987aa782147041dab65c4.zip
first ever correct use of strncpy
Diffstat (limited to 'string.c')
-rw-r--r--string.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/string.c b/string.c
index 0a92cca..2f9fc25 100644
--- a/string.c
+++ b/string.c
@@ -56,8 +56,20 @@ strncmp(const char *p, const char *q, uint n)
n--, p++, q++;
if(n == 0)
return 0;
- else
- return (int) ((uchar) *p - (uchar) *q);
+ return (uchar)*p - (uchar)*q;
+}
+
+char*
+strncpy(char *s, const char *t, int n)
+{
+ char *os;
+
+ os = s;
+ while(n-- > 0 && (*s++ = *t++) != 0)
+ ;
+ while(n-- > 0)
+ *s++ = 0;
+ return os;
}
// Like strncpy but guaranteed to NUL-terminate.