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 iscrw--w----if you read it like a character device
β οΈ real talk though: the behavior ofgrantpt()is unspecified if a signal handler is installed to catchSIGCHLDsignals. 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
-1and setserrnoto tell you exactly why she's upset
π ERRORS π
EACCESβ the corresponding slave pseudoterminal could not be accessed. she was locked out, fr fr.EBADFβ thefdargument is not a valid open file descriptor. bestie that's not a real door.EINVALβ thefdargument 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