diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2002-05-02 12:30:31 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2002-05-02 12:30:31 +0000 |
commit | b1447beb261d94b25472e24ba6b93ef2c32dea9e (patch) | |
tree | c3c3c82b9c7caf5338691ad7b494467a647eeee0 /lib/utmp.c | |
parent | 1d9d8dbc9cb4531aed8702e37de58bc2665beb07 (diff) | |
download | mailutils-b1447beb261d94b25472e24ba6b93ef2c32dea9e.tar.gz mailutils-b1447beb261d94b25472e24ba6b93ef2c32dea9e.tar.bz2 |
Replacements for {set,get,end}utent calls.
Diffstat (limited to 'lib/utmp.c')
-rw-r--r-- | lib/utmp.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/utmp.c b/lib/utmp.c new file mode 100644 index 000000000..8ae280744 --- /dev/null +++ b/lib/utmp.c @@ -0,0 +1,57 @@ +/* utmp.c -- Replacements for {set,get,end}utmp functions + +Copyright (C) 2002 Free Software Foundation, Inc. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#include <utmp.h> +#include <fcntl.h> +#include <unistd.h> +#include <string.h> +#include <stdio.h> + +static char *utmp_name = _PATH_UTMP; +static int fd = -1; +static struct utmp ut; + +void +setutent () +{ + endutent (); + if ((fd = open (utmp_name, O_RDWR)) < 0 + && ((fd = open (utmp_name, O_RDONLY)) < 0)) + perror ("setutent: Can't open utmp file"); +} + +void +endutent () +{ + if (fd > 0) + close (fd); + fd = -1; +} + +struct utmp * +getutent () +{ + if (fd < 0) + setutent (); + + if (fd < 0 || read (fd, &ut, sizeof ut) != sizeof ut) + return NULL; + + return &ut; +} + |