Switch to NetBSD utmp.c.
Change-Id: Ibe94888aa48b5b28fea97fd5719a1ed7a23ddeb3
diff --git a/libc/Android.mk b/libc/Android.mk
index d27d204..c9f94a3 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -82,7 +82,6 @@
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 @@
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 c3b55da..9fb0799 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 <sys/cdefs.h>
+#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 <sys/types.h>
#include <sys/param.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <utmp.h>
+#include <sys/stat.h>
static struct utmp utmp;
static FILE *ut;
@@ -58,11 +59,23 @@
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;
}