*** empty log message ***
[coreutils.git] / lib / readutmp.h
blob3d60b8240aefde2e41917afade688d27a39feecf
1 /* Declarations for GNU's read utmp module.
2 Copyright (C) 1992-2002 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 /* Written by jla; revised by djm */
20 #ifndef __READUTMP_H__
21 # define __READUTMP_H__
23 # ifndef PARAMS
24 # if defined PROTOTYPES || (defined __STDC__ && __STDC__)
25 # define PARAMS(Args) Args
26 # else
27 # define PARAMS(Args) ()
28 # endif
29 # endif
31 # include <sys/types.h>
33 /* AIX 4.3.3 has both utmp.h and utmpx.h, but only struct utmp
34 has the ut_exit member. */
35 # if HAVE_UTMPX_H && HAVE_UTMP_H && HAVE_STRUCT_UTMP_UT_EXIT && ! HAVE_STRUCT_UTMPX_UT_EXIT
36 # undef HAVE_UTMPX_H
37 # endif
39 # ifdef HAVE_UTMPX_H
40 # ifdef HAVE_UTMP_H
41 /* HPUX 10.20 needs utmp.h, for the definition of e.g., UTMP_FILE. */
42 # include <utmp.h>
43 # endif
44 # include <utmpx.h>
45 # define UTMP_STRUCT_NAME utmpx
46 # define UT_TIME_MEMBER(UT_PTR) ((UT_PTR)->ut_tv.tv_sec)
47 # define SET_UTMP_ENT setutxent
48 # define GET_UTMP_ENT getutxent
49 # define END_UTMP_ENT endutxent
50 # ifdef HAVE_UTMPXNAME
51 # define UTMP_NAME_FUNCTION utmpxname
52 # endif
54 # if HAVE_STRUCT_UTMPX_UT_EXIT_E_TERMINATION
55 # define UT_EXIT_E_TERMINATION(U) ((U)->ut_exit.e_termination)
56 # else
57 # if HAVE_STRUCT_UTMPX_UT_EXIT_UT_TERMINATION
58 # define UT_EXIT_E_TERMINATION(U) ((U)->ut_exit.ut_termination)
59 # else
60 # define UT_EXIT_E_TERMINATION(U) 0
61 # endif
62 # endif
64 # if HAVE_STRUCT_UTMPX_UT_EXIT_E_EXIT
65 # define UT_EXIT_E_EXIT(U) ((U)->ut_exit.e_exit)
66 # else
67 # if HAVE_STRUCT_UTMPX_UT_EXIT_UT_EXIT
68 # define UT_EXIT_E_EXIT(U) ((U)->ut_exit.ut_exit)
69 # else
70 # define UT_EXIT_E_EXIT(U) 0
71 # endif
72 # endif
74 # else
75 # include <utmp.h>
76 # if !HAVE_DECL_GETUTENT
77 struct utmp *getutent();
78 # endif
79 # define UTMP_STRUCT_NAME utmp
80 # define UT_TIME_MEMBER(UT_PTR) ((UT_PTR)->ut_time)
81 # define SET_UTMP_ENT setutent
82 # define GET_UTMP_ENT getutent
83 # define END_UTMP_ENT endutent
84 # ifdef HAVE_UTMPNAME
85 # define UTMP_NAME_FUNCTION utmpname
86 # endif
88 # if HAVE_STRUCT_UTMP_UT_EXIT_E_TERMINATION
89 # define UT_EXIT_E_TERMINATION(U) ((U)->ut_exit.e_termination)
90 # else
91 # if HAVE_STRUCT_UTMP_UT_EXIT_UT_TERMINATION
92 # define UT_EXIT_E_TERMINATION(U) ((U)->ut_exit.ut_termination)
93 # else
94 # define UT_EXIT_E_TERMINATION(U) 0
95 # endif
96 # endif
98 # if HAVE_STRUCT_UTMP_UT_EXIT_E_EXIT
99 # define UT_EXIT_E_EXIT(U) ((U)->ut_exit.e_exit)
100 # else
101 # if HAVE_STRUCT_UTMP_UT_EXIT_UT_EXIT
102 # define UT_EXIT_E_EXIT(U) ((U)->ut_exit.ut_exit)
103 # else
104 # define UT_EXIT_E_EXIT(U) 0
105 # endif
106 # endif
108 # endif
110 /* Accessor macro for the member named ut_user or ut_name. */
111 # ifdef HAVE_UTMPX_H
113 # if HAVE_STRUCT_UTMPX_UT_USER
114 # define UT_USER(Utmp) ((Utmp)->ut_user)
115 # endif
116 # if HAVE_STRUCT_UTMPX_UT_NAME
117 # undef UT_USER
118 # define UT_USER(Utmp) ((Utmp)->ut_name)
119 # endif
121 # else
123 # if HAVE_STRUCT_UTMP_UT_USER
124 # define UT_USER(Utmp) Utmp->ut_user
125 # endif
126 # if HAVE_STRUCT_UTMP_UT_NAME
127 # undef UT_USER
128 # define UT_USER(Utmp) Utmp->ut_name
129 # endif
131 # endif
133 # define HAVE_STRUCT_XTMP_UT_EXIT \
134 (HAVE_STRUCT_UTMP_UT_EXIT \
135 || HAVE_STRUCT_UTMPX_UT_EXIT)
137 # define HAVE_STRUCT_XTMP_UT_ID \
138 (HAVE_STRUCT_UTMP_UT_ID \
139 || HAVE_STRUCT_UTMPX_UT_ID)
141 # define HAVE_STRUCT_XTMP_UT_PID \
142 (HAVE_STRUCT_UTMP_UT_PID \
143 || HAVE_STRUCT_UTMPX_UT_PID)
145 # define HAVE_STRUCT_XTMP_UT_TYPE \
146 (HAVE_STRUCT_UTMP_UT_TYPE \
147 || HAVE_STRUCT_UTMPX_UT_TYPE)
149 typedef struct UTMP_STRUCT_NAME STRUCT_UTMP;
151 # include <time.h>
152 # ifdef HAVE_SYS_PARAM_H
153 # include <sys/param.h>
154 # endif
156 # include <errno.h>
157 # ifndef errno
158 extern int errno;
159 # endif
161 # if !defined (UTMP_FILE) && defined (_PATH_UTMP)
162 # define UTMP_FILE _PATH_UTMP
163 # endif
165 # if !defined (WTMP_FILE) && defined (_PATH_WTMP)
166 # define WTMP_FILE _PATH_WTMP
167 # endif
169 # ifdef UTMPX_FILE /* Solaris, SysVr4 */
170 # undef UTMP_FILE
171 # define UTMP_FILE UTMPX_FILE
172 # endif
174 # ifdef WTMPX_FILE /* Solaris, SysVr4 */
175 # undef WTMP_FILE
176 # define WTMP_FILE WTMPX_FILE
177 # endif
179 # ifndef UTMP_FILE
180 # define UTMP_FILE "/etc/utmp"
181 # endif
183 # ifndef WTMP_FILE
184 # define WTMP_FILE "/etc/wtmp"
185 # endif
187 # undef PARAMS
188 # if defined (__STDC__) && __STDC__
189 # define PARAMS(Args) Args
190 # else
191 # define PARAMS(Args) ()
192 # endif
194 extern char *extract_trimmed_name PARAMS ((const STRUCT_UTMP *ut));
195 extern int read_utmp PARAMS ((const char *filename,
196 int *n_entries, STRUCT_UTMP **utmp_buf));
198 #endif /* __READUTMP_H__ */