strncat - Online Linux Manual PageSection : 3
Updated : 2023-02-05
Source : Linux man-pages 6.03
NAMEstrncat − concatenate a null-padded character sequence into a string
LIBRARYStandard C library (libc, −lc)
SYNOPSIS#include <string.h>char *strncat(char *restrict dst, const char src[restrict .sz],
size_t sz);
DESCRIPTIONThis function catenates the input character sequence contained in a null-padded fixed-width buffer, into a string at the buffer pointed to by dst. The programmer is responsible for allocating a destination buffer large enough, that is, strlen(dst) + strnlen(src, sz) + 1. An implementation of this function might be: char *
strncat(char *restrict dst, const char *restrict src, size_t sz)
{
int len;
char *p;
len = strnlen(src, sz);
p = dst + strlen(dst);
p = mempcpy(p, src, len);
*p = '\0';
return dst;
}
RETURN VALUEstrncat() returns dst.
ATTRIBUTESFor an explanation of the terms used in this section, see attributes(7). InterfaceAttributeValue strncat() Thread safetyMT-Safe
STANDARDSPOSIX.1-2001, POSIX.1-2008, C99, SVr4, 4.3BSD.
CAVEATSThe name of this function is confusing. This function has no relation to strncpy(3). If the destination buffer is not large enough, the behavior is undefined. See _FORTIFY_SOURCE in feature_test_macros(7).
BUGSThis function can be very inefficient. Read about Shlemiel the painter .
EXAMPLES #include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define nitems(arr) (sizeof((arr)) / sizeof((arr)[0]))
int
main(void)
{
size_t maxsize;
// Null-padded fixed-width character sequences
char pre[4] = "pre.";
char new_post[50] = ".foo.bar";
// Strings
char post[] = ".post";
char src[] = "some_long_body.post";
char *dest;
maxsize = nitems(pre) + strlen(src) − strlen(post) +
nitems(new_post) + 1;
dest = malloc(sizeof(*dest) * maxsize);
if (dest == NULL)
err(EXIT_FAILURE, "malloc()");
dest[0] = '\0'; // There's no 'cpy' function to this 'cat'.
strncat(dest, pre, nitems(pre));
strncat(dest, src, strlen(src) − strlen(post));
strncat(dest, new_post, nitems(new_post));
puts(dest); // "pre.some_long_body.foo.bar"
free(dest);
exit(EXIT_SUCCESS);
}
SEE ALSOstring(3), string_copying(3) 0
Johanes Gumabo
Data Size : 10,996 byte
man-strncat.3Build : 2024-12-05, 20:55 :
Visitor Screen : x
Visitor Counter ( page / site ) : 4 / 239,085
Visitor ID : :
Visitor IP : 3.142.195.79 :
Visitor Provider : AMAZON-02 :
Provider Position ( lat x lon ) : 39.962500 x -83.006100 : x
Provider Accuracy Radius ( km ) : 1000 :
Provider City : Columbus :
Provider Province : Ohio , : ,
Provider Country : United States :
Provider Continent : North America :
Visitor Recorder : Version :
Visitor Recorder : Library :
Online Linux Manual Page : Version : Online Linux Manual Page - Fedora.40 - march=x86-64 - mtune=generic - 24.12.05
Online Linux Manual Page : Library : lib_c - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Online Linux Manual Page : Library : lib_m - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Data Base : Version : Online Linux Manual Page Database - 24.04.13 - march=x86-64 - mtune=generic - fedora-38
Data Base : Library : lib_c - 23.02.07 - march=x86-64 - mtune=generic - fedora.36
Very long time ago, I have the best tutor, Wenzel Svojanovsky . If someone knows the email address of Wenzel Svojanovsky , please send an email to johanes_gumabo@yahoo.co.id .
If error, please print screen and send to johanes_gumabo@yahoo.co.id
Under development. Support me via PayPal.