Fix up sched.h for XPG7.
[glibc.git] / login / getutent_r.c
blob76cb4cfc88e426f012c03ecf23fd3259be24854d
1 /* Copyright (C) 1996-1998,2000,2001,2002,2004 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 Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the 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 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #include <bits/libc-lock.h>
22 #include <stdlib.h>
23 #include <utmp.h>
25 #include "utmp-private.h"
28 /* Functions defined here. */
29 static int setutent_unknown (void);
30 static int getutent_r_unknown (struct utmp *buffer, struct utmp **result);
31 static int getutid_r_unknown (const struct utmp *line, struct utmp *buffer,
32 struct utmp **result);
33 static int getutline_r_unknown (const struct utmp *id, struct utmp *buffer,
34 struct utmp **result);
35 static struct utmp *pututline_unknown (const struct utmp *data);
36 static void endutent_unknown (void);
38 /* Initial Jump table. */
39 const struct utfuncs __libc_utmp_unknown_functions =
41 setutent_unknown,
42 getutent_r_unknown,
43 getutid_r_unknown,
44 getutline_r_unknown,
45 pututline_unknown,
46 endutent_unknown,
47 NULL
50 /* Currently selected backend. */
51 const struct utfuncs *__libc_utmp_jump_table = &__libc_utmp_unknown_functions;
53 /* We need to protect the opening of the file. */
54 __libc_lock_define_initialized (, __libc_utmp_lock attribute_hidden)
57 static int
58 setutent_unknown (void)
60 int result;
62 result = (*__libc_utmp_file_functions.setutent) ();
63 if (result)
64 __libc_utmp_jump_table = &__libc_utmp_file_functions;
66 return result;
70 static int
71 getutent_r_unknown (struct utmp *buffer, struct utmp **result)
73 /* The backend was not yet initialized. */
74 if (setutent_unknown ())
75 return (*__libc_utmp_jump_table->getutent_r) (buffer, result);
77 /* Not available. */
78 *result = NULL;
79 return -1;
83 static int
84 getutid_r_unknown (const struct utmp *id, struct utmp *buffer,
85 struct utmp **result)
87 /* The backend was not yet initialized. */
88 if (setutent_unknown ())
89 return (*__libc_utmp_jump_table->getutid_r) (id, buffer, result);
91 /* Not available. */
92 *result = NULL;
93 return -1;
97 static int
98 getutline_r_unknown (const struct utmp *line, struct utmp *buffer,
99 struct utmp **result)
101 /* The backend was not yet initialized. */
102 if (setutent_unknown ())
103 return (*__libc_utmp_jump_table->getutline_r) (line, buffer, result);
105 /* Not available. */
106 *result = NULL;
107 return -1;
111 static struct utmp *
112 pututline_unknown (const struct utmp *data)
114 /* The backend was not yet initialized. */
115 if (setutent_unknown ())
116 return (*__libc_utmp_jump_table->pututline) (data);
118 /* Not available. */
119 return NULL;
123 static void
124 endutent_unknown (void)
126 /* Nothing to do. */
130 void
131 __setutent (void)
133 __libc_lock_lock (__libc_utmp_lock);
135 (*__libc_utmp_jump_table->setutent) ();
137 __libc_lock_unlock (__libc_utmp_lock);
139 weak_alias (__setutent, setutent)
143 __getutent_r (struct utmp *buffer, struct utmp **result)
145 int retval;
147 __libc_lock_lock (__libc_utmp_lock);
149 retval = (*__libc_utmp_jump_table->getutent_r) (buffer, result);
151 __libc_lock_unlock (__libc_utmp_lock);
153 return retval;
155 weak_alias (__getutent_r, getutent_r)
158 struct utmp *
159 __pututline (const struct utmp *data)
161 struct utmp *buffer;
163 __libc_lock_lock (__libc_utmp_lock);
165 buffer = (*__libc_utmp_jump_table->pututline) (data);
167 __libc_lock_unlock (__libc_utmp_lock);
169 return buffer;
171 weak_alias (__pututline, pututline)
174 void
175 __endutent (void)
177 __libc_lock_lock (__libc_utmp_lock);
179 (*__libc_utmp_jump_table->endutent) ();
180 __libc_utmp_jump_table = &__libc_utmp_unknown_functions;
182 __libc_lock_unlock (__libc_utmp_lock);
184 weak_alias (__endutent, endutent)