HP-UX Reference (11i v1 00/12) - 3 Library Functions A-M (vol 6)
__________________________________________________________________________________________________________________________________________________________________________________________________
__________________________________________________________________________________________________________________________________________________________________________________________________
STANDARD Printed by: Nora Chuang [nchuang] STANDARD
/build/1111/BRICK/man3/!!!intro.3c
________________________________________________________________
___ ___
g
getut(3C) getut(3C)
LOGIN_PROCESS, USER_PROCESS, or DEAD_PROCESS, getutid() returns
a pointer to the first entry whose type is one of these four, and whose ut_id field
matches id−>ut_id. If end-of-file is reached without a match, getutid() fails.
getutline() Searches forward from the current point in the utmp file until it finds an entry of type
LOGIN_PROCESS or USER_PROCESS that also has a ut_line string matching
the line−>ut_line string. If end-of-file is reached without a match, getutline()
fails.
pututline() Writes out the supplied utmp structure into the utmp file, translates the supplied
utmp structure int a utmpx structure and writes it to a utmpx file. pututline()
uses getutid() to search forward for the proper location if it is not already there.
It is normally expected that the application program has already searched for the
proper entry by using one of the getut() routines before calling pututline() .
If the search as already been made, pututline() does not repeat it. If putut-
line()
does not find a matching slot for the new entry, it adds a new entry to the
end of the file.
_pututline() Performs the same actions as pututline() , except that it returns a value useful
for error checking.
setutent() Resets the input stream to the beginning of the file. This should be done before each
search for a new entry if it is desired that the entire file be examined.
endutent() Closes the currently open file.
utmpname() Allows the user to change the name of the file being examined from /etc/utmp and
/etc/utmpx to any other file(s). In this case, the name provided to utmpname
will be used for the utmp functions. An "x" will be appended to this name, and will be
used by the getutx functions. The one exception to this are the putut(x) functions as
they access both files in an attempt to keep the utmp and utmpx files in sync. The
other file(s) are usually
/var/adm/wtmp
and /var/adm/wtmpx. If the file(s) do
not exist, its absence is not discovered until the first subsequent attempt to reference
the file.
utmpname() does not open the file — it merely closes the old file if it is
currently open, and saves the new file name.
The most current entry is saved in a static structure. Multiple accesses require that the structure be copied
before further accesses are made. During each call to either getutid() or getutline() , the static
structure is examined before performing more I/O. If the contents of the static structure match what the
routine is searching for, no additional searching is done. Therefore, if using getutline() to search for
multiple occurrences, it is necessary to zero out the static structure after each success; otherwise getut-
line()
simply returns the same pointer over and over again. There is one exception to the rule about
removing the structure before a new read: The implicit read done by pututline() (if it finds that it is
not already at the correct place in the file) does not alter the contents of the static structure returned by
getutent(), getutid(),or getutline() if the user has just modified those contents and passed
the pointer back to pututline().
Obsolescent Interfaces
getutent_r() , getutid_r(), getutline_r(), pututline_r(), setutent_r() ,
endutent_r() , utmpname_r() access utmp file entry.
APPLICATION USAGE
getutent(), getutid(), getutline() , pututline() , _pututline() , setutent(),
endutent() and utmpname() are not thread-safe. These interfaces are not async-cancel-safe. A can-
cellation point may occur when a thread is executing getutent() , getutid() , getutline() ,
pututline() , _pututline() , setutent(), endutent() and utmpname() .
RETURN VALUE
These functions return a NULL pointer upon failure to read (whether for permissions or having reached
end-of-file), or upon failure to write. They also return a NULL pointer if the size of the file is not an integral
multiple of sizeof(struct utmp).
_pututline() behaves the same as pututline() , except that it returns a pointer to a static location
containing the most current utmp entry if the _pututline() call succeeds. The contents of this struc-
ture is identical to the contents of the supplied utmp structure if successful. If _pututline() fails
upon writing to
utmp , it returns a NULL pointer. If _putuline() is successful in writing to the
HP-UX Release 11i: December 2000 − 2 − Section 3−−365
___
___