manual: Sort overview listing by manual order.
[glibc.git] / nss / getXXent.c
blob609650e2722f7e32e24a7f0ec22edd436497bd5d
1 /* Copyright (C) 1996-2014 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
18 #include <errno.h>
19 #include <bits/libc-lock.h>
20 #include <stdlib.h>
22 #include "nsswitch.h"
24 /*******************************************************************\
25 |* Here we assume several symbols to be defined: *|
26 |* *|
27 |* LOOKUP_TYPE - the return type of the function *|
28 |* *|
29 |* GETFUNC_NAME - name of the non-reentrant getXXXent function *|
30 |* *|
31 |* BUFLEN - size of static buffer *|
32 |* *|
33 |* Optionally the following vars can be defined: *|
34 |* *|
35 |* NEED_H_ERRNO - an extra parameter will be passed to point to *|
36 |* the global `h_errno' variable. *|
37 |* *|
38 \*******************************************************************/
40 /* To make the real sources a bit prettier. */
41 #define REENTRANT_GETNAME APPEND_R (GETFUNC_NAME)
42 #define APPEND_R(name) APPEND_R1 (name)
43 #define APPEND_R1(name) name##_r
44 #define INTERNAL(name) INTERNAL1 (name)
45 #define INTERNAL1(name) __##name
47 /* Sometimes we need to store error codes in the `h_errno' variable. */
48 #ifdef NEED_H_ERRNO
49 # define H_ERRNO_PARM , int *h_errnop
50 # define H_ERRNO_VAR &h_errno
51 #else
52 # define H_ERRNO_PARM
53 # define H_ERRNO_VAR NULL
54 #endif
56 /* Prototype of the reentrant version. */
57 extern int INTERNAL (REENTRANT_GETNAME) (LOOKUP_TYPE *resbuf, char *buffer,
58 size_t buflen, LOOKUP_TYPE **result
59 H_ERRNO_PARM);
61 /* We need to protect the dynamic buffer handling. */
62 __libc_lock_define_initialized (static, lock);
64 /* This points to the static buffer used. */
65 libc_freeres_ptr (static char *buffer);
68 LOOKUP_TYPE *
69 GETFUNC_NAME (void)
71 static size_t buffer_size;
72 static union
74 LOOKUP_TYPE l;
75 void *ptr;
76 } resbuf;
77 LOOKUP_TYPE *result;
78 int save;
80 /* Get lock. */
81 __libc_lock_lock (lock);
83 result = (LOOKUP_TYPE *)
84 __nss_getent ((getent_r_function) INTERNAL (REENTRANT_GETNAME),
85 &resbuf.ptr, &buffer, BUFLEN, &buffer_size,
86 H_ERRNO_VAR);
88 save = errno;
89 __libc_lock_unlock (lock);
90 __set_errno (save);
91 return result;
94 nss_interface_function (GETFUNC_NAME)