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)
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)
36 /* HPUX 10.20 needs utmp.h, for the definition of e.g., UTMP_FILE. */
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
49 # if HAVE_STRUCT_UTMPX_UT_EXIT_E_TERMINATION
50 # define UT_EXIT_E_TERMINATION(U) ((U)->ut_exit.e_termination)
52 # if HAVE_STRUCT_UTMPX_UT_EXIT_UT_TERMINATION
53 # define UT_EXIT_E_TERMINATION(U) ((U)->ut_exit.ut_termination)
55 # define UT_EXIT_E_TERMINATION(U) 0
59 # if HAVE_STRUCT_UTMPX_UT_EXIT_E_EXIT
60 # define UT_EXIT_E_EXIT(U) ((U)->ut_exit.e_exit)
62 # if HAVE_STRUCT_UTMPX_UT_EXIT_UT_EXIT
63 # define UT_EXIT_E_EXIT(U) ((U)->ut_exit.ut_exit)
65 # define UT_EXIT_E_EXIT(U) 0
71 # if !HAVE_DECL_GETUTENT
72 struct utmp
*getutent();
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
80 # define UTMP_NAME_FUNCTION utmpname
83 # if HAVE_STRUCT_UTMP_UT_EXIT_E_TERMINATION
84 # define UT_EXIT_E_TERMINATION(U) ((U)->ut_exit.e_termination)
86 # if HAVE_STRUCT_UTMP_UT_EXIT_UT_TERMINATION
87 # define UT_EXIT_E_TERMINATION(U) ((U)->ut_exit.ut_termination)
89 # define UT_EXIT_E_TERMINATION(U) 0
93 # if HAVE_STRUCT_UTMP_UT_EXIT_E_EXIT
94 # define UT_EXIT_E_EXIT(U) ((U)->ut_exit.e_exit)
96 # if HAVE_STRUCT_UTMP_UT_EXIT_UT_EXIT
97 # define UT_EXIT_E_EXIT(U) ((U)->ut_exit.ut_exit)
99 # define UT_EXIT_E_EXIT(U) 0
105 /* Accessor macro for the member named ut_user or ut_name. */
108 # if HAVE_STRUCT_UTMPX_UT_USER
109 # define UT_USER(Utmp) ((Utmp)->ut_user)
111 # if HAVE_STRUCT_UTMPX_UT_NAME
113 # define UT_USER(Utmp) ((Utmp)->ut_name)
118 # if HAVE_STRUCT_UTMP_UT_USER
119 # define UT_USER(Utmp) Utmp->ut_user
121 # if HAVE_STRUCT_UTMP_UT_NAME
123 # define UT_USER(Utmp) Utmp->ut_name
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
;
147 # ifdef HAVE_SYS_PARAM_H
148 # include <sys/param.h>
156 # if !defined (UTMP_FILE) && defined (_PATH_UTMP)
157 # define UTMP_FILE _PATH_UTMP
160 # if !defined (WTMP_FILE) && defined (_PATH_WTMP)
161 # define WTMP_FILE _PATH_WTMP
164 # ifdef UTMPX_FILE /* Solaris, SysVr4 */
166 # define UTMP_FILE UTMPX_FILE
169 # ifdef WTMPX_FILE /* Solaris, SysVr4 */
171 # define WTMP_FILE WTMPX_FILE
175 # define UTMP_FILE "/etc/utmp"
179 # define WTMP_FILE "/etc/wtmp"
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__ */