Back to index

citadel  8.12
getutline.c
Go to the documentation of this file.
00001 /*
00002  * getutline.c: not-quite-compatible replacement for getutline(3)
00003  * by nathan bryant, feb 1999
00004  */
00005 
00006 #include "sysdep.h"
00007 #ifdef HAVE_UTMP_H
00008 #include <stdio.h>
00009 #include <sys/types.h>
00010 #include <utmp.h>
00011 #ifdef HAVE_PATHS_H
00012 #include <paths.h>
00013 #endif
00014 #include <string.h>
00015 
00016 struct utmp *getutline(struct utmp *ut)
00017 {
00018   static struct utmp retval;
00019   FILE *utmp;
00020 
00021 #ifdef UTMP_FILE
00022   if ((utmp = fopen(UTMP_FILE, "rb")) == NULL)
00023 #else
00024   if ((utmp = fopen(_PATH_UTMP, "rb")) == NULL)
00025 #endif
00026     return NULL;
00027 
00028   do
00029     if (!fread(&retval, sizeof retval, 1, utmp))
00030       {
00031        fclose(utmp);
00032        return NULL;
00033       }
00034   while (strcmp(ut->ut_line, retval.ut_line));
00035 
00036   fclose(utmp);
00037   return &retval;
00038 }
00039 #endif /* HAVE_UTMP_H */