summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-07-13 08:42:40 +0000
committerJim Meyering <jim@meyering.net>2003-07-13 08:42:40 +0000
commit497560dfe9007d0803636e2224b23f5aca1b36ff (patch)
tree449f6d0a42b216a0ec983317c1344bb7b88eba76 /lib
parentf24368a67a1655ba2aed2ce4aa6a62f1e4ccb54e (diff)
downloadcoreutils-497560dfe9007d0803636e2224b23f5aca1b36ff.tar.xz
(xgethostname): Return NULL, rather than exiting,
upon any non-malloc/realloc error.
Diffstat (limited to 'lib')
-rw-r--r--lib/xgethostname.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/xgethostname.c b/lib/xgethostname.c
index 4db3bbd16..a78dda8b6 100644
--- a/lib/xgethostname.c
+++ b/lib/xgethostname.c
@@ -1,5 +1,5 @@
/* xgethostname.c -- return current hostname with unlimited length
- Copyright (C) 1992, 1996, 2000, 2001 Free Software Foundation, Inc.
+ Copyright (C) 1992, 1996, 2000, 2001, 2003 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -45,6 +45,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 +70,10 @@ xgethostname ()
if (err >= 0 && hostname[k] == '\0')
break;
else if (err < 0 && errno != ENAMETOOLONG && errno != 0)
- error (EXIT_FAILURE, errno, "gethostname");
+ {
+ free (hostname);
+ return NULL;
+ }
size *= 2;
hostname = xrealloc (hostname, size + 1);
}