HP-UX Reference (11i v3 07/02) - 3 Library Functions A-M (vol 6)

g
getut(3C) getut(3C)
(TO BE OBSOLETED)
LOGIN_PROCESS
, USER_PROCESS ,orDEAD_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,
getut-
line()
fails.
pututline() Writes out the supplied
utmp structure into the utmp file, translates the supplied
utmp structure into a utmpx structure and writes it to a
utmpx file. putut-
line()
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
pututline() 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 files. 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(3C) functions. The one exception to this are the putut() and
pututx() functions as they access both files in an attempt to keep the utmp and
utmpx files in sync. The other files are usually /var/adm/wtmp
and
/var/adm/wtmpx. If the files do not exist, the 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 you are using getutline() to
search for multiple occurrences, it is necessary to zero out the static structure after each success; other-
wise,
getutline() 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.
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 utmp
file and fails in writing to the utmpx file, then _pututline() will behave as if it succeeded. Please
note that the utmp file and the utmpx file may not be in sync due to the above behavior. putut-
line()
and _pututline() are only guaranteed to have written to the utmp file upon successful
completion.
580 Hewlett-Packard Company 2 HP-UX 11i Version 3: February 2007