1getutent(3) Library Functions Manual getutent(3)
2
3
4
6 getutent, getutid, getutline, pututline, setutent, endutent, utmpname -
7 access utmp file entries
8
10 Standard C library (libc, -lc)
11
13 #include <utmp.h>
14
15 struct utmp *getutent(void);
16 struct utmp *getutid(const struct utmp *ut);
17 struct utmp *getutline(const struct utmp *ut);
18
19 struct utmp *pututline(const struct utmp *ut);
20
21 void setutent(void);
22 void endutent(void);
23
24 int utmpname(const char *file);
25
27 New applications should use the POSIX.1-specified "utmpx" versions of
28 these functions; see STANDARDS.
29
30 utmpname() sets the name of the utmp-format file for the other utmp
31 functions to access. If utmpname() is not used to set the filename be‐
32 fore the other functions are used, they assume _PATH_UTMP, as defined
33 in <paths.h>.
34
35 setutent() rewinds the file pointer to the beginning of the utmp file.
36 It is generally a good idea to call it before any of the other func‐
37 tions.
38
39 endutent() closes the utmp file. It should be called when the user
40 code is done accessing the file with the other functions.
41
42 getutent() reads a line from the current file position in the utmp
43 file. It returns a pointer to a structure containing the fields of the
44 line. The definition of this structure is shown in utmp(5).
45
46 getutid() searches forward from the current file position in the utmp
47 file based upon ut. If ut->ut_type is one of RUN_LVL, BOOT_TIME,
48 NEW_TIME, or OLD_TIME, getutid() will find the first entry whose
49 ut_type field matches ut->ut_type. If ut->ut_type is one of
50 INIT_PROCESS, LOGIN_PROCESS, USER_PROCESS, or DEAD_PROCESS, getutid()
51 will find the first entry whose ut_id field matches ut->ut_id.
52
53 getutline() searches forward from the current file position in the utmp
54 file. It scans entries whose ut_type is USER_PROCESS or LOGIN_PROCESS
55 and returns the first one whose ut_line field matches ut->ut_line.
56
57 pututline() writes the utmp structure ut into the utmp file. It uses
58 getutid() to search for the proper place in the file to insert the new
59 entry. If it cannot find an appropriate slot for ut, pututline() will
60 append the new entry to the end of the file.
61
63 getutent(), getutid(), and getutline() return a pointer to a struct
64 utmp on success, and NULL on failure (which includes the "record not
65 found" case). This struct utmp is allocated in static storage, and may
66 be overwritten by subsequent calls.
67
68 On success pututline() returns ut; on failure, it returns NULL.
69
70 utmpname() returns 0 if the new name was successfully stored, or -1 on
71 failure.
72
73 On failure, these functions errno set to indicate the error.
74