annotate toys/hostname.c @ 562:4d802d438983

Match uint64_t with PRIu64 to avoid warnings on 64 bit builds.
author Rob Landley <rob@landley.net>
date Sat, 14 Apr 2012 21:27:00 -0500
parents 9e1fe8e287a2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
463
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
1 /* vi: set sw=4 ts=4:
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
2 *
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
3 * hostname.c - Get/Set the hostname
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
4 *
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
5 * Copyright 2012 Andre Renaud <andre@bluewatersys.com>
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
6 *
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
7 * Not in SUSv4.
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
8
464
9e1fe8e287a2 Minor cleanups to hostname.
Rob Landley <rob@landley.net>
parents: 463
diff changeset
9 USE_HOSTNAME(NEWTOY(hostname, NULL, TOYFLAG_BIN))
463
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
10
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
11 config HOSTNAME
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
12 bool "hostname"
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
13 default n
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
14 help
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
15 usage: hostname [newname]
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
16
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
17 Get/Set the current hostname
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
18 */
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
19
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
20 #include "toys.h"
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
21
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
22 void hostname_main(void)
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
23 {
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
24 const char *hostname = toys.optargs[0];
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
25 if (hostname) {
464
9e1fe8e287a2 Minor cleanups to hostname.
Rob Landley <rob@landley.net>
parents: 463
diff changeset
26 if (sethostname(hostname, strlen(hostname)))
463
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
27 perror_exit("cannot set hostname to '%s'", hostname);
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
28 } else {
464
9e1fe8e287a2 Minor cleanups to hostname.
Rob Landley <rob@landley.net>
parents: 463
diff changeset
29 if (gethostname(toybuf, sizeof(toybuf)))
463
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
30 perror_exit("cannot get hostname");
464
9e1fe8e287a2 Minor cleanups to hostname.
Rob Landley <rob@landley.net>
parents: 463
diff changeset
31 xputs(toybuf);
463
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
32 }
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
33 }