From 97c26c1924b076ef23ebe4381558e8aa025712b2 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 16:54:37 +0200 Subject: Adding upstream version 1:4.13+dfsg1. Signed-off-by: Daniel Baumann --- lib/utent.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 lib/utent.c (limited to 'lib/utent.c') diff --git a/lib/utent.c b/lib/utent.c new file mode 100644 index 0000000..d5e6dae --- /dev/null +++ b/lib/utent.c @@ -0,0 +1,70 @@ +/* + * SPDX-FileCopyrightText: 1993 - 1994, Julianne Frances Haugh + * SPDX-FileCopyrightText: 1996 - 1998, Marek Michałkiewicz + * SPDX-FileCopyrightText: 2005 , Tomasz Kłoczko + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include + +#ifndef HAVE_GETUTENT + +#include "defines.h" +#include +#include +#include + +#ifndef lint +static char rcsid[] = "$Id$"; +#endif + +static int utmp_fd = -1; +static struct utmp utmp_buf; + +/* + * setutent - open or rewind the utmp file + */ + +void setutent (void) +{ + if (utmp_fd == -1) + if ((utmp_fd = open (_UTMP_FILE, O_RDWR)) == -1) + utmp_fd = open (_UTMP_FILE, O_RDONLY); + + if (utmp_fd != -1) + lseek (utmp_fd, (off_t) 0L, SEEK_SET); +} + +/* + * endutent - close the utmp file + */ + +void endutent (void) +{ + if (utmp_fd != -1) + close (utmp_fd); + + utmp_fd = -1; +} + +/* + * getutent - get the next record from the utmp file + */ + +struct utmp *getutent (void) +{ + if (utmp_fd == -1) + setutent (); + + if (utmp_fd == -1) + return 0; + + if (read (utmp_fd, &utmp_buf, sizeof utmp_buf) != sizeof utmp_buf) + return 0; + + return &utmp_buf; +} +#else +extern int errno; /* warning: ANSI C forbids an empty source file */ +#endif -- cgit v1.2.3