getpt(3)

✨ getpt β€” open a new pseudoterminal master ✨

okay bestie, we're in the library functions manual (getpt(3)) and this one is short but it's got LORE, so sit with me πŸ’…


🌸 NAME 🌸

getpt β€” open a new pseudoterminal master

like, it gets you a pty. that's the whole job. that's the girlbossery.


πŸ“š LIBRARY πŸ“š

Standard C library (libc, -lc)


πŸŽ€ SYNOPSIS πŸŽ€

#define _GNU_SOURCE             /* See feature_test_macros(7) */
#include <stdlib.h>

int getpt(void);
heads up: that #define _GNU_SOURCE is not optional, bestie. no define, no function. see feature_test_macros(7) for the receipts.

πŸ¦‹ DESCRIPTION πŸ¦‹

so getpt() opens a brand new pseudoterminal device and hands you back a file descriptor that refers to that device. that's it, that's the function 🫢

it is equivalent to opening the pseudoterminal multiplexer device like this:

open("/dev/ptmx", O_RDWR);

on Linux systems β€” but here's the plot twist β€” the pseudoterminal multiplexer device is located elsewhere on some systems that use the GNU C library. so like, don't be out here hardcoding assumptions, iykyk 🧚


πŸ’– RETURN VALUE πŸ’–

  • on a good day? getpt() returns an open file descriptor. slay. ✨
  • on a bad day? it returns -1 and sets errno to tell you what went wrong. not slay, but at least it's honest πŸ’€

😭 ERRORS 😭

getpt() can fail with various errors described in open(2). go read that one, it's the whole buffet.


πŸ‘‘ ATTRIBUTES πŸ‘‘

for an explanation of the terms used in this section, see attributes(7).

  • Interface: getpt()
  • Attribute: Thread safety
  • Value: MT-Safe

translation: it's thread safe, bestie, go wild (responsibly)


⭐ VERSIONS ⭐

use posix_openpt(3) instead.

fr fr. this one's giving deprecated energy. getpt() is lowkey the older sibling and posix_openpt(3) is the one that ate. πŸ’…

🌈 STANDARDS 🌈

GNU.


πŸ“ HISTORY πŸ“

glibc 2.1.

so it's been around a minute. respect the elders 🫑


πŸ’œ SEE ALSO πŸ’œ


and that's the page, bestie!! πŸŽ€ this was pulled straight from Linux man-pages 6.20, dated 2025-12-26, and you just read getpt(3). go forth and open your 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