From 19f58efa22357bfaa6a63a0940928830e95c5123 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Mon, 10 Mar 2014 16:32:35 -0700 Subject: [PATCH] Switch to NetBSD utmp.c. Change-Id: Ibe94888aa48b5b28fea97fd5719a1ed7a23ddeb3 --- libc/Android.mk | 2 +- .../lib/libc/gen}/utmp.c | 29 ++++++++++++++----- 2 files changed, 22 insertions(+), 9 deletions(-) rename libc/{bionic => upstream-netbsd/lib/libc/gen}/utmp.c (79%) diff --git a/libc/Android.mk b/libc/Android.mk index d27d2047f..c9f94a315 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -82,7 +82,6 @@ libc_common_src_files := \ bionic/time64.c \ bionic/umount.c \ bionic/unlockpt.c \ - bionic/utmp.c \ stdio/asprintf.c \ stdio/findfp.c \ stdio/fprintf.c \ @@ -279,6 +278,7 @@ libc_upstream_netbsd_src_files := \ upstream-netbsd/lib/libc/gen/psignal.c \ upstream-netbsd/lib/libc/gen/setjmperr.c \ upstream-netbsd/lib/libc/gen/utime.c \ + upstream-netbsd/lib/libc/gen/utmp.c \ upstream-netbsd/lib/libc/inet/inet_ntoa.c \ upstream-netbsd/lib/libc/inet/inet_ntop.c \ upstream-netbsd/lib/libc/inet/inet_pton.c \ diff --git a/libc/bionic/utmp.c b/libc/upstream-netbsd/lib/libc/gen/utmp.c similarity index 79% rename from libc/bionic/utmp.c rename to libc/upstream-netbsd/lib/libc/gen/utmp.c index c3b55da82..9fb0799db 100644 --- a/libc/bionic/utmp.c +++ b/libc/upstream-netbsd/lib/libc/gen/utmp.c @@ -1,3 +1,5 @@ +/* $NetBSD: utmp.c,v 1.10 2011/10/15 23:00:02 christos Exp $ */ + /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. * All rights reserved. @@ -13,13 +15,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED @@ -35,12 +30,18 @@ */ #include +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: utmp.c,v 1.10 2011/10/15 23:00:02 christos Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" #include #include #include #include #include #include +#include static struct utmp utmp; static FILE *ut; @@ -58,11 +59,23 @@ struct utmp * getutent(void) { if (ut == NULL) { - if ((ut = fopen(utfile, "r")) == NULL) + struct stat st; + off_t numentries; + if ((ut = fopen(utfile, "re")) == NULL) return NULL; + if (fstat(fileno(ut), &st) == -1) + goto out; + /* + * If we have a an old version utmp file bail. + */ + numentries = st.st_size / sizeof(utmp); + if ((off_t)(numentries * sizeof(utmp)) != st.st_size) + goto out; } if (fread(&utmp, sizeof(utmp), 1, ut) == 1) return &utmp; +out: + (void)fclose(ut); return NULL; }