[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-gnulib] xgethostname no exit on "normal" failure (merge from coreut
From: |
Paul Eggert |
Subject: |
[Bug-gnulib] xgethostname no exit on "normal" failure (merge from coreutils) |
Date: |
16 Aug 2003 00:01:56 -0700 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 |
I installed this change from coreutils:
2003-08-15 Jim Meyering <address@hidden>
* xgethostname.c: Include <stdlib.h>.
(xghostname): Don't exit for anything other than memory-related
failure; just return NULL.
Index: lib/xgethostname.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/xgethostname.c,v
retrieving revision 1.13
diff -p -u -r1.13 xgethostname.c
--- lib/xgethostname.c 22 Jul 2003 22:56:34 -0000 1.13
+++ lib/xgethostname.c 16 Aug 2003 02:56:38 -0000
@@ -21,6 +21,7 @@
# include <config.h>
#endif
+#include <stdlib.h>
#include <sys/types.h>
#include <errno.h>
@@ -45,6 +46,9 @@ int gethostname ();
# define INITIAL_HOSTNAME_LENGTH 34
#endif
+/* Return the current hostname in malloc'd storage.
+ If malloc fails, exit.
+ Upon any other failure, return NULL. */
char *
xgethostname ()
{
@@ -67,7 +71,12 @@ xgethostname ()
if (err >= 0 && hostname[k] == '\0')
break;
else if (err < 0 && errno != ENAMETOOLONG && errno != 0)
- error (EXIT_FAILURE, errno, "gethostname");
+ {
+ int saved_errno = errno;
+ free (hostname);
+ errno = saved_errno;
+ return NULL;
+ }
size *= 2;
hostname = xrealloc (hostname, size + 1);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Bug-gnulib] xgethostname no exit on "normal" failure (merge from coreutils),
Paul Eggert <=