From a02fb11d70b9e3b7a1056de6d153960c4101de08 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Fri, 30 Jan 1998 17:29:20 +0000 Subject: [PATCH] (gethostid): Correct handling of enlarging buffers (clear errno). --- sysdeps/unix/sysv/linux/gethostid.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sysdeps/unix/sysv/linux/gethostid.c b/sysdeps/unix/sysv/linux/gethostid.c index 67e64208b38..9b061e6b6ee 100644 --- a/sysdeps/unix/sysv/linux/gethostid.c +++ b/sysdeps/unix/sysv/linux/gethostid.c @@ -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); -- 2.47.2