[HAVE_UTMPX_H && !HAVE_DECL_GETUTENT]: Declare getutent.
[gnulib.git] / lib / readutmp.h
1 /* Declarations for GNU's read utmp module.
2    Copyright (C) 1992-2000 Free Software Foundation, Inc.
3
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.
8
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.
13
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.  */
17
18 /* Written by jla; revised by djm */
19
20 #ifndef __READUTMP_H__
21 # define __READUTMP_H__
22
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
30
31 # include <sys/types.h>
32
33 # ifdef HAVE_UTMPX_H
34 #  include <utmpx.h>
35 #  define UTMP_STRUCT_NAME utmpx
36 #  define UT_TIME_MEMBER(UT_PTR) ((UT_PTR)->ut_tv.tv_sec)
37 #  define SET_UTMP_ENT setutxent
38 #  define GET_UTMP_ENT getutxent
39 #  define END_UTMP_ENT endutxent
40 #  ifdef HAVE_UTMPXNAME
41 #   define UTMP_NAME_FUNCTION utmpxname
42 #  endif
43 # else
44 #  include <utmp.h>
45 #  if !HAVE_DECL_GETUTENT
46     struct utmp *getutent();
47 #  endif
48 #  define UTMP_STRUCT_NAME utmp
49 #  define UT_TIME_MEMBER(UT_PTR) ((UT_PTR)->ut_time)
50 #  define SET_UTMP_ENT setutent
51 #  define GET_UTMP_ENT getutent
52 #  define END_UTMP_ENT endutent
53 #  ifdef HAVE_UTMPNAME
54 #   define UTMP_NAME_FUNCTION utmpname
55 #  endif
56 # endif
57
58 /* Accessor macro for the member named ut_user or ut_name.  */
59 # ifdef HAVE_UTMPX_H
60
61 #  if HAVE_STRUCT_UTMPX_UT_USER
62 #   define UT_USER(Utmp) ((Utmp)->ut_user)
63 #  endif
64 #  if HAVE_STRUCT_UTMPX_UT_NAME
65 #   undef UT_USER
66 #   define UT_USER(Utmp) ((Utmp)->ut_name)
67 #  endif
68
69 # else
70
71 #  if HAVE_STRUCT_UTMP_UT_USER
72 #   define UT_USER(Utmp) Utmp->ut_user
73 #  endif
74 #  if HAVE_STRUCT_UTMP_UT_NAME
75 #   undef UT_USER
76 #   define UT_USER(Utmp) Utmp->ut_name
77 #  endif
78
79 # endif
80
81 typedef struct UTMP_STRUCT_NAME STRUCT_UTMP;
82
83 # include <time.h>
84 # ifdef HAVE_SYS_PARAM_H
85 #  include <sys/param.h>
86 # endif
87
88 # include <errno.h>
89 # ifndef errno
90 extern int errno;
91 # endif
92
93 # if !defined (UTMP_FILE) && defined (_PATH_UTMP)
94 #  define UTMP_FILE _PATH_UTMP
95 # endif
96
97 # if !defined (WTMP_FILE) && defined (_PATH_WTMP)
98 #  define WTMP_FILE _PATH_WTMP
99 # endif
100
101 # ifdef UTMPX_FILE /* Solaris, SysVr4 */
102 #  undef UTMP_FILE
103 #  define UTMP_FILE UTMPX_FILE
104 # endif
105
106 # ifdef WTMPX_FILE /* Solaris, SysVr4 */
107 #  undef WTMP_FILE
108 #  define WTMP_FILE WTMPX_FILE
109 # endif
110
111 # ifndef UTMP_FILE
112 #  define UTMP_FILE "/etc/utmp"
113 # endif
114
115 # ifndef WTMP_FILE
116 #  define WTMP_FILE "/etc/wtmp"
117 # endif
118
119 # undef PARAMS
120 # if defined (__STDC__) && __STDC__
121 #  define PARAMS(Args) Args
122 # else
123 #  define PARAMS(Args) ()
124 # endif
125
126 extern char *extract_trimmed_name PARAMS ((const STRUCT_UTMP *ut));
127 extern int read_utmp PARAMS ((const char *filename,
128                               int *n_entries, STRUCT_UTMP **utmp_buf));
129
130 #endif /* __READUTMP_H__ */