2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-FileCopyrightText: 1993 - 1994, Julianne Frances Haugh
|
|
|
|
* SPDX-FileCopyrightText: 1996 - 1998, Marek Michałkiewicz
|
|
|
|
* SPDX-FileCopyrightText: 2005 , Tomasz Kłoczko
|
2007-10-07 17:14:02 +05:30
|
|
|
*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifndef HAVE_GETUTENT
|
|
|
|
|
|
|
|
#include "defines.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <utmp.h>
|
|
|
|
|
|
|
|
#ifndef lint
|
2007-11-11 05:16:11 +05:30
|
|
|
static char rcsid[] = "$Id$";
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static int utmp_fd = -1;
|
|
|
|
static struct utmp utmp_buf;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* setutent - open or rewind the utmp file
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
void setutent (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
void endutent (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
if (utmp_fd != -1)
|
|
|
|
close (utmp_fd);
|
|
|
|
|
|
|
|
utmp_fd = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* getutent - get the next record from the utmp file
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
struct utmp *getutent (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
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
|
2007-10-07 17:16:07 +05:30
|
|
|
extern int errno; /* warning: ANSI C forbids an empty source file */
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|