/* print the hexadecimal identifier for the current host This is the hostid utility
Copyright (C) 1997-2018 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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */ The GNUv3 license
/* Written by Jim Meyering. */
#include <config.h> Provides system specific information
#include <getopt.h> ...!includes auto-comment...
#include <stdio.h> Provides standard I/O capability
#include <sys/types.h> Provides system data types
#include "system.h" ...!includes auto-comment...
#include "long-options.h" ...!includes auto-comment...
#include "error.h" ...!includes auto-comment...
#include "quote.h" ...!includes auto-comment...
/* The official name of this program (e.g., no 'g' prefix). */
#define PROGRAM_NAME "hostid" Line 31
#define AUTHORS proper_name ("Jim Meyering") Line 33
static struct option const long_options[] = Line 35
{
{NULL, 0, NULL, 0} Line 37
}; Block 1
void Line 40
usage (int status) Line 41
{
if (status != EXIT_SUCCESS) Line 43
emit_try_help (); ...!common auto-comment...
else Line 45
{
printf (_("\ Line 47
Usage: %s [OPTION]\n\ Line 48
Print the numeric identifier (in hexadecimal) for the current host.\n\ Line 49
\n\
"), program_name); Line 51
fputs (HELP_OPTION_DESCRIPTION, stdout); Line 52
fputs (VERSION_OPTION_DESCRIPTION, stdout); Line 53
emit_ancillary_info (PROGRAM_NAME); Line 54
}
exit (status); Line 56
} Block 2
int
main (int argc, char **argv) Line 60
{
unsigned int id; Line 62
initialize_main (&argc, &argv); VMS-specific entry point handling wildcard expansion
set_program_name (argv[0]); Retains program name and discards path
setlocale (LC_ALL, ""); Sets up internationalization (i18n)
bindtextdomain (PACKAGE, LOCALEDIR); Assigns i18n directorySets text domain for _() [gettext()] function
textdomain (PACKAGE); Sets text domain for _() [gettext()] function
atexit (close_stdout); Close stdout on exit (see gnulib)
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, ...!common auto-comment...
usage, AUTHORS, (char const *) NULL); Line 73
if (getopt_long (argc, argv, "", long_options, NULL) != -1) Line 74
usage (EXIT_FAILURE); Line 75
if (optind < argc) Line 77
{
error (0, 0, _("extra operand %s"), quote (argv[optind])); Line 79
usage (EXIT_FAILURE); Line 80
}
id = gethostid (); Line 83
/* POSIX says gethostid returns a "32-bit identifier" but is silent
whether it's sign-extended. Turn off any sign-extension. This
is a no-op unless unsigned int is wider than 32 bits. */
id &= 0xffffffff; Line 88
printf ("%08x\n", id); Line 90
return EXIT_SUCCESS; Line 92
} Block 3