]>
Commit | Line | Data |
---|---|---|
8a523922 UD |
1 | /* Copyright (C) 1996 Free Software Foundation, Inc. |
2 | This file is part of the GNU C Library. | |
3 | Contributed by Ulrich Drepper <drepper@cygnus.com> | |
4 | and Paul Janzen <pcj@primenet.com>, 1996. | |
5 | ||
6 | The GNU C Library is free software; you can redistribute it and/or | |
7 | modify it under the terms of the GNU Library General Public License as | |
8 | published by the Free Software Foundation; either version 2 of the | |
9 | License, or (at your option) any later version. | |
10 | ||
11 | The GNU C Library is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | Library General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU Library General Public | |
17 | License along with the GNU C Library; see the file COPYING.LIB. If not, | |
18 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
19 | Boston, MA 02111-1307, USA. */ | |
20 | ||
21 | #include <assert.h> | |
22 | #include <db.h> | |
23 | #include <fcntl.h> | |
24 | #include <stdio.h> | |
25 | #include <stdlib.h> | |
26 | #include <string.h> | |
27 | #include <utmp.h> | |
28 | #include <sys/stat.h> | |
29 | ||
30 | #include "utmp-private.h" | |
31 | ||
32 | ||
33 | /* This is the default name. */ | |
34 | static const char default_file_name[] = _PATH_UTMP_DB; | |
35 | ||
36 | /* Current file name. */ | |
37 | static const char *file_name = (const char *) default_file_name; | |
38 | ||
39 | /* Descriptor for database. */ | |
01c901a5 | 40 | #if 0 |
5b826692 | 41 | /* XXX One day this will become meaningful again. */ |
8a523922 UD |
42 | static DB *db_fd; |
43 | static char last_date[16]; | |
01c901a5 | 44 | #endif |
8a523922 UD |
45 | |
46 | /* Our local functions. */ | |
47 | static int setutent_db (int reset); | |
48 | static void endutent_db (void); | |
49 | static int utmpname_db (const char *name); | |
50 | ||
51 | ||
52 | /* The jump table for the local functions. */ | |
53 | struct utfuncs __libc_utmp_db_functions = | |
54 | { | |
55 | setutent_db, | |
56 | NULL, | |
57 | NULL, | |
58 | NULL, | |
59 | NULL, | |
60 | endutent_db, | |
61 | utmpname_db | |
62 | }; | |
63 | ||
64 | ||
65 | static int | |
66 | setutent_db (int reset) | |
67 | { | |
68 | return 0; | |
69 | } | |
70 | ||
71 | ||
72 | static void | |
73 | endutent_db (void) | |
74 | { | |
75 | } | |
76 | ||
77 | ||
78 | static int | |
79 | utmpname_db (const char *name) | |
80 | { | |
81 | if (strcmp (name, file_name) != 0) | |
82 | { | |
83 | if (strcmp (name, default_file_name) == 0) | |
84 | { | |
85 | if (file_name != default_file_name) | |
86 | free ((char *) file_name); | |
87 | ||
88 | file_name = default_file_name; | |
89 | } | |
90 | else | |
91 | { | |
92 | char *new_name = __strdup (name); | |
93 | if (new_name == NULL) | |
94 | /* Out of memory. */ | |
95 | return -1; | |
96 | ||
97 | if (file_name != default_file_name) | |
98 | free ((char *) file_name); | |
99 | ||
100 | file_name = new_name; | |
101 | } | |
102 | } | |
103 | return 0; | |
104 | } |