Began removing $Id$ tags. This will be an ongoing process.
[citadel.git] / citadel / getutline.c
1 /*
2  * getutline.c: not-quite-compatible replacement for getutline(3)
3  * by nathan bryant, feb 1999
4  */
5
6 #include "sysdep.h"
7 #ifdef HAVE_UTMP_H
8 #include <stdio.h>
9 #include <sys/types.h>
10 #include <utmp.h>
11 #ifdef HAVE_PATHS_H
12 #include <paths.h>
13 #endif
14 #include <string.h>
15
16 struct utmp *getutline(struct utmp *ut)
17 {
18   static struct utmp retval;
19   FILE *utmp;
20
21 #ifdef UTMP_FILE
22   if ((utmp = fopen(UTMP_FILE, "rb")) == NULL)
23 #else
24   if ((utmp = fopen(_PATH_UTMP, "rb")) == NULL)
25 #endif
26     return NULL;
27
28   do
29     if (!fread(&retval, sizeof retval, 1, utmp))
30       {
31         fclose(utmp);
32         return NULL;
33       }
34   while (strcmp(ut->ut_line, retval.ut_line));
35
36   fclose(utmp);
37   return &retval;
38 }
39 #endif /* HAVE_UTMP_H */