hjl / source-git / glibc

Forked from source-git/glibc 3 years ago
Clone

Blame nss/getXXent.c

Packit 6c4009
/* Copyright (C) 1996-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <errno.h>
Packit 6c4009
#include <libc-lock.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
Packit 6c4009
#include "nsswitch.h"
Packit 6c4009
Packit 6c4009
/*******************************************************************\
Packit 6c4009
|* Here we assume several symbols to be defined:		   *|
Packit 6c4009
|*								   *|
Packit 6c4009
|* LOOKUP_TYPE   - the return type of the function		   *|
Packit 6c4009
|*								   *|
Packit 6c4009
|* GETFUNC_NAME  - name of the non-reentrant getXXXent function	   *|
Packit 6c4009
|*								   *|
Packit 6c4009
|* BUFLEN	 - size of static buffer			   *|
Packit 6c4009
|*								   *|
Packit 6c4009
|* Optionally the following vars can be defined:		   *|
Packit 6c4009
|*								   *|
Packit 6c4009
|* NEED_H_ERRNO  - an extra parameter will be passed to point to   *|
Packit 6c4009
|*		   the global `h_errno' variable.		   *|
Packit 6c4009
|*								   *|
Packit 6c4009
\*******************************************************************/
Packit 6c4009
Packit 6c4009
/* To make the real sources a bit prettier.  */
Packit 6c4009
#define REENTRANT_GETNAME APPEND_R (GETFUNC_NAME)
Packit 6c4009
#define APPEND_R(name) APPEND_R1 (name)
Packit 6c4009
#define APPEND_R1(name) name##_r
Packit 6c4009
#define INTERNAL(name) INTERNAL1 (name)
Packit 6c4009
#define INTERNAL1(name) __##name
Packit 6c4009
Packit 6c4009
/* Sometimes we need to store error codes in the `h_errno' variable.  */
Packit 6c4009
#ifdef NEED_H_ERRNO
Packit 6c4009
# define H_ERRNO_PARM , int *h_errnop
Packit 6c4009
# define H_ERRNO_VAR &h_errno
Packit 6c4009
#else
Packit 6c4009
# define H_ERRNO_PARM
Packit 6c4009
# define H_ERRNO_VAR NULL
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
/* Prototype of the reentrant version.  */
Packit 6c4009
extern int INTERNAL (REENTRANT_GETNAME) (LOOKUP_TYPE *resbuf, char *buffer,
Packit 6c4009
					 size_t buflen, LOOKUP_TYPE **result
Packit 6c4009
					 H_ERRNO_PARM) attribute_hidden;
Packit 6c4009
Packit 6c4009
/* We need to protect the dynamic buffer handling.  */
Packit 6c4009
__libc_lock_define_initialized (static, lock);
Packit 6c4009
Packit 6c4009
/* This points to the static buffer used.  */
Packit 6c4009
libc_freeres_ptr (static char *buffer);
Packit 6c4009
Packit 6c4009
Packit 6c4009
LOOKUP_TYPE *
Packit 6c4009
GETFUNC_NAME (void)
Packit 6c4009
{
Packit 6c4009
  static size_t buffer_size;
Packit 6c4009
  static union
Packit 6c4009
  {
Packit 6c4009
    LOOKUP_TYPE l;
Packit 6c4009
    void *ptr;
Packit 6c4009
  } resbuf;
Packit 6c4009
  LOOKUP_TYPE *result;
Packit 6c4009
  int save;
Packit 6c4009
Packit 6c4009
  /* Get lock.  */
Packit 6c4009
  __libc_lock_lock (lock);
Packit 6c4009
Packit 6c4009
  result = (LOOKUP_TYPE *)
Packit 6c4009
    __nss_getent ((getent_r_function) INTERNAL (REENTRANT_GETNAME),
Packit 6c4009
		  &resbuf.ptr, &buffer, BUFLEN, &buffer_size,
Packit 6c4009
		  H_ERRNO_VAR);
Packit 6c4009
Packit 6c4009
  save = errno;
Packit 6c4009
  __libc_lock_unlock (lock);
Packit 6c4009
  __set_errno (save);
Packit 6c4009
  return result;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
nss_interface_function (GETFUNC_NAME)