2.9
[glibc/nacl-glibc.git] / sysdeps / unix / sysv / linux / s390 / s390-32 / utmp32.c
blob32a5d7137684e0c866722a98108b11ef827bd9f6
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 /* Allocate a static buffer to be returned to the caller. As well as
29 with the existing version of these functions the caller has to be
30 aware that the contents of this buffer will change with subsequent
31 calls. */
32 #define ALLOCATE_UTMP32_OUT(OUT) \
33 static struct utmp32 *OUT = NULL; \
35 if (OUT == NULL) \
36 { \
37 OUT = malloc (sizeof (struct utmp32)); \
38 if (OUT == NULL) \
39 return NULL; \
42 /* Perform a lookup for a utmp entry matching FIELD using function
43 FUNC. FIELD is converted to a 64 bit utmp and the result is
44 converted back to 32 bit utmp. */
45 #define ACCESS_UTMP_ENTRY(FUNC, FIELD) \
46 struct utmp in64; \
47 struct utmp *out64; \
48 ALLOCATE_UTMP32_OUT (out32); \
50 utmp_convert32to64 (FIELD, &in64); \
51 out64 = FUNC (&in64); \
53 if (out64 == NULL) \
54 return NULL; \
56 utmp_convert64to32 (out64, out32); \
58 return out32;
60 /* Search forward from the current point in the utmp file until the
61 next entry with a ut_type matching ID->ut_type. */
62 struct utmp32 *
63 getutid32 (const struct utmp32 *id)
65 ACCESS_UTMP_ENTRY (getutid, id)
67 symbol_version (getutid32, getutid, GLIBC_2.0);
69 /* Search forward from the current point in the utmp file until the
70 next entry with a ut_line matching LINE->ut_line. */
71 struct utmp32 *
72 getutline32 (const struct utmp32 *line)
74 ACCESS_UTMP_ENTRY (getutline, line)
76 symbol_version (getutline32, getutline, GLIBC_2.0);
78 /* Write out entry pointed to by UTMP_PTR into the utmp file. */
79 struct utmp32 *
80 pututline32 (const struct utmp32 *utmp_ptr)
82 ACCESS_UTMP_ENTRY (pututline, utmp_ptr)
84 symbol_version (pututline32, pututline, GLIBC_2.0);
86 /* Read next entry from a utmp-like file. */
87 struct utmp32 *
88 getutent32 (void)
90 struct utmp *out64;
91 ALLOCATE_UTMP32_OUT (out32);
93 out64 = getutent ();
94 if (!out64)
95 return NULL;
97 utmp_convert64to32 (out64, out32);
98 return out32;
100 symbol_version (getutent32, getutent, GLIBC_2.0);
102 /* Reentrant versions of the file for handling utmp files. */
105 getutent32_r (struct utmp32 *buffer, struct utmp32 **result)
107 struct utmp out64;
108 struct utmp *out64p;
109 int ret;
111 ret = getutent_r (&out64, &out64p);
112 if (ret == -1)
114 *result = NULL;
115 return -1;
118 utmp_convert64to32 (out64p, buffer);
119 *result = buffer;
121 return 0;
123 symbol_version (getutent32_r, getutent_r, GLIBC_2.0);
126 getutid32_r (const struct utmp32 *id, struct utmp32 *buffer,
127 struct utmp32 **result)
129 struct utmp in64;
130 struct utmp out64;
131 struct utmp *out64p;
132 int ret;
134 utmp_convert32to64 (id, &in64);
136 ret = getutid_r (&in64, &out64, &out64p);
137 if (ret == -1)
139 *result = NULL;
140 return -1;
143 utmp_convert64to32 (out64p, buffer);
144 *result = buffer;
146 return 0;
148 symbol_version (getutid32_r, getutid_r, GLIBC_2.0);
151 getutline32_r (const struct utmp32 *line,
152 struct utmp32 *buffer, struct utmp32 **result)
154 struct utmp in64;
155 struct utmp out64;
156 struct utmp *out64p;
157 int ret;
159 utmp_convert32to64 (line, &in64);
161 ret = getutline_r (&in64, &out64, &out64p);
162 if (ret == -1)
164 *result = NULL;
165 return -1;
168 utmp_convert64to32 (out64p, buffer);
169 *result = buffer;
171 return 0;
174 symbol_version (getutline32_r, getutline_r, GLIBC_2.0);
176 /* Append entry UTMP to the wtmp-like file WTMP_FILE. */
177 void
178 updwtmp32 (const char *wtmp_file, const struct utmp32 *utmp)
180 struct utmp in32;
182 utmp_convert32to64 (utmp, &in32);
183 updwtmp (wtmp_file, &in32);
185 symbol_version (updwtmp32, updwtmp, GLIBC_2.0);