*** empty log message ***
[coreutils.git] / lib / readutmp.h
blobbe59fe99497580722832c5e8b719dbe12fa2dca7
1 /* Declarations for GNU's read utmp module.
3 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 2001, 2002, 2003 Free Software Foundation, Inc.
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.
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.
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. */
20 /* Written by jla; revised by djm */
22 #ifndef __READUTMP_H__
23 # define __READUTMP_H__
25 # include <sys/types.h>
27 /* AIX 4.3.3 has both utmp.h and utmpx.h, but only struct utmp
28 has the ut_exit member. */
29 # if (HAVE_UTMPX_H && HAVE_UTMP_H && HAVE_STRUCT_UTMP_UT_EXIT \
30 && ! HAVE_STRUCT_UTMPX_UT_EXIT)
31 # undef HAVE_UTMPX_H
32 # endif
34 # ifdef HAVE_UTMPX_H
35 # ifdef HAVE_UTMP_H
36 /* HPUX 10.20 needs utmp.h, for the definition of e.g., UTMP_FILE. */
37 # include <utmp.h>
38 # endif
39 # include <utmpx.h>
40 # define UTMP_STRUCT_NAME utmpx
41 # define UT_TIME_MEMBER(UT_PTR) ((UT_PTR)->ut_tv.tv_sec)
42 # define SET_UTMP_ENT setutxent
43 # define GET_UTMP_ENT getutxent
44 # define END_UTMP_ENT endutxent
45 # ifdef HAVE_UTMPXNAME
46 # define UTMP_NAME_FUNCTION utmpxname
47 # endif
49 # if HAVE_STRUCT_UTMPX_UT_EXIT_E_TERMINATION
50 # define UT_EXIT_E_TERMINATION(U) ((U)->ut_exit.e_termination)
51 # else
52 # if HAVE_STRUCT_UTMPX_UT_EXIT_UT_TERMINATION
53 # define UT_EXIT_E_TERMINATION(U) ((U)->ut_exit.ut_termination)
54 # else
55 # define UT_EXIT_E_TERMINATION(U) 0
56 # endif
57 # endif
59 # if HAVE_STRUCT_UTMPX_UT_EXIT_E_EXIT
60 # define UT_EXIT_E_EXIT(U) ((U)->ut_exit.e_exit)
61 # else
62 # if HAVE_STRUCT_UTMPX_UT_EXIT_UT_EXIT
63 # define UT_EXIT_E_EXIT(U) ((U)->ut_exit.ut_exit)
64 # else
65 # define UT_EXIT_E_EXIT(U) 0
66 # endif
67 # endif
69 # else
70 # include <utmp.h>
71 # if !HAVE_DECL_GETUTENT
72 struct utmp *getutent();
73 # endif
74 # define UTMP_STRUCT_NAME utmp
75 # define UT_TIME_MEMBER(UT_PTR) ((UT_PTR)->ut_time)
76 # define SET_UTMP_ENT setutent
77 # define GET_UTMP_ENT getutent
78 # define END_UTMP_ENT endutent
79 # ifdef HAVE_UTMPNAME
80 # define UTMP_NAME_FUNCTION utmpname
81 # endif
83 # if HAVE_STRUCT_UTMP_UT_EXIT_E_TERMINATION
84 # define UT_EXIT_E_TERMINATION(U) ((U)->ut_exit.e_termination)
85 # else
86 # if HAVE_STRUCT_UTMP_UT_EXIT_UT_TERMINATION
87 # define UT_EXIT_E_TERMINATION(U) ((U)->ut_exit.ut_termination)
88 # else
89 # define UT_EXIT_E_TERMINATION(U) 0
90 # endif
91 # endif
93 # if HAVE_STRUCT_UTMP_UT_EXIT_E_EXIT
94 # define UT_EXIT_E_EXIT(U) ((U)->ut_exit.e_exit)
95 # else
96 # if HAVE_STRUCT_UTMP_UT_EXIT_UT_EXIT
97 # define UT_EXIT_E_EXIT(U) ((U)->ut_exit.ut_exit)
98 # else
99 # define UT_EXIT_E_EXIT(U) 0
100 # endif
101 # endif
103 # endif
105 /* Accessor macro for the member named ut_user or ut_name. */
106 # ifdef HAVE_UTMPX_H
108 # if HAVE_STRUCT_UTMPX_UT_USER
109 # define UT_USER(Utmp) ((Utmp)->ut_user)
110 # endif
111 # if HAVE_STRUCT_UTMPX_UT_NAME
112 # undef UT_USER
113 # define UT_USER(Utmp) ((Utmp)->ut_name)
114 # endif
116 # else
118 # if HAVE_STRUCT_UTMP_UT_USER
119 # define UT_USER(Utmp) Utmp->ut_user
120 # endif
121 # if HAVE_STRUCT_UTMP_UT_NAME
122 # undef UT_USER
123 # define UT_USER(Utmp) Utmp->ut_name
124 # endif
126 # endif
128 # define HAVE_STRUCT_XTMP_UT_EXIT \
129 (HAVE_STRUCT_UTMP_UT_EXIT \
130 || HAVE_STRUCT_UTMPX_UT_EXIT)
132 # define HAVE_STRUCT_XTMP_UT_ID \
133 (HAVE_STRUCT_UTMP_UT_ID \
134 || HAVE_STRUCT_UTMPX_UT_ID)
136 # define HAVE_STRUCT_XTMP_UT_PID \
137 (HAVE_STRUCT_UTMP_UT_PID \
138 || HAVE_STRUCT_UTMPX_UT_PID)
140 # define HAVE_STRUCT_XTMP_UT_TYPE \
141 (HAVE_STRUCT_UTMP_UT_TYPE \
142 || HAVE_STRUCT_UTMPX_UT_TYPE)
144 typedef struct UTMP_STRUCT_NAME STRUCT_UTMP;
146 # include <time.h>
147 # ifdef HAVE_SYS_PARAM_H
148 # include <sys/param.h>
149 # endif
151 # include <errno.h>
152 # ifndef errno
153 extern int errno;
154 # endif
156 # if !defined (UTMP_FILE) && defined (_PATH_UTMP)
157 # define UTMP_FILE _PATH_UTMP
158 # endif
160 # if !defined (WTMP_FILE) && defined (_PATH_WTMP)
161 # define WTMP_FILE _PATH_WTMP
162 # endif
164 # ifdef UTMPX_FILE /* Solaris, SysVr4 */
165 # undef UTMP_FILE
166 # define UTMP_FILE UTMPX_FILE
167 # endif
169 # ifdef WTMPX_FILE /* Solaris, SysVr4 */
170 # undef WTMP_FILE
171 # define WTMP_FILE WTMPX_FILE
172 # endif
174 # ifndef UTMP_FILE
175 # define UTMP_FILE "/etc/utmp"
176 # endif
178 # ifndef WTMP_FILE
179 # define WTMP_FILE "/etc/wtmp"
180 # endif
182 char *extract_trimmed_name (const STRUCT_UTMP *ut);
183 int read_utmp (const char *filename, int *n_entries, STRUCT_UTMP **utmp_buf);
185 #endif /* __READUTMP_H__ */