]>
Commit | Line | Data |
---|---|---|
04277e02 | 1 | /* Copyright (C) 1997-2019 Free Software Foundation, Inc. |
76b87c03 UD |
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 | |
41bdb6e2 AJ |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
76b87c03 UD |
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 | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
76b87c03 | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 16 | License along with the GNU C Library; if not, see |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
76b87c03 | 18 | |
ec999b8e | 19 | #include <libc-lock.h> |
76b87c03 UD |
20 | #include <stdlib.h> |
21 | #include <string.h> | |
22 | #include <utmp.h> | |
23 | ||
24 | #include "utmp-private.h" | |
25 | ||
26 | ||
27 | /* This is the default name. */ | |
28 | static const char default_file_name[] = _PATH_UTMP; | |
29 | ||
30 | /* Current file name. */ | |
31 | const char *__libc_utmp_file_name = (const char *) default_file_name; | |
32 | ||
33 | /* We have to use the lock in getutent_r.c. */ | |
ab26a24a | 34 | __libc_lock_define (extern, __libc_utmp_lock attribute_hidden) |
76b87c03 UD |
35 | |
36 | ||
37 | int | |
38 | __utmpname (const char *file) | |
39 | { | |
40 | int result = -1; | |
41 | ||
42 | __libc_lock_lock (__libc_utmp_lock); | |
43 | ||
44 | /* Close the old file. */ | |
1a7fe2eb | 45 | __libc_endutent (); |
76b87c03 UD |
46 | |
47 | if (strcmp (file, __libc_utmp_file_name) != 0) | |
48 | { | |
49 | if (strcmp (file, default_file_name) == 0) | |
50 | { | |
fa3ac53f | 51 | free ((char *) __libc_utmp_file_name); |
76b87c03 UD |
52 | |
53 | __libc_utmp_file_name = default_file_name; | |
54 | } | |
55 | else | |
56 | { | |
57 | char *file_name = __strdup (file); | |
58 | if (file_name == NULL) | |
59 | /* Out of memory. */ | |
60 | goto done; | |
61 | ||
62 | if (__libc_utmp_file_name != default_file_name) | |
63 | free ((char *) __libc_utmp_file_name); | |
64 | ||
65 | __libc_utmp_file_name = file_name; | |
66 | } | |
67 | } | |
68 | ||
76b87c03 UD |
69 | result = 0; |
70 | ||
71 | done: | |
72 | __libc_lock_unlock (__libc_utmp_lock); | |
73 | return result; | |
74 | } | |
75 | weak_alias (__utmpname, utmpname) |