GETTTYENT(3)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1

πŸ’– 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 that init(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 by ty_getty on this entry) βœ…
    • TTY_SECURE β€” allow users with a uid of 0 to login on this terminal πŸ”
    • TTY_DIALUP β€” identifies a tty as a dialin line. if this flag is set, then isdialuptty() will return a non-zero value πŸ“ž
    • TTY_NETWORK β€” identifies a tty used for network connections. if this flag is set, then isnettty() 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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms