]>
Commit | Line | Data |
---|---|---|
04277e02 | 1 | /* Copyright (C) 1996-2019 Free Software Foundation, Inc. |
26761c28 | 2 | This file is part of the GNU C Library. |
5f0e6fc7 | 3 | |
26761c28 | 4 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
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. | |
5f0e6fc7 | 8 | |
26761c28 UD |
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 | |
41bdb6e2 | 12 | Lesser General Public License for more details. |
5f0e6fc7 | 13 | |
41bdb6e2 | 14 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 15 | License along with the GNU C Library; if not, see |
5a82c748 | 16 | <https://www.gnu.org/licenses/>. */ |
26761c28 UD |
17 | |
18 | #include <errno.h> | |
ec999b8e | 19 | #include <libc-lock.h> |
26761c28 | 20 | #include <stdlib.h> |
5f0e6fc7 RM |
21 | |
22 | #include "nsswitch.h" | |
23 | ||
24 | /*******************************************************************\ | |
25 | |* Here we assume several symbols to be defined: *| | |
6b9fecdc | 26 | |* *| |
5f0e6fc7 | 27 | |* LOOKUP_TYPE - the return type of the function *| |
6b9fecdc | 28 | |* *| |
5f0e6fc7 | 29 | |* GETFUNC_NAME - name of the non-reentrant getXXXent function *| |
6b9fecdc | 30 | |* *| |
5f0e6fc7 | 31 | |* BUFLEN - size of static buffer *| |
6b9fecdc | 32 | |* *| |
5f0e6fc7 | 33 | |* Optionally the following vars can be defined: *| |
6b9fecdc | 34 | |* *| |
5f0e6fc7 RM |
35 | |* NEED_H_ERRNO - an extra parameter will be passed to point to *| |
36 | |* the global `h_errno' variable. *| | |
6b9fecdc | 37 | |* *| |
5f0e6fc7 RM |
38 | \*******************************************************************/ |
39 | ||
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 | |
23396375 UD |
44 | #define INTERNAL(name) INTERNAL1 (name) |
45 | #define INTERNAL1(name) __##name | |
5f0e6fc7 RM |
46 | |
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 | |
8b801829 | 50 | # define H_ERRNO_VAR &h_errno |
5f0e6fc7 RM |
51 | #else |
52 | # define H_ERRNO_PARM | |
8b801829 | 53 | # define H_ERRNO_VAR NULL |
5f0e6fc7 RM |
54 | #endif |
55 | ||
56 | /* Prototype of the reentrant version. */ | |
ba1ffaa1 UD |
57 | extern int INTERNAL (REENTRANT_GETNAME) (LOOKUP_TYPE *resbuf, char *buffer, |
58 | size_t buflen, LOOKUP_TYPE **result | |
1dbbb1ec | 59 | H_ERRNO_PARM) attribute_hidden; |
5f0e6fc7 | 60 | |
26761c28 UD |
61 | /* We need to protect the dynamic buffer handling. */ |
62 | __libc_lock_define_initialized (static, lock); | |
63 | ||
d60d215c | 64 | /* This points to the static buffer used. */ |
c877418f | 65 | libc_freeres_ptr (static char *buffer); |
d60d215c | 66 | |
5f0e6fc7 RM |
67 | |
68 | LOOKUP_TYPE * | |
69 | GETFUNC_NAME (void) | |
70 | { | |
26761c28 | 71 | static size_t buffer_size; |
fb776f3e AJ |
72 | static union |
73 | { | |
74 | LOOKUP_TYPE l; | |
75 | void *ptr; | |
76 | } resbuf; | |
22d57dd3 | 77 | LOOKUP_TYPE *result; |
26761c28 UD |
78 | int save; |
79 | ||
80 | /* Get lock. */ | |
81 | __libc_lock_lock (lock); | |
82 | ||
8b801829 UD |
83 | result = (LOOKUP_TYPE *) |
84 | __nss_getent ((getent_r_function) INTERNAL (REENTRANT_GETNAME), | |
fb776f3e | 85 | &resbuf.ptr, &buffer, BUFLEN, &buffer_size, |
8b801829 | 86 | H_ERRNO_VAR); |
26761c28 | 87 | |
26761c28 UD |
88 | save = errno; |
89 | __libc_lock_unlock (lock); | |
90 | __set_errno (save); | |
ba1ffaa1 | 91 | return result; |
5f0e6fc7 | 92 | } |
2f7f7bc6 | 93 | |
01767843 | 94 | nss_interface_function (GETFUNC_NAME) |