strcpy strncpy strlcpy

来源:互联网 发布:淘宝怎么没有人工服务 编辑:程序博客网 时间:2024/05/21 10:38

1. strcpy  do not check the length of buffer that would be filled.  it can cause buffer overflow.

 

2. strncpy do not fill '/0'  at the end of the target string. you should do it manual.

 

  it's standard method is as follows:

 

   strncpy(path, str, sizeof(path)-1);

   path[sizeof(path)-1] = 0;

 

 

 

3. strlcpy

 

   strlcpy(dest, src, sizeof(dest));

 

   the third parameter of  the function is the sizeof source string. you need not to fill the '/0' at the end of the string.

 

but it can be used only in linux.

原创粉丝点击