x86: Don't check XFD against /proc/cpuinfo
[glibc.git] / nss / getXXent.c
blob46a527316db583b27c2537d3098a2fd17534c961
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/>. */
18 #include <errno.h>
19 #include <libc-lock.h>
20 #include <stdlib.h>
21 #include <set-freeres.h>
23 #include "nsswitch.h"
25 /*******************************************************************\
26 |* Here we assume several symbols to be defined: *|
27 |* *|
28 |* LOOKUP_TYPE - the return type of the function *|
29 |* *|
30 |* GETFUNC_NAME - name of the non-reentrant getXXXent function *|
31 |* *|
32 |* BUFLEN - size of static buffer *|
33 |* *|
34 |* Optionally the following vars can be defined: *|
35 |* *|
36 |* NEED_H_ERRNO - an extra parameter will be passed to point to *|
37 |* the global `h_errno' variable. *|
38 |* *|
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. */
52 #ifdef NEED_H_ERRNO
53 # define H_ERRNO_PARM , int *h_errnop
54 # define H_ERRNO_VAR &h_errno
55 #else
56 # define H_ERRNO_PARM
57 # define H_ERRNO_VAR NULL
58 #endif
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. */
69 static char *buffer;
71 weak_alias (buffer, FREEMEM_NAME)
73 LOOKUP_TYPE *
74 GETFUNC_NAME (void)
76 static size_t buffer_size;
77 static union
79 LOOKUP_TYPE l;
80 void *ptr;
81 } resbuf;
82 LOOKUP_TYPE *result;
83 int save;
85 /* Get lock. */
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,
91 H_ERRNO_VAR);
93 save = errno;
94 __libc_lock_unlock (lock);
95 __set_errno (save);
96 return result;
99 nss_interface_function (GETFUNC_NAME)