Mercurial > hg > toybox
comparison toys/hostname.c @ 464:9e1fe8e287a2
Minor cleanups to hostname.
author | Rob Landley <rob@landley.net> |
---|---|
date | Wed, 15 Feb 2012 05:55:38 -0600 |
parents | dc88e450288c |
children |
comparison
equal
deleted
inserted
replaced
463:dc88e450288c | 464:9e1fe8e287a2 |
---|---|
4 * | 4 * |
5 * Copyright 2012 Andre Renaud <andre@bluewatersys.com> | 5 * Copyright 2012 Andre Renaud <andre@bluewatersys.com> |
6 * | 6 * |
7 * Not in SUSv4. | 7 * Not in SUSv4. |
8 | 8 |
9 USE_HOSTNAME(NEWTOY(hostname, "", TOYFLAG_BIN)) | 9 USE_HOSTNAME(NEWTOY(hostname, NULL, TOYFLAG_BIN)) |
10 | 10 |
11 config HOSTNAME | 11 config HOSTNAME |
12 bool "hostname" | 12 bool "hostname" |
13 default n | 13 default n |
14 help | 14 help |
21 | 21 |
22 void hostname_main(void) | 22 void hostname_main(void) |
23 { | 23 { |
24 const char *hostname = toys.optargs[0]; | 24 const char *hostname = toys.optargs[0]; |
25 if (hostname) { | 25 if (hostname) { |
26 int len = strlen(hostname); | 26 if (sethostname(hostname, strlen(hostname))) |
27 if (sethostname(hostname, len)) | |
28 perror_exit("cannot set hostname to '%s'", hostname); | 27 perror_exit("cannot set hostname to '%s'", hostname); |
29 } else { | 28 } else { |
30 char buffer[256]; | 29 if (gethostname(toybuf, sizeof(toybuf))) |
31 if (gethostname(buffer, sizeof(buffer))) | |
32 perror_exit("cannot get hostname"); | 30 perror_exit("cannot get hostname"); |
33 xprintf("%s\n", buffer); | 31 xputs(toybuf); |
34 } | 32 } |
35 } | 33 } |