update from main archive 970124
[glibc.git] / login / utmp_db.c
blobfa0e29a52ea90a456db743b4fbf7ec929c841966
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.
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.
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.
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. */
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>
30 #include "utmp-private.h"
33 /* This is the default name. */
34 static const char default_file_name[] = _PATH_UTMP_DB;
36 /* Current file name. */
37 static const char *file_name = (const char *) default_file_name;
39 /* Descriptor for database. */
40 #if 0
41 /* XXX One day this will become meaningful again. */
42 static DB *db_fd;
43 static char last_date[16];
44 #endif
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);
52 /* The jump table for the local functions. */
53 struct utfuncs __libc_utmp_db_functions =
55 setutent_db,
56 NULL,
57 NULL,
58 NULL,
59 NULL,
60 endutent_db,
61 utmpname_db
65 static int
66 setutent_db (int reset)
68 return 0;
72 static void
73 endutent_db (void)
78 static int
79 utmpname_db (const char *name)
81 if (strcmp (name, file_name) != 0)
83 if (strcmp (name, default_file_name) == 0)
85 if (file_name != default_file_name)
86 free ((char *) file_name);
88 file_name = default_file_name;
90 else
92 char *new_name = __strdup (name);
93 if (new_name == NULL)
94 /* Out of memory. */
95 return -1;
97 if (file_name != default_file_name)
98 free ((char *) file_name);
100 file_name = new_name;
103 return 0;