summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix von Leitner <felix-libowfat@fefe.de>2018-09-30 19:27:16 +0000
committerFelix von Leitner <felix-libowfat@fefe.de>2018-09-30 19:27:16 +0000
commite0ab8984bfdf4330dc4272dcb9a596af5a154adb (patch)
treeea10486288c9825a3ce86cd6ba3703bdd2d8291e
parent133aa01439c80094aca30e3ba76042e8aa3eff99 (diff)
downloadlibowfat-e0ab8984bfdf4330dc4272dcb9a596af5a154adb.tar.gz
libowfat-e0ab8984bfdf4330dc4272dcb9a596af5a154adb.zip
mention that the str_copy return value does not include the \0
add unit test
-rw-r--r--str/str_copy.32
-rw-r--r--str/str_copy.c10
2 files changed, 11 insertions, 1 deletions
diff --git a/str/str_copy.3 b/str/str_copy.3
index 89e618a..c014e38 100644
--- a/str/str_copy.3
+++ b/str/str_copy.3
@@ -9,6 +9,6 @@ size_t \fBstr_copy\fP(char* \fIout\fR,const char* \fIin\fR);
str_copy copies the leading bytes of \fIin\fR to \fIout\fR up to and
including the first occurrance of \\0.
-str_copy returns the number of bytes copied.
+str_copy returns the number of bytes copied (not including the \\0).
.SH "SEE ALSO"
strlen(3)
diff --git a/str/str_copy.c b/str/str_copy.c
index 9bca180..89f864e 100644
--- a/str/str_copy.c
+++ b/str/str_copy.c
@@ -15,3 +15,13 @@ size_t str_copy(char *out,const char *in) {
}
return (size_t)(s-out);
}
+
+#ifdef UNITTEST
+#include <assert.h>
+#include <string.h>
+
+int main() {
+ char buf[100];
+ memset(buf,1,sizeof(buf)); assert(str_copy(buf,"foo")==3 && !memcmp(buf,"foo",4));
+}
+#endif