summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2004-08-02 21:52:28 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2004-08-02 21:52:28 +0000
commit98d2fbe2809541076cb88b9902c93448d57f9047 (patch)
tree3cf222dc12b0e6aabd21c3b5c338961a710517a9 /src
parentc87d825fd35999ef6d23ccceafe154d1ee5c4ef2 (diff)
downloadcoreutils-98d2fbe2809541076cb88b9902c93448d57f9047.tar.xz
Include "xgethostname.h".
(xgethostname): Remove decl; xgethostname.h has it. (sethostname) [!defined(HAVE_SETHOSTNAME) && defined(HAVE_SYSINFO) && defined (HAVE_SYS_SYSTEMINFO_H) && defined(HAVE_LIMITS_H)]: Use prototypes rather than K&R form. Assume any negative value from sysinfo denotes failure, not just -1. (main): Simplify use of sethostname.
Diffstat (limited to 'src')
-rw-r--r--src/hostname.c18
1 files changed, 4 insertions, 14 deletions
diff --git a/src/hostname.c b/src/hostname.c
index 69aedac12..ae74a42cf 100644
--- a/src/hostname.c
+++ b/src/hostname.c
@@ -25,6 +25,7 @@
#include "long-options.h"
#include "error.h"
#include "quote.h"
+#include "xgethostname.h"
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "hostname"
@@ -40,23 +41,15 @@ int sethostname ();
# include <sys/systeminfo.h>
int
-sethostname (name, namelen)
- char *name;
- int namelen;
+sethostname (char *name, size_t namelen)
{
/* Using sysinfo() is the SVR4 mechanism to set a hostname. */
- int result;
-
- result = sysinfo (SI_SET_HOSTNAME, name, namelen);
-
- return (result == -1 ? result : 0);
+ return (sysinfo (SI_SET_HOSTNAME, name, namelen) < 0 ? -1 : 0);
}
# define HAVE_SETHOSTNAME 1 /* Now we have it... */
#endif
-char *xgethostname ();
-
/* The name this program was run with. */
char *program_name;
@@ -109,11 +102,8 @@ main (int argc, char **argv)
#ifdef HAVE_SETHOSTNAME
if (argc == 2)
{
- int err;
-
/* Set hostname to argv[1]. */
- err = sethostname (argv[1], strlen (argv[1]));
- if (err != 0)
+ if (sethostname (argv[1], strlen (argv[1])) != 0)
error (EXIT_FAILURE, errno, _("cannot set hostname to `%s'"), argv[1]);
exit (EXIT_SUCCESS);
}