1GETUTENT(3) Library functions GETUTENT(3)
2
3
4
6 getutent, getutid, getutline, pututline, setutent, endutent, utmpname -
7 access utmp file entries
8
10 #include <utmp.h>
11
12 struct utmp *getutent(void);
13 struct utmp *getutid(struct utmp *ut);
14 struct utmp *getutline(struct utmp *ut);
15
16 struct utmp *pututline(struct utmp *ut);
17
18 void setutent(void);
19 void endutent(void);
20
21 void utmpname(const char *file);
22
24 utmpname() sets the name of the utmp-format file for the other utmp
25 functions to access. If utmpname() is not used to set the filename
26 before the other functions are used, they assume _PATH_UTMP, as defined
27 in <paths.h>.
28
29 setutent() rewinds the file pointer to the beginning of the utmp file.
30 It is generally a Good Idea to call it before any of the other func‐
31 tions.
32
33 endutent() closes the utmp file. It should be called when the user
34 code is done accessing the file with the other functions.
35
36 getutent() reads a line from the current file position in the utmp
37 file. It returns a pointer to a structure containing the fields of the
38 line.
39
40 getutid() searches forward from the current file position in the utmp
41 file based upon ut. If ut->ut_type is one of RUN_LVL, BOOT_TIME,
42 NEW_TIME, or OLD_TIME, getutid() will find the first entry whose
43 ut_type field matches ut->ut_type. If ut->ut_type is one of
44 INIT_PROCESS, LOGIN_PROCESS, USER_PROCESS, or DEAD_PROCESS, getutid()
45 will find the first entry whose ut_id field matches ut->ut_id.
46
47 getutline() searches forward from the current file position in the utmp
48 file. It scans entries whose ut_type is USER_PROCESS or LOGIN_PROCESS
49 and returns the first one whose ut_line field matches ut->ut_line.
50
51 pututline() writes the utmp structure ut into the utmp file. It uses
52 getutid() to search for the proper place in the file to insert the new
53 entry. If it cannot find an appropriate slot for ut, pututline() will
54 append the new entry to the end of the file.
55
57 getutent(), getutid(), getutline() and pututline() return a pointer to
58 a struct utmp on success, and NULL on failure. This struct utmp is
59 allocated in static storage, and may be overwritten by subsequent
60 calls.
61
63 These above functions are not thread-safe. Glibc adds reentrant ver‐
64 sions
65
66 #define _GNU_SOURCE /* or _SVID_SOURCE or _BSD_SOURCE */
67 #include <utmp.h>
68
69 int getutent_r(struct utmp *ubuf, struct utmp **ubufp);
70
71 int getutid_r(struct utmp *ut,
72 struct utmp *ubuf, struct utmp **ubufp);
73
74 int getutline_r(struct utmp *ut,
75 struct utmp *ubuf, struct utmp **ubufp);
76
77 These functions are GNU extensions, analogs of the functions of the
78 same name without the _r suffix. The ubuf parameter gives these func‐
79 tions a place to store their result. On success