1 /* Copyright (C) 1996-2024 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 <https://www.gnu.org/licenses/>. */
19 #include <libc-lock.h>
21 #include <set-freeres.h>
25 /*******************************************************************\
26 |* Here we assume several symbols to be defined: *|
28 |* LOOKUP_TYPE - the return type of the function *|
30 |* GETFUNC_NAME - name of the non-reentrant getXXXent function *|
32 |* BUFLEN - size of static buffer *|
34 |* Optionally the following vars can be defined: *|
36 |* NEED_H_ERRNO - an extra parameter will be passed to point to *|
37 |* the global `h_errno' variable. *|
39 \*******************************************************************/
41 /* To make the real sources a bit prettier. */
42 #define REENTRANT_GETNAME APPEND_R (GETFUNC_NAME)
43 #define APPEND_R(name) APPEND_R1 (name)
44 #define APPEND_R1(name) name##_r
45 #define INTERNAL(name) INTERNAL1 (name)
46 #define INTERNAL1(name) __##name
47 #define APPEND_FREEMEM_NAME1(name) __libc_##name##_freemem_ptr
48 #define APPEND_FREEMEM_NAME(name) APPEND_FREEMEM_NAME1(name)
49 #define FREEMEM_NAME APPEND_FREEMEM_NAME (GETFUNC_NAME)
51 /* Sometimes we need to store error codes in the `h_errno' variable. */
53 # define H_ERRNO_PARM , int *h_errnop
54 # define H_ERRNO_VAR &h_errno
57 # define H_ERRNO_VAR NULL
60 /* Prototype of the reentrant version. */
61 extern int INTERNAL (REENTRANT_GETNAME
) (LOOKUP_TYPE
*resbuf
, char *buffer
,
62 size_t buflen
, LOOKUP_TYPE
**result
63 H_ERRNO_PARM
) attribute_hidden
;
65 /* We need to protect the dynamic buffer handling. */
66 __libc_lock_define_initialized (static, lock
);
68 /* This points to the static buffer used. */
71 weak_alias (buffer
, FREEMEM_NAME
)
76 static size_t buffer_size
;
86 __libc_lock_lock (lock
);
88 result
= (LOOKUP_TYPE
*)
89 __nss_getent ((getent_r_function
) INTERNAL (REENTRANT_GETNAME
),
90 &resbuf
.ptr
, &buffer
, BUFLEN
, &buffer_size
,
94 __libc_lock_unlock (lock
);
99 nss_interface_function (GETFUNC_NAME
)