fchmod-tests, fchmodat tests, lchmod tests: Add more tests.
[gnulib.git] / lib / readutmp.h
blob5971e7fd82d7015ce6748eb4f45ebd9d381cca64
1 /* Declarations for GNU's read utmp module.
3 Copyright (C) 1992-2007, 2009-2021 Free Software Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 /* Written by jla; revised by djm */
20 #ifndef __READUTMP_H__
21 # define __READUTMP_H__
23 # include <sys/types.h>
25 /* AIX 4.3.3 has both utmp.h and utmpx.h, but only struct utmp
26 has the ut_exit member. */
27 # if (HAVE_UTMPX_H && HAVE_UTMP_H && HAVE_STRUCT_UTMP_UT_EXIT \
28 && ! HAVE_STRUCT_UTMPX_UT_EXIT)
29 # undef HAVE_UTMPX_H
30 # endif
32 # if HAVE_UTMPX_H
33 # if HAVE_UTMP_H
34 /* HPUX 10.20 needs utmp.h, for the definition of e.g., UTMP_FILE. */
35 # include <utmp.h>
36 # endif
37 # if defined _THREAD_SAFE && defined UTMP_DATA_INIT
38 /* When including both utmp.h and utmpx.h on AIX 4.3, with _THREAD_SAFE
39 defined, work around the duplicate struct utmp_data declaration. */
40 # define utmp_data gl_aix_4_3_workaround_utmp_data
41 # endif
42 # include <utmpx.h>
43 # define UTMP_STRUCT_NAME utmpx
44 # define UT_TIME_MEMBER(UT_PTR) ((UT_PTR)->ut_tv.tv_sec)
45 # define SET_UTMP_ENT setutxent
46 # define GET_UTMP_ENT getutxent
47 # define END_UTMP_ENT endutxent
48 # ifdef HAVE_UTMPXNAME
49 # define UTMP_NAME_FUNCTION utmpxname
50 # elif defined UTXDB_ACTIVE
51 # define UTMP_NAME_FUNCTION(x) setutxdb (UTXDB_ACTIVE, x)
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 # elif HAVE_UTMP_H
76 # include <utmp.h>
77 # if !HAVE_DECL_GETUTENT
78 struct utmp *getutent (void);
79 # endif
80 # define UTMP_STRUCT_NAME utmp
81 # define UT_TIME_MEMBER(UT_PTR) ((UT_PTR)->ut_time)
82 # define SET_UTMP_ENT setutent
83 # define GET_UTMP_ENT getutent
84 # define END_UTMP_ENT endutent
85 # ifdef HAVE_UTMPNAME
86 # define UTMP_NAME_FUNCTION utmpname
87 # endif
89 # if HAVE_STRUCT_UTMP_UT_EXIT_E_TERMINATION
90 # define UT_EXIT_E_TERMINATION(U) ((U)->ut_exit.e_termination)
91 # else
92 # if HAVE_STRUCT_UTMP_UT_EXIT_UT_TERMINATION
93 # define UT_EXIT_E_TERMINATION(U) ((U)->ut_exit.ut_termination)
94 # else
95 # define UT_EXIT_E_TERMINATION(U) 0
96 # endif
97 # endif
99 # if HAVE_STRUCT_UTMP_UT_EXIT_E_EXIT
100 # define UT_EXIT_E_EXIT(U) ((U)->ut_exit.e_exit)
101 # else
102 # if HAVE_STRUCT_UTMP_UT_EXIT_UT_EXIT
103 # define UT_EXIT_E_EXIT(U) ((U)->ut_exit.ut_exit)
104 # else
105 # define UT_EXIT_E_EXIT(U) 0
106 # endif
107 # endif
109 # endif
111 /* Accessor macro for the member named ut_user or ut_name. */
112 # if HAVE_UTMPX_H
114 # if HAVE_STRUCT_UTMPX_UT_USER
115 # define UT_USER(Utmp) ((Utmp)->ut_user)
116 # endif
117 # if HAVE_STRUCT_UTMPX_UT_NAME
118 # undef UT_USER
119 # define UT_USER(Utmp) ((Utmp)->ut_name)
120 # endif
122 # elif HAVE_UTMP_H
124 # if HAVE_STRUCT_UTMP_UT_USER
125 # define UT_USER(Utmp) ((Utmp)->ut_user)
126 # endif
127 # if HAVE_STRUCT_UTMP_UT_NAME
128 # undef UT_USER
129 # define UT_USER(Utmp) ((Utmp)->ut_name)
130 # endif
132 # endif
134 # define HAVE_STRUCT_XTMP_UT_EXIT \
135 (HAVE_STRUCT_UTMP_UT_EXIT \
136 || HAVE_STRUCT_UTMPX_UT_EXIT)
138 # define HAVE_STRUCT_XTMP_UT_ID \
139 (HAVE_STRUCT_UTMP_UT_ID \
140 || HAVE_STRUCT_UTMPX_UT_ID)
142 # define HAVE_STRUCT_XTMP_UT_PID \
143 (HAVE_STRUCT_UTMP_UT_PID \
144 || HAVE_STRUCT_UTMPX_UT_PID)
146 typedef struct UTMP_STRUCT_NAME STRUCT_UTMP;
148 enum { UT_USER_SIZE = sizeof UT_USER ((STRUCT_UTMP *) 0) };
150 # if !defined UTMP_FILE && defined _PATH_UTMP
151 # define UTMP_FILE _PATH_UTMP
152 # endif
154 # if !defined WTMP_FILE && defined _PATH_WTMP
155 # define WTMP_FILE _PATH_WTMP
156 # endif
158 # ifdef UTMPX_FILE /* Solaris, SysVr4 */
159 # undef UTMP_FILE
160 # define UTMP_FILE UTMPX_FILE
161 # endif
163 # ifdef WTMPX_FILE /* Solaris, SysVr4 */
164 # undef WTMP_FILE
165 # define WTMP_FILE WTMPX_FILE
166 # endif
168 # ifndef UTMP_FILE
169 # define UTMP_FILE "/etc/utmp"
170 # endif
172 # ifndef WTMP_FILE
173 # define WTMP_FILE "/etc/wtmp"
174 # endif
176 # if HAVE_STRUCT_XTMP_UT_PID
177 # define UT_PID(U) ((U)->ut_pid)
178 # else
179 # define UT_PID(U) 0
180 # endif
182 # if HAVE_STRUCT_UTMP_UT_TYPE || HAVE_STRUCT_UTMPX_UT_TYPE
183 # define UT_TYPE_EQ(U, V) ((U)->ut_type == (V))
184 # define UT_TYPE_NOT_DEFINED 0
185 # else
186 # define UT_TYPE_EQ(U, V) 0
187 # define UT_TYPE_NOT_DEFINED 1
188 # endif
190 # ifdef BOOT_TIME
191 # define UT_TYPE_BOOT_TIME(U) UT_TYPE_EQ (U, BOOT_TIME)
192 # else
193 # define UT_TYPE_BOOT_TIME(U) 0
194 # endif
196 # ifdef USER_PROCESS
197 # define UT_TYPE_USER_PROCESS(U) UT_TYPE_EQ (U, USER_PROCESS)
198 # else
199 # define UT_TYPE_USER_PROCESS(U) 0
200 # endif
202 # define IS_USER_PROCESS(U) \
203 (UT_USER (U)[0] \
204 && (UT_TYPE_USER_PROCESS (U) \
205 || (UT_TYPE_NOT_DEFINED && UT_TIME_MEMBER (U) != 0)))
207 /* Options for read_utmp. */
208 enum
210 READ_UTMP_CHECK_PIDS = 1,
211 READ_UTMP_USER_PROCESS = 2
214 char *extract_trimmed_name (const STRUCT_UTMP *ut);
215 int read_utmp (char const *file, size_t *n_entries, STRUCT_UTMP **utmp_buf,
216 int options);
218 #endif /* __READUTMP_H__ */