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_SOURCE thing is real, bestie โ€” you literally have to define it before ptsname_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. buf is NULL. (heads up bestie: this error is returned only for glibc 2.25 and earlier.)
  • ENOTTY โ€” fd does not refer to a pseudoterminal master device. like, wrong file descriptor, wrong era, not your moment ๐Ÿ™ˆ
  • ERANGE โ€” ptsname_r() only. buf is 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 (see pts(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