]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
(gethostid): Correct handling of enlarging buffers (clear errno).
authorUlrich Drepper <drepper@redhat.com>
Fri, 30 Jan 1998 17:29:20 +0000 (17:29 +0000)
committerUlrich Drepper <drepper@redhat.com>
Fri, 30 Jan 1998 17:29:20 +0000 (17:29 +0000)
sysdeps/unix/sysv/linux/gethostid.c

index 67e64208b380a6a637213b8248e024f48658f886..9b061e6b6ee5c77c79465b1f35078074bb2faf28 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+/* Copyright (C) 1995, 1996, 1998 Free Software Foundation, Inc.
 
    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
@@ -66,6 +66,7 @@ gethostid ()
   struct in_addr in;
   int herr;
   int fd;
+  int save_errno;
 
   /* First try to get the ID from a former invocation of sethostid.  */
   fd = __open (HOSTIDFILE, O_RDONLY);
@@ -87,6 +88,7 @@ gethostid ()
 
   buflen = 1024;
   buffer = __alloca (buflen);
+  save_errno = errno;
 
   /* To get the IP address we need to know the host name.  */
   while (__gethostbyname_r (hostname, &hostbuf, buffer, buflen, &hp, &herr)
@@ -98,8 +100,12 @@ gethostid ()
        /* Enlarge buffer.  */
        buflen *= 2;
        buffer = __alloca (buflen);
+       __set_errno (0);
       }
 
+  if (errno == 0)
+    __set_errno (save_errno);
+
   in.s_addr = 0;
   memcpy (&in, hp->h_addr,
          (int) sizeof (in) < hp->h_length ? sizeof (in) : hp->h_length);