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