Blame hurd/getdport.c

Packit Service 82fcde
/* Copyright (C) 1991-2018 Free Software Foundation, Inc.
Packit Service 82fcde
Packit Service 82fcde
   This file is part of the GNU C Library.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 82fcde
   modify it under the terms of the GNU Lesser General Public
Packit Service 82fcde
   License as published by the Free Software Foundation; either
Packit Service 82fcde
   version 2.1 of the License, or (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 82fcde
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 82fcde
   Lesser General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
   You should have received a copy of the GNU Lesser General Public
Packit Service 82fcde
   License along with the GNU C Library; if not, see
Packit Service 82fcde
   <http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
#include <hurd.h>
Packit Service 82fcde
Packit Service 82fcde
/* This is initialized in dtable.c when that gets linked in.
Packit Service 82fcde
   If dtable.c is not linked in, it will be zero.  */
Packit Service 82fcde
static file_t (*_default_hurd_getdport_fn) (int fd) = 0;
Packit Service 82fcde
weak_alias (_default_hurd_getdport_fn, _hurd_getdport_fn)
Packit Service 82fcde
Packit Service 82fcde
file_t
Packit Service 82fcde
__getdport (int fd)
Packit Service 82fcde
{
Packit Service 82fcde
  if (_hurd_getdport_fn)
Packit Service 82fcde
    /* dtable.c has defined the function to fetch a port from the real file
Packit Service 82fcde
       descriptor table.  */
Packit Service 82fcde
    return (*_hurd_getdport_fn) (fd);
Packit Service 82fcde
Packit Service 82fcde
  /* getdport is the only use of file descriptors,
Packit Service 82fcde
     so we don't bother allocating a real table.  */
Packit Service 82fcde
Packit Service 82fcde
  if (_hurd_init_dtable == NULL)
Packit Service 82fcde
    {
Packit Service 82fcde
      /* Never had a descriptor table.  */
Packit Service 82fcde
      errno = EBADF;
Packit Service 82fcde
      return MACH_PORT_NULL;
Packit Service 82fcde
    }
Packit Service 82fcde
Packit Service 82fcde
  if (fd < 0 || (unsigned int) fd > _hurd_init_dtablesize ||
Packit Service 82fcde
      _hurd_init_dtable[fd] == MACH_PORT_NULL)
Packit Service 82fcde
    {
Packit Service 82fcde
      errno = EBADF;
Packit Service 82fcde
      return MACH_PORT_NULL;
Packit Service 82fcde
    }
Packit Service 82fcde
  else
Packit Service 82fcde
    {
Packit Service 82fcde
      __mach_port_mod_refs (__mach_task_self (), _hurd_init_dtable[fd],
Packit Service 82fcde
			    MACH_PORT_RIGHT_SEND, 1);
Packit Service 82fcde
      return _hurd_init_dtable[fd];
Packit Service 82fcde
    }
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
weak_alias (__getdport, getdport)