mention that the str_copy return value does not include the \0

add unit test
master
leitner 6 years ago
parent 2d78cb8406
commit 8714ae112d

@ -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 str_copy copies the leading bytes of \fIin\fR to \fIout\fR up to and
including the first occurrance of \\0. 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" .SH "SEE ALSO"
strlen(3) strlen(3)

@ -15,3 +15,13 @@ size_t str_copy(char *out,const char *in) {
} }
return (size_t)(s-out); 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

Loading…
Cancel
Save