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>, 1996.
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.
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.
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
17 not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
26 /* This is the default name. */
27 static const char default_utmp_name
[] = _PATH_UTMP
;
29 /* Current file name. */
30 static const char *utmp_file_name
= (const char *) default_utmp_name
;
34 __setutent_r (struct utmp_data
*utmp_data
)
36 /* Before the UTMP_DATA is used before the first time the UT_FD
37 field must be set to -1. */
38 if (utmp_data
->ut_fd
== -1)
40 utmp_data
->ut_fd
= open (utmp_file_name
, O_RDWR
);
41 if (utmp_data
->ut_fd
== -1)
43 /* Hhm, read-write access did not work. Try read-only. */
44 utmp_data
->ut_fd
= open (utmp_file_name
, O_RDONLY
);
45 if (utmp_data
->ut_fd
== -1)
47 perror (_("while opening UTMP file"));
53 /* Remember we are at beginning of file. */
54 utmp_data
->loc_utmp
= 0;
56 utmp_data
->ubuf
.ut_type
= UT_UNKNOWN
;
59 weak_alias (__setutent_r
, setutent_r
)
63 __utmpname (const char *file
)
65 char *fname
= __strdup (file
);
69 if (utmp_file_name
!= default_utmp_name
)
70 free ((void *) utmp_file_name
);
72 utmp_file_name
= fname
;
76 weak_alias (__utmpname
, utmpname
)