PMSTRNCAT(3)

πŸ“¦
version 7.2.2 Β· 3 versions
, in arch rolling, centos-stream 10, fedora 43, fedora 44, ubuntu resolute, ubuntu stonking

✨ 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:

  • src must be null-byte terminated for pmstrncat ⚠️
  • destlen is the length of the destination buffer (dest) for pmstrncat, not the maximum number of non-null bytes to copy from src as it is for strncat
  • the length argument has the same semantics for pmstrncat and pmstrncpy(3), unlike strncat(3) and strncpy(3) β€” consistency slay πŸ’–
  • the return value from pmstrncat is useful (iconic behaviour, honestly)
  • the order of the arguments for pmstrncat has been deliberately changed from the order of the arguments for strncat(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