GETTTYENT(3)
π GETTTYENT(3) β ttys(5) file routines π
okay so bestie, we're deep in getttyent(3) territory today β that's the manual page, third section of the library manuals, and it lives in the Library Functions Manual β¨. This is the whole getttyent, getttynam, setttyent, endttyent, isdialuptty, isnettty situation and honestly it's giving "low-level system girlie" and I'm obsessed. Let's get into it π
πΈ NAME πΈ
getttyent, getttynam, setttyent, endttyent, isdialuptty, isnettty β the ttys(5) file routines, periodt π
π LIBRARY π
Standard C Library (libc, -lc) β the classic, no cap π«Ά
β¨ SYNOPSIS β¨
#include <ttyent.h>
struct ttyent *
getttyent(void);
struct ttyent *
getttynam(const char *name);
int
setttyent(void);
int
endttyent(void);
int
isdialuptty(const char *name);
int
isnettty(const char *name);
π¦ DESCRIPTION π¦
so getttyent() and getttynam() both return a pointer to an object β and that object has this structure right here, containing the broken-out fields of a line from the tty description file. icon behavior honestly π
struct ttyent {
char *ty_name; /* terminal device name */
char *ty_getty; /* command to execute, usually getty */
char *ty_type; /* terminal type for termcap */
#define TTY_ON 0x01 /* enable logins (start ty_getty program) */
#define TTY_SECURE 0x02 /* allow uid of 0 to login */
#define TTY_DIALUP 0x04 /* is a dialup tty */
#define TTY_NETWORK 0x08 /* is a network tty */
#define TTY_IFEXISTS 0x10 /* configured as "onifexists" */
#define TTY_IFCONSOLE 0x20 /* configured as "onifconsole" */
int ty_status; /* status flags */
char *ty_window; /* command to start up window manager */
char *ty_comment; /* comment field */
char *ty_group; /* tty group name */
};
and here's the field-by-field breakdown, bestie, buckle up π
ty_nameβ the name of the character-special file. that's it, that's the vibe.ty_gettyβ the name of the command thatinit(8)invokes to initialize tty line characteristics π₯ty_typeβ the name of the default terminal type connected to this tty line β¨ty_statusβ a mask of bit fields that says which actions are allowed on this tty line. the possible flags are:TTY_ONβ enables logins (i.e.,init(8)will start the command referenced byty_gettyon this entry) βTTY_SECUREβ allow users with a uid of0to login on this terminal πTTY_DIALUPβ identifies a tty as a dialin line. if this flag is set, thenisdialuptty()will return a non-zero value πTTY_NETWORKβ identifies a tty used for network connections. if this flag is set, thenisnettty()will return a non-zero value πTTY_IFEXISTSβ identifies a tty that does not necessarily exist π»TTY_IFCONSOLEβ identifies a tty that might be a system console π₯οΈ
ty_windowβ the command to execute for a window system associated with the line πͺty_groupβ a group name to which the tty belongs. if no group is specified in the ttys description file, then the tty is placed in an anonymous group called"none"πty_commentβ any trailing comment field, with any leading hash marks (`#') or whitespace removed π¬
if any of the fields pointing to character strings are unspecified, they come back as null pointers. and ty_status will be zero if no flag values are specified. zero thoughts, head empty, literally π
see ttys(5) for a more complete discussion of the meaning and usage of the fields β that's the lore drop if you want the full backstory, fr fr π
okay now the function lore:
getttyent()reads the next line from the ttys file, opening the file if necessary πsetttyent()rewinds the file if it's open, or opens the file if it's unopened πendttyent()closes any open files πͺgetttynam()searches from the beginning of the file until a matching name is found (or until EOF is encountered) π
π RETURN VALUES π
getttyent() and getttynam() return a null pointer on EOF or error π
setttyent() and endttyent() return 0 on failure and 1 on success β
isdialuptty() and isnettty() return non-zero if the dialup or network flag is set for the tty entry relating to the tty named by the argument, and zero otherwise π
π FILES π
/etc/ttys
π SEE ALSO π
login(1), gettytab(5), termcap(5), ttys(5), getty(8), init(8) β the whole friend group, iykyk π
π°οΈ HISTORY π°οΈ
getttyent(), getttynam(), setttyent(), and endttyent() appeared in 4.3BSD. vintage but make it iconic π
π BUGS π
these functions use static data storage β so if you need that data for future use, you gotta copy it before any subsequent calls overwrite it. like, it WILL get overwritten bestie, do not test me on this ππ
so yeah, that's the whole page πΈ this one's from Debian, dated November 17, 1996 β ancient but still slaying, mwah ππ«Ά
π¦ where this page comes from
- freebsd 15.1: base 15.1
- Copyright (c) 1989, 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms