2001-02-02 17:54:47 +00:00
|
|
|
#include "str.h"
|
|
|
|
|
2006-11-07 17:56:05 +00:00
|
|
|
size_t str_copy(char *out,const char *in) {
|
2001-02-02 17:54:47 +00:00
|
|
|
register char* s=out;
|
|
|
|
register const char* t=in;
|
|
|
|
for (;;) {
|
2016-04-27 14:07:49 +00:00
|
|
|
if (!(*s=*t)) break;
|
|
|
|
++s; ++t;
|
|
|
|
if (!(*s=*t)) break;
|
|
|
|
++s; ++t;
|
|
|
|
if (!(*s=*t)) break;
|
|
|
|
++s; ++t;
|
|
|
|
if (!(*s=*t)) break;
|
|
|
|
++s; ++t;
|
2001-02-02 17:54:47 +00:00
|
|
|
}
|
2014-03-14 02:15:38 +00:00
|
|
|
return (size_t)(s-out);
|
2001-02-02 17:54:47 +00:00
|
|
|
}
|
2018-09-30 19:27:16 +00:00
|
|
|
|
|
|
|
#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
|