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