VM: simplify slab allocator
[minix.git] / lib / libc / compat / gen / compat_utmpx.c
blob44784a26850b6d05b91b1f06bd255405cb624488
1 /* $NetBSD: compat_utmpx.c,v 1.3 2009/01/11 02:46:25 christos Exp $ */
3 /*-
4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
33 #if defined(LIBC_SCCS) && !defined(lint)
34 __RCSID("$NetBSD: compat_utmpx.c,v 1.3 2009/01/11 02:46:25 christos Exp $");
35 #endif /* LIBC_SCCS and not lint */
37 #include "namespace.h"
38 #include <sys/types.h>
39 #include <sys/param.h>
41 #define __LIBC12_SOURCE__
42 #include <assert.h>
43 #include <sys/time.h>
44 #include <string.h>
45 #include <compat/sys/time.h>
46 #include <utmpx.h>
47 #include <compat/include/utmpx.h>
49 __warn_references(getutxent,
50 "warning: reference to compatibility getutxent(); include <utmpx.h> for correct reference")
51 __warn_references(getutxid,
52 "warning: reference to compatibility getutxid(); include <utmpx.h> for correct reference")
53 __warn_references(getutxline,
54 "warning: reference to compatibility getutxline(); include <utmpx.h> for correct reference")
55 __warn_references(pututxline,
56 "warning: reference to compatibility pututxline(); include <utmpx.h> for correct reference")
57 __warn_references(updwtmpx,
58 "warning: reference to compatibility updwtmpx(); include <utmpx.h> for correct reference")
59 __warn_references(getlastlogx,
60 "warning: reference to compatibility getlastlogx(); include <utmpx.h> for correct reference")
61 __warn_references(updlastlogx,
62 "warning: reference to compatibility updlastlogx(); include <utmpx.h> for correct reference")
63 __warn_references(getutmp,
64 "warning: reference to compatibility getutmp(); include <utmpx.h> for correct reference")
65 __warn_references(getutmpx,
66 "warning: reference to compatibility getutmpx(); include <utmpx.h> for correct reference")
68 static struct utmpx50 *
69 cvt(struct utmpx *ut)
71 if (ut == NULL)
72 return NULL;
73 timeval_to_timeval50(&ut->ut_tv, (void *)&ut->ut_tv);
74 return (void *)ut;
77 static void
78 lastlogx50_to_lastlogx(const struct lastlogx50 *ll50, struct lastlogx *ll)
80 (void)memcpy(ll->ll_line, ll50->ll_line, sizeof(ll->ll_line));
81 (void)memcpy(ll->ll_host, ll50->ll_host, sizeof(ll->ll_host));
82 (void)memcpy(&ll->ll_ss, &ll50->ll_ss, sizeof(&ll->ll_ss));
83 timeval50_to_timeval(&ll50->ll_tv, &ll->ll_tv);
86 static void
87 lastlogx_to_lastlogx50(const struct lastlogx *ll, struct lastlogx50 *ll50)
89 (void)memcpy(ll50->ll_line, ll->ll_line, sizeof(ll50->ll_line));
90 (void)memcpy(ll50->ll_host, ll->ll_host, sizeof(ll50->ll_host));
91 (void)memcpy(&ll50->ll_ss, &ll->ll_ss, sizeof(&ll50->ll_ss));
92 timeval_to_timeval50(&ll->ll_tv, &ll50->ll_tv);
95 struct utmpx50 *
96 getutxent(void)
98 return cvt(__getutxent50());
101 struct utmpx50 *
102 getutxid(const struct utmpx50 *ut50)
104 struct utmpx ut;
105 utmpx50_to_utmpx(ut50, &ut);
106 return cvt(__getutxid50(&ut));
109 struct utmpx50 *
110 getutxline(const struct utmpx50 *ut50)
112 struct utmpx ut;
113 utmpx50_to_utmpx(ut50, &ut);
114 return cvt(__getutxline50(&ut));
117 struct utmpx50 *
118 pututxline(const struct utmpx50 *ut50)
120 struct utmpx ut;
121 utmpx50_to_utmpx(ut50, &ut);
122 return cvt(__pututxline50(&ut));
126 updwtmpx(const char *fname, const struct utmpx50 *ut50)
128 struct utmpx ut;
129 utmpx50_to_utmpx(ut50, &ut);
130 return __updwtmpx50(fname, &ut);
133 struct lastlogx50 *
134 __getlastlogx13(const char *fname, uid_t uid, struct lastlogx50 *ll50)
136 struct lastlogx ll;
137 if (__getlastlogx50(fname, uid, &ll) == NULL)
138 return NULL;
139 lastlogx_to_lastlogx50(&ll, ll50);
140 return ll50;
143 static char llfile[MAXPATHLEN] = _PATH_LASTLOGX;
146 lastlogxname(const char *fname)
148 size_t len;
150 _DIAGASSERT(fname != NULL);
152 len = strlen(fname);
154 if (len >= sizeof(llfile))
155 return 0;
157 /* must end in x! */
158 if (fname[len - 1] != 'x')
159 return 0;
161 (void)strlcpy(llfile, fname, sizeof(llfile));
162 return 1;
165 struct lastlogx50 *
166 getlastlogx(uid_t uid, struct lastlogx50 *ll)
169 return __getlastlogx13(llfile, uid, ll);
173 updlastlogx(const char *fname, uid_t uid, struct lastlogx50 *ll50)
175 struct lastlogx ll;
176 lastlogx50_to_lastlogx(ll50, &ll);
177 return __updlastlogx50(fname, uid, &ll);
180 void
181 getutmp(const struct utmpx50 *utx50, struct utmp *ut)
183 struct utmpx utx;
184 utmpx50_to_utmpx(utx50, &utx);
185 __getutmp50(&utx, ut);
188 void
189 getutmpx(const struct utmp *ut, struct utmpx50 *utx50)
191 struct utmpx utx;
192 __getutmpx50(ut, &utx);
193 utmpx_to_utmpx50(&utx, utx50);