Replacements for {set,get,end}utent calls.
Showing
1 changed file
with
57 additions
and
0 deletions
lib/utmp.c
0 → 100644
1 | /* utmp.c -- Replacements for {set,get,end}utmp functions | ||
2 | |||
3 | Copyright (C) 2002 Free Software Foundation, Inc. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU General Public License as | ||
7 | published by the Free Software Foundation; either version 2 of the | ||
8 | License, or (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software | ||
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | ||
18 | |||
19 | #include <utmp.h> | ||
20 | #include <fcntl.h> | ||
21 | #include <unistd.h> | ||
22 | #include <string.h> | ||
23 | #include <stdio.h> | ||
24 | |||
25 | static char *utmp_name = _PATH_UTMP; | ||
26 | static int fd = -1; | ||
27 | static struct utmp ut; | ||
28 | |||
29 | void | ||
30 | setutent () | ||
31 | { | ||
32 | endutent (); | ||
33 | if ((fd = open (utmp_name, O_RDWR)) < 0 | ||
34 | && ((fd = open (utmp_name, O_RDONLY)) < 0)) | ||
35 | perror ("setutent: Can't open utmp file"); | ||
36 | } | ||
37 | |||
38 | void | ||
39 | endutent () | ||
40 | { | ||
41 | if (fd > 0) | ||
42 | close (fd); | ||
43 | fd = -1; | ||
44 | } | ||
45 | |||
46 | struct utmp * | ||
47 | getutent () | ||
48 | { | ||
49 | if (fd < 0) | ||
50 | setutent (); | ||
51 | |||
52 | if (fd < 0 || read (fd, &ut, sizeof ut) != sizeof ut) | ||
53 | return NULL; | ||
54 | |||
55 | return &ut; | ||
56 | } | ||
57 |
-
Please register or sign in to post a comment