]> sourceware.org Git - glibc.git/blob - login/utmpname.c
Update.
[glibc.git] / login / utmpname.c
1 /* Copyright (C) 1997 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library 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 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20 #include <bits/libc-lock.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <utmp.h>
24
25 #include "utmp-private.h"
26
27
28 /* This is the default name. */
29 static const char default_file_name[] = _PATH_UTMP;
30
31 /* Current file name. */
32 const char *__libc_utmp_file_name = (const char *) default_file_name;
33
34 /* We have to use the lock in getutent_r.c. */
35 __libc_lock_define (extern, __libc_utmp_lock)
36
37
38 int
39 __utmpname (const char *file)
40 {
41 int result = -1;
42
43 __libc_lock_lock (__libc_utmp_lock);
44
45 /* Close the old file. */
46 (*__libc_utmp_jump_table->endutent) ();
47 __libc_utmp_jump_table = &__libc_utmp_unknown_functions;
48
49 if (strcmp (file, __libc_utmp_file_name) != 0)
50 {
51 if (strcmp (file, default_file_name) == 0)
52 {
53 if (__libc_utmp_file_name != default_file_name)
54 free ((char *) __libc_utmp_file_name);
55
56 __libc_utmp_file_name = default_file_name;
57 }
58 else
59 {
60 char *file_name = __strdup (file);
61 if (file_name == NULL)
62 /* Out of memory. */
63 goto done;
64
65 if (__libc_utmp_file_name != default_file_name)
66 free ((char *) __libc_utmp_file_name);
67
68 __libc_utmp_file_name = file_name;
69 }
70 }
71
72 result = 0;
73
74 done:
75 __libc_lock_unlock (__libc_utmp_lock);
76 return result;
77 }
78 weak_alias (__utmpname, utmpname)
This page took 0.036043 seconds and 5 git commands to generate.