v05i060: A more complete getut emulation
Paul Sutcliffe Jr.
paul at devon.UUCP
Sun Nov 27 09:12:26 AEST 1988
Posting-number: Volume 5, Issue 60
Submitted-by: "Paul Sutcliffe Jr." <paul at devon.UUCP>
Archive-name: bsd.getut.2
+---------
| Posting-number: Volume 5, Issue 37
| Submitted-by: "Jeff Beadles" <jeff at tekcsc.mkt.tek.com>
| Archive-name: bsd.getut
|
| [I take it this was redirected. Note that it won't help you compile s5finger
| on a non-System-V system: getutline() isn't here. ++bsa]
+---------
Okay, so you need a getutline()? Here is the complete getutent
emulation that I use here at devon. You may post this in c.s.m. if you
feel it useful to the net at large (given they've already seen bsd.getut).
- paul
----- 8< ---------- 8< ---------- 8< ---------- 8< ---------- 8< -----
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
# getutent.c
# This archive created: Wed Nov 9 23:34:29 1988
export PATH; PATH=/bin:$PATH
echo shar: extracting "'getutent.c'" '(1324 characters)'
if test -f 'getutent.c'
then
echo shar: will not over-write existing file "'getutent.c'"
else
sed 's/^X//' << \SHAR_EOF > 'getutent.c'
X/**
X ** Simulate SysV getutent(3) calls, as best as can be done in
X ** a System III environment, at least.
X **
X ** Author: Paul Sutcliffe, Jr. <paul at devon.uucp>
X **
X ** I hereby place this in the public domain.
X ** No warranties expressed or implied.
X **/
X
X#include <stdio.h>
X#include <string.h>
X#include <sys/types.h>
X#include <utmp.h>
X
Xstatic char *utmpfil = "/etc/utmp"; /* default utmp file */
Xstatic FILE *ufp = NULL; /* file pointer to utmp file */
X /* NULL = no utmp file open */
Xstatic struct utmp ut; /* buffer for utmp record */
X
Xstruct utmp *getutent(), *getutline();
Xvoid pututline(), setutent(), endutent(), utmpname();
X
Xstruct utmp *
Xgetutent()
X{
X FILE *fopen();
X
X if (ufp == NULL) {
X if ((ufp = fopen(utmpfil, "r+")) == NULL) {
X return((struct utmp *)NULL);
X }
X }
X do {
X if (fread((char *)&ut, sizeof(ut), 1, ufp) != 1) {
X return((struct utmp *)NULL);
X }
X } while (ut.ut_name[0] == 0); /* valid entry? */
X
X return(&ut);
X}
X
Xstruct utmp *
Xgetutline(line)
Xstruct utmp *line;
X{
X do {
X if (strcmp(ut.ut_line, line->ut_line) == 0) {
X return(&ut);
X }
X } while (getutent() != (struct utmp *)NULL);
X
X return((struct utmp *)NULL);
X}
X
Xvoid
Xsetutent()
X{
X if (ufp != NULL) rewind(ufp);
X}
X
Xvoid
Xendutent()
X{
X if (ufp != NULL) fclose(ufp);
X}
X
Xvoid
Xutmpname(file)
Xchar *file;
X{
X utmpfil = file;
X}
SHAR_EOF
if test 1324 -ne "`wc -c < 'getutent.c'`"
then
echo shar: error transmitting "'getutent.c'" '(should have been 1324 characters)'
fi
fi # end of overwriting check
# End of shell archive
exit 0
More information about the Comp.sources.misc
mailing list