From 497560dfe9007d0803636e2224b23f5aca1b36ff Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sun, 13 Jul 2003 08:42:40 +0000 Subject: (xgethostname): Return NULL, rather than exiting, upon any non-malloc/realloc error. --- lib/xgethostname.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib') 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); } -- cgit v1.2.3-54-g00ecf