- port to Cygwin (DLL support, etc.)
[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 #ifdef DLL_EXPORT
10 #define IN_LIBCIT
11 #endif
12
13 #include "sysdep.h"
14 #ifdef HAVE_UTMP_H
15 #include <stdio.h>
16 #include <sys/types.h>
17 #include <utmp.h>
18 #ifdef HAVE_PATHS_H
19 #include <paths.h>
20 #endif
21 #include <string.h>
22
23 struct utmp *getutline(struct utmp *ut)
24 {
25   static struct utmp retval;
26   FILE *utmp;
27
28 #ifdef UTMP_FILE
29   if ((utmp = fopen(UTMP_FILE, "rb")) == NULL)
30 #else
31   if ((utmp = fopen(_PATH_UTMP, "rb")) == NULL)
32 #endif
33     return NULL;
34
35   do
36     if (!fread(&retval, sizeof retval, 1, utmp))
37       {
38         fclose(utmp);
39         return NULL;
40       }
41   while (strcmp(ut->ut_line, retval.ut_line));
42
43   fclose(utmp);
44   return &retval;
45 }
46 #endif /* HAVE_UTMP_H */