]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - hurd/hurdsock.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / hurd / hurdsock.c
index 266fd40d31657aea9faf15bf9c16962b279a807c..bb98a6b7454dc00dd37ea8fd51884b1b3800e943 100644 (file)
@@ -1,22 +1,20 @@
 /* _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>
@@ -24,14 +22,14 @@ Cambridge, MA 02139, USA.  */
 #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
@@ -48,6 +46,12 @@ _hurd_socket_server (int domain, int dead)
 {
   socket_t server;
 
+  if (domain < 0)
+    {
+      errno = EAFNOSUPPORT;
+      return MACH_PORT_NULL;
+    }
+
   HURD_CRITICAL_BEGIN;
   __mutex_lock (&lock);
 
@@ -57,8 +61,9 @@ _hurd_socket_server (int domain, int dead)
       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
@@ -92,7 +97,7 @@ _hurd_socket_server (int domain, int dead)
 
   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;
@@ -103,7 +108,7 @@ _hurd_socket_server (int domain, int dead)
 static void
 init (void)
 {
-  size_t i;
+  int i;
 
   __mutex_init (&lock);