strcat 函数 man 手册翻译

STRCAT(3)                        Linux Programmer's Manual                        STRCAT(3)

NAME
       strcat, strncat - concatenate two strings		//连接两个字符串

SYNOPSIS
       #include <string.h>

       char *strcat(char *dest, const char *src);

       char *strncat(char *dest, const char *src, size_t n);

DESCRIPTION
       The strcat() function appends the src string to the dest string, overwriting the terminating null byte ('\0') at the end of dest, and then adds a terminating null byte. The strings may not overlap, and the dest string must have enough space for the result. If dest is not large enough, program behavior is unpredictable; buffer overruns are a favorite avenue for attacking secure programs.
	   /*strcat() 函数将 src 字符串附加到 dest 后面,同时将 dest 字符串末尾的结束符 '\0' 覆盖,然后在整个字符的最后添加一个结束符 '\0'。字符串可能不会重叠,但是 dest 指向的空间必须有足够的空间能容纳结果。如果 dest 不是足够大,那么程序行为是不可预知的,缓存区溢出是攻击安全程序的最佳途径。*/

       The strncat() function is similar, except that

       *  it will use at most n bytes from src; and

       *  src does not need to be null-terminated if it contains n or more bytes.
	   /*strncat() 函数和 strcat() 函数很类似,只是最多使用到 src 字符串 n 个字节,同时如果 src 的包含 n 个或更多字节时, src 不需要有结束符。*/

       As with strcat(), the resulting string in dest is always null-terminated.
	   /*和 strcat 函数一样,dest 字符串结尾一定有结束符 '\0'。*/

       If src contains n or more bytes, strncat() writes n+1 bytes to dest (n from src plus the terminating  null byte). Therefore, the size of dest must be at least strlen(dest)+n+1.
	   /*如果 src 包含 n 个或更多字节时,strncat 函数会向 dest 写入 n+1 个字节。因此,dest 的大小至少为 strlen(dest)+n+1。*/

       A simple implementation of strncat() might be:
	   /*strncat() 函数的简单实现如下:*/

           char *
           strncat(char *dest, const char *src, size_t n)
           {
               size_t dest_len = strlen(dest);
               size_t i;

               for (i = 0 ; i < n && src[i] != '\0' ; i++)
                   dest[dest_len + i] = src[i];
               dest[dest_len + i] = '\0';

               return dest;
           }

RETURN VALUE
       The strcat() and strncat() functions return a pointer to the resulting string dest.
	   /*strcat() 和 strncat() 函数的返回值是一个指向最终 dest 字符串的指针。*/

ATTRIBUTES
       For an explanation of the terms used in this section, see attributes(7).

       ┌────────────────────┬───────────────┬─────────┐
       │Interface           │ Attribute     │ Value   │
       ├────────────────────┼───────────────┼─────────┤
       │strcat(), strncat() │ Thread safety │ MT-Safe │
       └────────────────────┴───────────────┴─────────┘
CONFORMING TO
       POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD.

NOTES
       Some systems (the BSDs, Solaris, and others) provide the following function:
	   /*有些系统(the BSDs, Solaris, and others)还提供了以下函数:*/

           size_t strlcat(char *dest, const char *src, size_t size);

       This function appends the null-terminated string src to the string dest, copying at most size-strlen(dest)-1 from src, and adds a terminating null byte to the result, unless size is less than strlen(dest). This function fixes the buffer overrun problem of strcat(), but the caller must still handle the possibility of data loss if size is too small. The function returns the length of the string strlcat() tried to create; if the return value is greater than or equal to size, data loss occurred. If data loss matters, the caller must either check the arguments before the call, or test the function return value.  strlcat() is not present in glibc and is not  standardized by POSIX, but is available on Linux via the libbsd library.
	   /*该函数将以空字符结尾的字符串 src 附加到字符串 dest 后面,但是最多只会拷贝 size-strlen(dest)-1 个字节,在 dest 结尾加一个结束符 '\0',除非 size < strlen(dest)。该函数修复了strcat() 函数的缓冲区溢出问题,但是如果 size 太小的话,调用函数一定要处理好所丢失的部分。函数返回的是 strlcat 函数试图创建的字符串长度,如果返回值 >= size,那么数据一定有截断。如果丢失的数据很重要,那么调用者一定要在调用前检查参数,或者测试函数的返回值。在 glibc 中目前没有 strlcat() 函数,同时在 POSIX 中也不属于标准 C 函数,但是可以调用 libbsd 库在 Linux 上使用。*/

SEE ALSO
       bcopy(3),   memccpy(3),  memcpy(3),  strcpy(3),  string(3),  strncpy(3),  wcscat(3),
       wcsncat(3)

COLOPHON
       This page is part of release 4.04 of the Linux man-pages project.  A description  of the  project, information about reporting bugs, and the latest version of this page, can be found at http://www.kernel.org/doc/man-pages/.

GNU                                      2015-08-08                               STRCAT(3)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值