/* _hurd_socket_server - Find the server for a socket domain.
+ Copyright (C) 1991-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
-Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
-This file is part of the GNU C Library.
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
-The GNU C Library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Library General Public License as
-published by the Free Software Foundation; either version 2 of the
-License, or (at your option) any later version.
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
-The GNU C Library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Library General Public License for more details.
-
-You should have received a copy of the GNU Library General Public
-License along with the GNU C Library; see the file COPYING.LIB. If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA. */
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
#include <hurd.h>
#include <sys/socket.h>
#include <string.h>
#include <hurd/paths.h>
#include <stdio.h>
-#include "stdio/_itoa.h"
+#include <_itoa.h>
#include <cthreads.h> /* For `struct mutex'. */
#include "hurdmalloc.h" /* XXX */
static struct mutex lock;
static file_t *servers;
-static int max_domain;
+static int max_domain = -1;
/* Return a port to the socket server for DOMAIN.
Socket servers translate nodes in the directory _SERVERS_SOCKET
{
socket_t server;
+ if (domain < 0)
+ {
+ errno = EAFNOSUPPORT;
+ return MACH_PORT_NULL;
+ }
+
HURD_CRITICAL_BEGIN;
__mutex_lock (&lock);
file_t *new = realloc (servers, (domain + 1) * sizeof (file_t));
if (new != NULL)
{
- while (max_domain <= domain)
- new[max_domain++] = MACH_PORT_NULL;
+ do
+ new[++max_domain] = MACH_PORT_NULL;
+ while (max_domain < domain);
servers = new;
}
else
if (server == MACH_PORT_NULL && errno == ENOENT)
/* If the server node is absent, we don't support that protocol. */
- errno = EPFNOSUPPORT;
+ errno = EAFNOSUPPORT;
__mutex_unlock (&lock);
HURD_CRITICAL_END;
static void
init (void)
{
- size_t i;
+ int i;
__mutex_init (&lock);