source: trunk/libs/newlib/src/newlib/libc/sys/linux/net/getXXent.c

Last change on this file was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 2.9 KB
Line 
1/* Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
2   This file is part of the GNU C Library.
3
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.
8
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.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with the GNU C Library; if not, write to the Free
16   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17   02111-1307 USA.  */
18
19#include <errno.h>
20#define _IO_MTSAFE_IO
21#include <bits/libc-lock.h>
22#include <stdlib.h>
23
24#include "nsswitch.h"
25
26/*******************************************************************\
27|* Here we assume several symbols to be defined:                   *|
28|*                                                                 *|
29|* LOOKUP_TYPE   - the return type of the function                 *|
30|*                                                                 *|
31|* GETFUNC_NAME  - name of the non-reentrant getXXXent function    *|
32|*                                                                 *|
33|* BUFLEN        - size of static buffer                           *|
34|*                                                                 *|
35|* Optionally the following vars can be defined:                   *|
36|*                                                                 *|
37|* NEED_H_ERRNO  - an extra parameter will be passed to point to   *|
38|*                 the global `h_errno' variable.                  *|
39|*                                                                 *|
40\*******************************************************************/
41
42/* To make the real sources a bit prettier.  */
43#define REENTRANT_GETNAME APPEND_R (GETFUNC_NAME)
44#define APPEND_R(name) APPEND_R1 (name)
45#define APPEND_R1(name) name##_r
46#define INTERNAL(name) INTERNAL1 (name)
47#define INTERNAL1(name) __##name
48
49/* Sometimes we need to store error codes in the `h_errno' variable.  */
50#ifdef NEED_H_ERRNO
51# define H_ERRNO_PARM , int *h_errnop
52# define H_ERRNO_VAR &h_errno
53#else
54# define H_ERRNO_PARM
55# define H_ERRNO_VAR NULL
56#endif
57
58/* Prototype of the reentrant version.  */
59extern int INTERNAL (REENTRANT_GETNAME) (LOOKUP_TYPE *resbuf, char *buffer,
60                                         size_t buflen, LOOKUP_TYPE **result
61                                         H_ERRNO_PARM);
62
63/* We need to protect the dynamic buffer handling.  */
64__libc_lock_define_initialized (static, lock);
65
66/* This points to the static buffer used.  */
67libc_freeres_ptr (static char *buffer);
68
69
70LOOKUP_TYPE *
71GETFUNC_NAME (void)
72{
73  static size_t buffer_size;
74  static union
75  {
76    LOOKUP_TYPE l;
77    void *ptr;
78  } resbuf;
79  LOOKUP_TYPE *result;
80  int save;
81
82  /* Get lock.  */
83  __libc_lock_lock (lock);
84
85  result = (LOOKUP_TYPE *)
86    __nss_getent ((getent_r_function) INTERNAL (REENTRANT_GETNAME),
87                  &resbuf.ptr, &buffer, BUFLEN, &buffer_size,
88                  H_ERRNO_VAR);
89
90  save = errno;
91  __libc_lock_unlock (lock);
92  __set_errno (save);
93  return result;
94}
95
96static_link_warning (GETFUNC_NAME)
Note: See TracBrowser for help on using the repository browser.