Manpage of STRCAT

STRCAT

Section: Linux Programmer's Manual (3)
Updated: 2015-08-08
Index
 

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 srcstring to the deststring, overwriting the terminating null byte (aq\0aq) at the end of dest, and then adds a terminating null byte. The strings may not overlap, and the deststring must have enough space for the result. If destis not large enough, program behavior is unpredictable; buffer overruns are a favorite avenue for attacking secure programs.

The strncat() function is similar, except that

*
it will use at most nbytes from src; and
*
srcdoes not need to be null-terminated if it contains nor more bytes.

As with strcat(), the resulting string in destis always null-terminated.

If srccontains nor more bytes, strncat() writes n+1bytes to dest(nfrom srcplus the terminating null byte). Therefore, the size of destmust be at least strlen(dest)+n+1.

A simple implementation of strncat() might be:

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] != aq\0aq ; i++)
        dest[dest_len + i] = src[i];
    dest[dest_len + i] = aq\0aq;

    return dest;
}
 

RETURN VALUE

The strcat() and strncat() functions return a pointer to the resulting string dest.  

ATTRIBUTES

For an explanation of the terms used in this section, see attributes(7).
InterfaceAttributeValue
strcat(), strncat() Thread safetyMT-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:


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

This function appends the null-terminated string srcto the string dest, copying at most size-strlen(dest)-1from src, and adds a terminating null byte to the result, unlesssizeis 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 sizeis 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 musteither 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 libbsdlibrary.  

SEE ALSO

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


 

Index

NAME
SYNOPSIS
DESCRIPTION
RETURN VALUE
ATTRIBUTES
CONFORMING TO
NOTES
SEE ALSO

This document was created by man2html, using the manual pages.
Time: 22:28:01 GMT, June 20, 2016