grantpt(3)

✨ grantpt(3) β€” bestie edition ✨

okay so this is the manual page for grantpt(3), which lives in the Library Functions Manual (it's a libc girlie, and the library is the Standard C library, libc, -lc). she's here to hand over the keys to your pty's little sibling. let's get into it πŸ’…


πŸŽ€ NAME πŸŽ€

grantpt β€” grant access to the slave pseudoterminal

no cap, that's the whole job description. she gives the slave side of the pty its permissions, periodt.


πŸ“š LIBRARY πŸ“š

Standard C library, a.k.a. libc, link with -lc. classic.


🌸 SYNOPSIS 🌸

okay here's the ritual you gotta perform before you can even call her:

#define _XOPEN_SOURCE
#include <stdlib.h>

int grantpt(int fd);

πŸ¦‹ Feature Test Macro Requirements for glibc πŸ¦‹

(peep feature_test_macros(7) if you wanna know what those even are)

grantpt():

  • Since glibc 2.24:
    • _XOPEN_SOURCE >= 500
  • glibc 2.23 and earlier:
    • _XOPEN_SOURCE

so if you're on a newer glibc you gotta bring a little more to the table. the audacity honestly. but we deal. πŸ’€


πŸ’– DESCRIPTION πŸ’–

so here's the tea, bestie. grantpt() changes the mode and owner of the slave pseudoterminal device that corresponds to the master pseudoterminal referred to by the file descriptor fd.

let's break down the glow-up she performs on that slave:

  • the user ID of the slave is set to the real UID of the calling process (yes, real UID, not effective β€” she's not about that effective life)
  • the group ID is set to an unspecified value (e.g., tty β€” so like, don't go counting on a specific one, k?)
  • the mode of the slave is set to 0620, which is crw--w---- if you read it like a character device
⚠️ real talk though: the behavior of grantpt() is unspecified if a signal handler is installed to catch SIGCHLD signals. so like… don't do that. she will simply not know what to do with herself. 😭

⭐ RETURN VALUE ⭐

  • when she slays (success): returns 0
  • when she does not slay (failure): returns -1 and sets errno to tell you exactly why she's upset

πŸ’… ERRORS πŸ’…

  • EACCES β€” the corresponding slave pseudoterminal could not be accessed. she was locked out, fr fr.
  • EBADF β€” the fd argument is not a valid open file descriptor. bestie that's not a real door.
  • EINVAL β€” the fd argument is valid, but it's not associated with a master pseudoterminal. wrong vibes, wrong device. πŸ™ˆ

🫢 ATTRIBUTES 🫢

for what all these terms even mean, go peek at attributes(7) β€” she's the dictionary for this section.

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

translation: she's safe to call from multiple threads, as long as you're not being weird about locale. team player energy. πŸ‘‘


🌈 STANDARDS 🌈

POSIX.1-2008. certified, standardized, iconic.


πŸ‘‘ HISTORY πŸ‘‘

she's been around a minute:

  • glibc 2.1
  • POSIX.1-2001

this whole thing is part of the UNIX 98 pseudoterminal support β€” check pts(4) for the lore.

now here's the messy backstory, and it's giving drama πŸ“: historical systems implemented this function using a set-user-ID helper binary called "pt_chown". glibc on Linux before glibc 2.33 could do that too, in order to support configurations with only BSD pseudoterminals β€” but that support has been removed, so don't come looking for it.

on modern systems, this function is either:

  • a no-op β€” with permissions configured on pty allocation, which is the case on Linux β€” or
  • an ioctl(2)

so basically she either does nothing (gracefully, queenfully) or she's out here making an ioctl call. either way, she's got it handled. ✨


πŸ”₯ SEE ALSO πŸ”₯

open(2), posix_openpt(3), ptsname(3), unlockpt(3), pts(4), pty(7)

go read those if you want the full pty cinematic universe. iykyk 🌸


and that's the whole page, bestie!! this was Linux man-pages 6.20, dated 2025-09-21 β€” love her, read her, cite her. mwah πŸ’– 🧚

πŸ“¦ 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