strncpy

strncpystrncpy
  1. The function strncpy ( 3 ) can also be used to copy only a part of the source string into the destination .

    函数strncpy(3)还可以用来仅把源字符串的一部分复制到目标中。

  2. The example has an implementation of strncpy , where the source and destination strings are checked first , respectively , to be readable and writable .

    这个例子有一个strncpy工具,在这个例子中源和目的字符串首先被分别核查,使其能够被读取和写入。

  3. Both strncpy ( 3 ) and strncat ( 3 ) require that you give the amount of space left , not the total size of the buffer .

    strncpy(3)和strncat(3)都要求您给出剩余的空间,而不是给出缓冲区的总大小。

  4. The correct way to do this would be to use the strncpy () function instead of strcpy (), and give the maximum number of bytes to copy as BUFSIZ-1 .

    复制的正确方法是用strncpy()函数代替strcpy(),并将要复制的最大字节数定为BUFSIZ-1。

  5. The function strncpy ( 3 ) also doesn 't NUL-terminate its destination if the source string is at least as long as the destination ; this can cause havoc later .

    如果源字符串至少和目标一样长,那么函数strncpy(3)还不会使用NUL来结束字符串;这可能会在以后导致严重破坏。

  6. This means that switching from strcpy ( 3 ) to strncpy ( 3 ) can reduce performance & often not a serious problem on today 's computers , but it can still be a nuisance .

    这意味着从strcpy(3)切换到strncpy(3)会降低性能――这在如今的计算机上通常不是一个严重的问题,但它仍然是有害的。

  7. Memcpy () joins the ranks of other popular functions like strcpy , strncpy , strcat , strncat which were banned due to their security vulnerability through buffer overruns .

    memcpy()加入到strcpy,strncpy,strcat,strncat等常用函数的队伍中,都是由于可通过缓存溢出进行安全攻击而被禁用。

  8. In theory , strncpy ( 3 ) is the safe replacement for strcpy ( 3 ), but strncpy ( 3 ) also fills the entire destination with NULs once the end of the source string has been met .

    从理论上讲,strncpy(3)是strcpy(3)的安全替代者,但是strncpy(3)还会在源字符串结束时使用NUL来填充整个目标空间。

  9. Then , we 'll discuss two examples of the static approach ( standard C strncpy / strncat and OpenBSD 's strlcpy / strlcat ), followed by two examples of the dynamic approach ( SafeStr and C + + 's std : : string ) .

    然后,我们将讨论静态方法的两个例子(标准Cstrncpy/strncat和OpenBSD的strlcpy/strlcat),接着讨论动态方法的两个例子(SafeStr和C++的std::string)。