annotate toys/lsb/hostname.c @ 1037:af1780148f7c draft

Implement ls --color=auto, suggested by Rich Felker.
author Rob Landley <rob@landley.net>
date Sun, 01 Sep 2013 08:00:41 -0500
parents 786841fdb1e0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
1 /* hostname.c - Get/Set the hostname
463
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 * Copyright 2012 Andre Renaud <andre@bluewatersys.com>
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
4 *
656
6df4ccc0acbe Regularize command headers, update links to standards documents.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
5 * http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/hostname.html
463
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
6
464
9e1fe8e287a2 Minor cleanups to hostname.
Rob Landley <rob@landley.net>
parents: 463
diff changeset
7 USE_HOSTNAME(NEWTOY(hostname, NULL, TOYFLAG_BIN))
463
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
8
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
9 config HOSTNAME
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
10 bool "hostname"
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
11 default y
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
12 help
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
13 usage: hostname [newname]
463
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
14
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
15 Get/Set the current hostname
463
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
674
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 665
diff changeset
18 #define FOR_hostname
463
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
19 #include "toys.h"
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
20
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
21 void hostname_main(void)
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
22 {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
23 const char *hostname = toys.optargs[0];
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
24 if (hostname) {
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
25 if (sethostname(hostname, strlen(hostname)))
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
26 perror_exit("set failed '%s'", hostname);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
27 } else {
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
28 if (gethostname(toybuf, sizeof(toybuf))) perror_exit("get failed");
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
29 xputs(toybuf);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
30 }
463
dc88e450288c Add hostname from Andre Renaud.
Rob Landley <rob@landley.net>
parents:
diff changeset
31 }