PMSTRNCAT(3)
β¨ pmstrncat β bestie edition π
okay so real talk, this is the pmstrncat page from the PCP (Performance Co-Pilot) library functions manual, and it's literally about safe string concatenation. no cap. let's get into it π«Ά
πΈ NAME πΈ
pmstrncat β safe string concatenation, fr fr π
π C SYNOPSIS π
#include <pcp/pmapi.h>
int pmstrncat(char *dest, size_t destlen, char *src);
cc ... -lpcp
β¨ DESCRIPTION β¨
so pmstrncat is a safe string concatenation routine whose semantics are similar to strncat(3). similar. not the same. bestie, they are NOT the same, and that's the whole point π
the main differences between pmstrncat and strncat(3) are, and I'm listing them all because you deserve to know:
srcmust be null-byte terminated forpmstrncatβ οΈdestlenis the length of the destination buffer (dest) forpmstrncat, not the maximum number of non-null bytes to copy fromsrcas it is forstrncat- the length argument has the same semantics for
pmstrncatandpmstrncpy(3), unlikestrncat(3)andstrncpy(3)β consistency slay π - the return value from
pmstrncatis useful (iconic behaviour, honestly) - the order of the arguments for
pmstrncathas been deliberately changed from the order of the arguments forstrncat(3)to avoid accidental misuse that a compiler can easily detect π₯
On success, pmstrncat returns 0, else -1 indicates that src is too big and the result has been truncated to ensure dest has not been overrun. so like, it protects you. it's giving bodyguard energy π‘οΈβ¨
π¦ HISTORY π¦
strncat(3) first appeared in Edition 7 AT&T Unix around 1979. and ngl, it was specifically crafted to construct file pathnames (which needed to be null-byte terminated) from component names from on-disk directory entries that were of a fixed maximum size and may have zero, one or more trailing null-bytes. very niche. very 1979. π
the subsequent attempts to use strncat(3) for more general string concatenation operations have been fraught with abuse and security issues π and pmstrncat is an attempt to address these problems. it's the glow-up the function always needed.
π SEE ALSO π
PMAPI(3), pmstrncpy(3), strncat(3) and strncpy(3) π«Ά
and that's the whole page, bestie!! brought to you by Performance Co-Pilot (PCP) β mwah, go write some safe concatenation πβ¨π
π¦ where this page comes from
- arch rolling: pcp 7.2.2-2 Β· GPL-2.0-or-later AND LGPL-2.1-or-later AND CC-BY-3.0
- centos-stream 10: pcp-doc 7.1.5-6.el10 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 43: pcp-doc 7.0.1-1.fc43 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 43: pcp-doc 7.2.1-1.fc43
- fedora 43: pcp-doc 7.2.2-1.fc43
- fedora 43: pcp-doc 7.2.2-2.fc43 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 44: pcp-doc 7.1.0-6.fc44 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 44: pcp-doc 7.2.1-1.fc44
- fedora 44: pcp-doc 7.2.2-1.fc44
- fedora 44: pcp-doc 7.2.2-2.fc44 Β· GPL-2.0-or-later AND CC-BY-3.0
- ubuntu resolute: libpcp4-dev 7.1.1-1
- ubuntu stonking: libpcp4-dev 7.2.1-2build1
- Copyright (c) 2021 Ken McDonell
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms