-/* Copyright (C) 1996 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997 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
Boston, MA 02111-1307, USA. */
#include <errno.h>
-#include <libc-lock.h>
+#include <bits/libc-lock.h>
#include <stdlib.h>
#include "nsswitch.h"
/* Sometimes we need to store error codes in the `h_errno' variable. */
#ifdef NEED_H_ERRNO
# define H_ERRNO_PARM , int *h_errnop
-# define H_ERRNO_VAR , &h_errno
+# define H_ERRNO_VAR , &h_errno_tmp
#else
# define H_ERRNO_PARM
# define H_ERRNO_VAR
static LOOKUP_TYPE resbuf;
LOOKUP_TYPE *result;
int save;
+#ifdef NEED_H_ERRNO
+ int h_errno_tmp = 0;
+#endif
/* Get lock. */
__libc_lock_lock (lock);
buffer = malloc (buffer_size);
}
+ if (buffer != NULL)
+ {
+#ifdef HANDLE_DIGITS_DOTS
+# include "digits_dots.c"
+#endif
+ }
+
while (buffer != NULL
&& INTERNAL (REENTRANT_NAME) (ADD_VARIABLES, &resbuf, buffer,
buffer_size, &result H_ERRNO_VAR) != 0
+#ifdef NEED_H_ERRNO
+ && h_errno_tmp == NETDB_INTERNAL
+#endif
&& errno == ERANGE)
{
char *new_buf;
buffer_size += BUFLEN;
new_buf = realloc (buffer, buffer_size);
if (new_buf == NULL)
- /* We are out of memory. Free the current buffer so that the
- process gets a chance for a normal termination. */
- free (buffer);
+ {
+ /* We are out of memory. Free the current buffer so that the
+ process gets a chance for a normal termination. */
+ save = errno;
+ free (buffer);
+ __set_errno (save);
+ }
buffer = new_buf;
}
+ if (buffer == NULL)
+ result = NULL;
+
+#ifdef HANDLE_DIGITS_DOTS
+done:
+#endif
/* Release lock. Preserve error value. */
save = errno;
__libc_lock_unlock (lock);
__set_errno (save);
+#ifdef NEED_H_ERRNO
+ if (h_errno_tmp != 0)
+ __set_h_errno (h_errno_tmp);
+#endif
+
return result;
}