2.9
[glibc/nacl-glibc.git] / sysdeps / unix / sysv / linux / s390 / s390-32 / utmpx32.c
blob69a1384db6e39f66ab8317ca59b79e5e15ba92b5
1 /* Copyright (C) 2008 Free Software Foundation, Inc.
2 Contributed by Andreas Krebbel <Andreas.Krebbel@de.ibm.com>.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library 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 GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <sys/types.h>
21 #include <utmp.h>
22 #include <errno.h>
23 #include <libc-symbols.h>
25 #include "utmp32.h"
26 #include "utmp-convert.h"
28 #include "utmpx32.h"
29 #include "utmpx-convert.h"
31 /* Allocate a static buffer to be returned to the caller. As well as
32 with the existing version of these functions the caller has to be
33 aware that the contents of this buffer will change with subsequent
34 calls. */
35 #define ALLOCATE_UTMPX32_OUT(OUT) \
36 static struct utmpx32 *OUT = NULL; \
38 if (OUT == NULL) \
39 { \
40 OUT = malloc (sizeof (struct utmpx32)); \
41 if (OUT == NULL) \
42 return NULL; \
45 /* Perform a lookup for a utmpx entry matching FIELD using function
46 FUNC. FIELD is converted to a 64 bit utmpx and the result is
47 converted back to 32 bit utmpx. */
48 #define ACCESS_UTMPX_ENTRY(FUNC, FIELD) \
49 struct utmpx in64; \
50 struct utmpx *out64; \
51 ALLOCATE_UTMPX32_OUT (out32); \
53 utmpx_convert32to64 (FIELD, &in64); \
54 out64 = FUNC (&in64); \
56 if (out64 == NULL) \
57 return NULL; \
59 utmpx_convert64to32 (out64, out32); \
61 return out32;
64 /* Get the next entry from the user accounting database. */
65 struct utmpx32 *
66 getutxent32 (void)
68 struct utmpx *out64;
69 ALLOCATE_UTMPX32_OUT (out32);
71 out64 = getutxent ();
72 if (!out64)
73 return NULL;
75 utmpx_convert64to32 (out64, out32);
76 return out32;
79 symbol_version (getutxent32, getutxent, GLIBC_2.1);
81 /* Get the user accounting database entry corresponding to ID. */
82 struct utmpx32 *
83 getutxid32 (const struct utmpx32 *id)
85 ACCESS_UTMPX_ENTRY (getutxid, id);
87 symbol_version (getutxid32, getutxid, GLIBC_2.1);
89 /* Get the user accounting database entry corresponding to LINE. */
90 struct utmpx32 *
91 getutxline32 (const struct utmpx32 *line)
93 ACCESS_UTMPX_ENTRY (getutxline, line);
95 symbol_version (getutxline32, getutxline, GLIBC_2.1);
97 /* Write the entry UTMPX into the user accounting database. */
98 struct utmpx32 *
99 pututxline32 (const struct utmpx32 *utmpx)
101 ACCESS_UTMPX_ENTRY (pututxline, utmpx);
103 symbol_version (pututxline32, pututxline, GLIBC_2.1);
105 /* Append entry UTMP to the wtmpx-like file WTMPX_FILE. */
106 void
107 updwtmpx32 (const char *wtmpx_file, const struct utmpx32 *utmpx)
109 struct utmpx in64;
111 utmpx_convert32to64 (utmpx, &in64);
112 updwtmpx (wtmpx_file, &in64);
114 symbol_version (updwtmpx32, updwtmpx, GLIBC_2.1);
116 /* Copy the information in UTMPX to UTMP. */
117 void
118 getutmp32 (const struct utmpx32 *utmpx, struct utmp32 *utmp)
120 struct utmpx in64;
121 struct utmp out64;
123 utmpx_convert32to64 (utmpx, &in64);
124 getutmp (&in64, &out64);
125 utmp_convert64to32 (&out64, utmp);
127 symbol_version (getutmp32, getutmp, GLIBC_2.1.1);
129 /* Copy the information in UTMP to UTMPX. */
130 void
131 getutmpx32 (const struct utmp32 *utmp, struct utmpx32 *utmpx)
133 struct utmp in64;
134 struct utmpx out64;
136 utmp_convert32to64 (utmp, &in64);
137 getutmpx (&in64, &out64);
138 utmpx_convert64to32 (&out64, utmpx);
140 symbol_version (getutmpx32, getutmpx, GLIBC_2.1.1);