#include <stdio.h>
#include <stdlib.h>
//字符串拷贝.把from所指字符串添加到to指向的空间并覆盖to原来所有内容.
char * strlcpy(char * to, const char * from,unsigned int size_t)
{
char * dest;
int i,lenth=0;
if(NULL==to ||NULL==from || size_t==0)return NULL;
dest = to;
lenth=strlen(from);
//lenth=lenth>size_t?size_t:lenth;
lenth=lenth<size_t?lenth:size_t-1;
//memcpy(to,from,lenth);
for (i=0; ((*to = *from) != '\0')&&i<lenth; ++from, ++to,i++);
*to='\0';
return dest;
}
int main (void)
{
char cbuf[]={"abcdefghijklmnopqrstuvwxyz!"};
char dbuf[]={"1234567890!"};
strlcpy(cbuf,dbuf,sizeof(cbuf));
printf ("cbuf= %s\n",cbuf);
printf ("dbuf= %s\n",dbuf);
return 0;
}