Browse Source

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

add unit test
master
Felix von Leitner 3 years ago
parent
commit
e0ab8984bf
  1. 2
      str/str_copy.3
  2. 10
      str/str_copy.c

2
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)

10
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

Loading…
Cancel
Save