红联Linux门户
Linux帮助

linux 2.6.10中strncpy函数修改意见

发布时间:2006-12-03 00:41:46来源:红联作者:Dream
/**
* strncpy - Copy a length-limited, %NUL-terminated string
* @dest: Where to copy the string to
* @src: Where to copy the string from
* @count: The maximum number of bytes to copy
*
* The result is not %NUL-terminated if the source exceeds
* @count bytes.
*/
char * strncpy(char * dest,const char *src,size_t count)
{
char *tmp = dest;
while (count) {
if ((*tmp = *src) != 0) src++;
tmp++;
count--;
}
return dest;
}

linux 2.6.10中strncpy函数好像不妥当,如果改成

while (count)
{
if ((*tmp = *src) != 0)
{
src++;
tmp++;
count--;
}
else
{
break;
}
}

好像更高效些
文章评论

共有 1 条评论

  1. niuqian 于 2006-12-04 21:03:13发表:

    你的返回呢