Search for an entry in the user-information file
#include <utmp.h> struct utmp * getutid( struct utmp * id );
- A pointer to a utmp structure that you want to find in the user-information file.
Use the -l c option to qcc to link against this library. This library is usually included automatically.
This function is in libc.a, but not in libc.so (in order to save space).
The getutid() function searches forward from the current point in the utmp file until it finds a matching entry:
- If id->ut_type is one of RUN_LVL, BOOT_TIME, OLD_TIME, or NEW_TIME, the function looks for an entry with the same ut_type.
- If id->ut_type is INIT_PROCESS, LOGIN_PROCESS, USER_PROCESS, or DEAD_PROCESS, getutid() looks for the first entry entry with the same ut_type and a ut_id field that matches id->ut_id.
If getutid() reaches the end of the file without finding a match, the search fails.
A pointer to the utmp structure for the matching entry, or NULL if it couldn't be found.
- Specifies the user information file.
The most current entry is saved in a static structure. Copy it before making further accesses.
On each call to either getutid() or getutline(), the routine examines the static structure before performing more I/O. If the contents of the static structure match what it's searching for, the function looks no further. For this reason, to use getutline() to search for multiple occurrences, zero out the static area after each success, or getutline() will return the same structure over and over again.
There's one exception to the rule about emptying the structure before further reads are done: the implicit read done by pututline() (if it finds that it isn't already at the correct place in the file) doesn't hurt the contents of the static structure returned by the getutent(), getutid() or getutline() routines, if the user has just modified those contents and passed the pointer back to pututline().
These routines use buffered standard I/O for input, but pututline() uses an unbuffered nonstandard write to avoid race conditions between processes trying to modify the utmp and wtmp files.
Last modified: 2014-06-24