.
[coreutils.git] / src / hostid.c
blob095b758917ec792de6f783c7230d10cb39f9db10
1 /* print the hexadecimal identifier for the current host
3 Copyright (C) 1997, 1999, 2000, 2001, 2002, 2003, 2004 Free
4 Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software Foundation,
18 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 /* Written by Jim Meyering. */
22 #include <config.h>
23 #include <stdio.h>
24 #include <sys/types.h>
26 #include "system.h"
27 #include "long-options.h"
28 #include "error.h"
30 /* The official name of this program (e.g., no `g' prefix). */
31 #define PROGRAM_NAME "hostid"
33 #define AUTHORS "Jim Meyering"
35 /* The name this program was run with, for error messages. */
36 char *program_name;
38 void
39 usage (int status)
41 if (status != EXIT_SUCCESS)
42 fprintf (stderr, _("Try `%s --help' for more information.\n"),
43 program_name);
44 else
46 printf (_("\
47 Usage: %s\n\
48 or: %s OPTION\n\
49 Print the numeric identifier (in hexadecimal) for the current host.\n\
50 \n\
51 "),
52 program_name, program_name);
53 fputs (HELP_OPTION_DESCRIPTION, stdout);
54 fputs (VERSION_OPTION_DESCRIPTION, stdout);
55 printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
57 exit (status);
60 int
61 main (int argc, char **argv)
63 long int id;
65 initialize_main (&argc, &argv);
66 program_name = argv[0];
67 setlocale (LC_ALL, "");
68 bindtextdomain (PACKAGE, LOCALEDIR);
69 textdomain (PACKAGE);
71 atexit (close_stdout);
73 parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
74 usage, AUTHORS, (char const *) NULL);
76 if (argc > 1)
78 error (0, 0, _("too many arguments"));
79 usage (EXIT_FAILURE);
82 id = gethostid ();
83 printf ("%lx\n", id);
85 exit (EXIT_SUCCESS);