nss_dns: Remove dead PTR IPv4-to-IPv6 mapping code
[glibc.git] / login / utmpname.c
blob74a4caf71b0d2340fd7b860cdb1cdaf885a4ec5a
1 /* Copyright (C) 1997-2017 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
5 The GNU C Library is free software; you can redistribute it and/or
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.
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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <libc-lock.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <utmp.h>
24 #include "utmp-private.h"
27 /* This is the default name. */
28 static const char default_file_name[] = _PATH_UTMP;
30 /* Current file name. */
31 const char *__libc_utmp_file_name = (const char *) default_file_name;
33 /* We have to use the lock in getutent_r.c. */
34 __libc_lock_define (extern, __libc_utmp_lock attribute_hidden)
37 int
38 __utmpname (const char *file)
40 int result = -1;
42 __libc_lock_lock (__libc_utmp_lock);
44 /* Close the old file. */
45 (*__libc_utmp_jump_table->endutent) ();
46 __libc_utmp_jump_table = &__libc_utmp_unknown_functions;
48 if (strcmp (file, __libc_utmp_file_name) != 0)
50 if (strcmp (file, default_file_name) == 0)
52 free ((char *) __libc_utmp_file_name);
54 __libc_utmp_file_name = default_file_name;
56 else
58 char *file_name = __strdup (file);
59 if (file_name == NULL)
60 /* Out of memory. */
61 goto done;
63 if (__libc_utmp_file_name != default_file_name)
64 free ((char *) __libc_utmp_file_name);
66 __libc_utmp_file_name = file_name;
70 result = 0;
72 done:
73 __libc_lock_unlock (__libc_utmp_lock);
74 return result;
76 weak_alias (__utmpname, utmpname)