From 8714ae112d0bd0f3781a29da0f15713952e73756 Mon Sep 17 00:00:00 2001 From: leitner Date: Sun, 30 Sep 2018 19:27:16 +0000 Subject: [PATCH] mention that the str_copy return value does not include the \0 add unit test --- str/str_copy.3 | 2 +- str/str_copy.c | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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 +#include + +int main() { + char buf[100]; + memset(buf,1,sizeof(buf)); assert(str_copy(buf,"foo")==3 && !memcmp(buf,"foo",4)); +} +#endif