]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(xgethostname): Return NULL, rather than exiting,
authorJim Meyering <jim@meyering.net>
Sun, 13 Jul 2003 08:42:40 +0000 (08:42 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 13 Jul 2003 08:42:40 +0000 (08:42 +0000)
upon any non-malloc/realloc error.

lib/xgethostname.c

index 4db3bbd16a41f540a06a13a47c7e531c62dd45a7..a78dda8b62a45292191a0fe186461b8a7da4fb7b 100644 (file)
@@ -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);
     }