Assume C89, so PARAMS isn't needed.
[gnulib.git] / lib / readutmp.h
1 /* Declarations for GNU's read utmp module.
2
3    Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4    2001, 2002, 2003 Free Software Foundation, Inc.
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2, or (at your option)
9    any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software Foundation,
18    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
19
20 /* Written by jla; revised by djm */
21
22 #ifndef __READUTMP_H__
23 # define __READUTMP_H__
24
25 # include <sys/types.h>
26
27 # ifdef HAVE_UTMPX_H
28 #  ifdef HAVE_UTMP_H
29     /* HPUX 10.20 needs utmp.h, for the definition of e.g., UTMP_FILE.  */
30 #   include <utmp.h>
31 #  endif
32 #  include <utmpx.h>
33 #  define UTMP_STRUCT_NAME utmpx
34 #  define UT_TIME_MEMBER(UT_PTR) ((UT_PTR)->ut_tv.tv_sec)
35 #  define SET_UTMP_ENT setutxent
36 #  define GET_UTMP_ENT getutxent
37 #  define END_UTMP_ENT endutxent
38 #  ifdef HAVE_UTMPXNAME
39 #   define UTMP_NAME_FUNCTION utmpxname
40 #  endif
41 # else
42 #  include <utmp.h>
43 #  if !HAVE_DECL_GETUTENT
44     struct utmp *getutent();
45 #  endif
46 #  define UTMP_STRUCT_NAME utmp
47 #  define UT_TIME_MEMBER(UT_PTR) ((UT_PTR)->ut_time)
48 #  define SET_UTMP_ENT setutent
49 #  define GET_UTMP_ENT getutent
50 #  define END_UTMP_ENT endutent
51 #  ifdef HAVE_UTMPNAME
52 #   define UTMP_NAME_FUNCTION utmpname
53 #  endif
54 # endif
55
56 /* Accessor macro for the member named ut_user or ut_name.  */
57 # ifdef HAVE_UTMPX_H
58
59 #  if HAVE_STRUCT_UTMPX_UT_USER
60 #   define UT_USER(Utmp) ((Utmp)->ut_user)
61 #  endif
62 #  if HAVE_STRUCT_UTMPX_UT_NAME
63 #   undef UT_USER
64 #   define UT_USER(Utmp) ((Utmp)->ut_name)
65 #  endif
66
67 # else
68
69 #  if HAVE_STRUCT_UTMP_UT_USER
70 #   define UT_USER(Utmp) Utmp->ut_user
71 #  endif
72 #  if HAVE_STRUCT_UTMP_UT_NAME
73 #   undef UT_USER
74 #   define UT_USER(Utmp) Utmp->ut_name
75 #  endif
76
77 # endif
78
79 # define HAVE_STRUCT_XTMP_UT_EXIT \
80     (HAVE_STRUCT_UTMP_UT_EXIT \
81      || HAVE_STRUCT_UTMPX_UT_EXIT)
82
83 # define HAVE_STRUCT_XTMP_UT_ID \
84     (HAVE_STRUCT_UTMP_UT_ID \
85      || HAVE_STRUCT_UTMPX_UT_ID)
86
87 # define HAVE_STRUCT_XTMP_UT_PID \
88     (HAVE_STRUCT_UTMP_UT_PID \
89      || HAVE_STRUCT_UTMPX_UT_PID)
90
91 # define HAVE_STRUCT_XTMP_UT_TYPE \
92     (HAVE_STRUCT_UTMP_UT_TYPE \
93      || HAVE_STRUCT_UTMPX_UT_TYPE)
94
95 typedef struct UTMP_STRUCT_NAME STRUCT_UTMP;
96
97 # include <time.h>
98 # ifdef HAVE_SYS_PARAM_H
99 #  include <sys/param.h>
100 # endif
101
102 # include <errno.h>
103 # ifndef errno
104 extern int errno;
105 # endif
106
107 # if !defined (UTMP_FILE) && defined (_PATH_UTMP)
108 #  define UTMP_FILE _PATH_UTMP
109 # endif
110
111 # if !defined (WTMP_FILE) && defined (_PATH_WTMP)
112 #  define WTMP_FILE _PATH_WTMP
113 # endif
114
115 # ifdef UTMPX_FILE /* Solaris, SysVr4 */
116 #  undef UTMP_FILE
117 #  define UTMP_FILE UTMPX_FILE
118 # endif
119
120 # ifdef WTMPX_FILE /* Solaris, SysVr4 */
121 #  undef WTMP_FILE
122 #  define WTMP_FILE WTMPX_FILE
123 # endif
124
125 # ifndef UTMP_FILE
126 #  define UTMP_FILE "/etc/utmp"
127 # endif
128
129 # ifndef WTMP_FILE
130 #  define WTMP_FILE "/etc/wtmp"
131 # endif
132
133 char *extract_trimmed_name (const STRUCT_UTMP *ut);
134 int read_utmp (const char *filename, int *n_entries, STRUCT_UTMP **utmp_buf);
135
136 #endif /* __READUTMP_H__ */