ptsname(3)
๐ ptsname(3) โ the manual page, but make it cute ๐
okay bestie, so this is a page from the Library Functions Manual, and no cap, it's about getting the name of the slave pseudoterminal. it's giving terminal-girlie energy. let's get into it ๐ซถ
โจ NAME โจ
ptsname, ptsname_r โ get the name of the slave pseudoterminal ๐ธ
๐ LIBRARY ๐
Standard C library (libc, -lc) โ the classic, the icon, the moment ๐
๐ SYNOPSIS ๐
#include <stdlib.h>
char *ptsname(int fd);
int ptsname_r(size_t size;
int fd, char buf[size], size_t size);
๐ฆ Feature Test Macro Requirements for glibc (see feature_test_macros(7)) ๐ฆ
ptsname():
- Since glibc 2.24:
_XOPEN_SOURCE >= 500
- glibc 2.23 and earlier:
_XOPEN_SOURCE
ptsname_r():
_GNU_SOURCE
lowkey the_GNU_SOURCEthing is real, bestie โ you literally have to define it beforeptsname_r()will show up. no shade, just facts ๐
๐ DESCRIPTION ๐
so the ptsname() function literally returns the name of the slave pseudoterminal device that matches up with the master referred to by the file descriptor fd. that's it, that's the whole vibe.
and ptsname_r() is the reentrant equivalent of ptsname() โ the safe, thread-friendly sibling ๐. it returns the name of the slave pseudoterminal device as a null-terminated string, and it drops it into the buffer pointed to by buf. the size argument tells it how many bytes are actually available in buf, so likeโฆ no overflowing, periodt.
๐ฅ RETURN VALUE ๐ฅ
on success, ptsname() hands you back a pointer to a string that lives in static storage โ which means it will 100% get overwritten by subsequent calls ๐ญ. and listen: that pointer must not be freed. do not. put. it. in free(). on failure, NULL is returned, and that's your sign something went sideways.
on success, ptsname_r() returns 0. on failure, it returns an error number to indicate the error โ no errno detective work, the number is right there. slay ๐
๐ ERRORS ๐
EINVALโptsname_r()only.bufisNULL. (heads up bestie: this error is returned only for glibc 2.25 and earlier.)ENOTTYโfddoes not refer to a pseudoterminal master device. like, wrong file descriptor, wrong era, not your moment ๐ERANGEโptsname_r()only.bufis too small. your buffer said "i can't hold all this" ๐
๐ ATTRIBUTES ๐
for an explanation of the terms used in this section, see attributes(7).
ptsname()โ Thread safety:MT-Unsafe race:ptsname๐ฌ (yeah, it races โ that static storage is shared, so watch out)ptsname_r()โ Thread safety:MT-Safeโจ (this is the one you want in multithreaded code, fr fr)
๐ VERSIONS ๐
a version of ptsname_r() is documented on Tru64, HP-UX, and FreeBSD โ but plot twist ๐ซฃ: on those implementations, -1 is returned on error, with errno set to indicate the error. so the return-value contract is NOT the same everywhere. avoid using this function in portable programs. that's not me being dramatic, that's the manpage. be careful bestie ๐
โญ STANDARDS โญ
ptsname():
- POSIX.1-2008.
ptsname_r():
- POSIX.1-2024.
๐ธ HISTORY ๐ธ
ptsname():
- POSIX.1-2001. glibc 2.1.
- also,
ptsname()is part of the UNIX 98 pseudoterminal support (seepts(4)). iconic lineage honestly.
ptsname_r():
- GNU. yeah, it's a GNU original ๐ง
๐ SEE ALSO ๐
grantpt(3), posix_openpt(3), ttyname(3), unlockpt(3), pts(4), pty(7)
and that's the whole page, bestie ๐ซถ this was Linux man-pages 6.20, dated 2025-10-29, ptsname(3). go forth and name your slave pseudoterminals responsibly ๐โจ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms