source: trunk/coreutils/src/logname.c@ 2603

Last change on this file since 2603 was 2554, checked in by bird, 20 years ago

coretuils-5.94

File size: 2.4 KB
Line 
1/* logname -- print user's login name
2 Copyright (C) 1990-1997, 1999-2005 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
17
18#include <config.h>
19#include <stdio.h>
20#include <sys/types.h>
21#include <getopt.h>
22
23#include "system.h"
24#include "error.h"
25#include "long-options.h"
26#include "quote.h"
27
28/* The official name of this program (e.g., no `g' prefix). */
29#define PROGRAM_NAME "logname"
30
31#define AUTHORS "FIXME: unknown"
32
33/* The name this program was run with. */
34char *program_name;
35
36void
37usage (int status)
38{
39 if (status != EXIT_SUCCESS)
40 fprintf (stderr, _("Try `%s --help' for more information.\n"),
41 program_name);
42 else
43 {
44 printf (_("Usage: %s [OPTION]\n"), program_name);
45 fputs (_("\
46Print the name of the current user.\n\
47\n\
48"), stdout);
49 fputs (HELP_OPTION_DESCRIPTION, stdout);
50 fputs (VERSION_OPTION_DESCRIPTION, stdout);
51 printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
52 }
53 exit (status);
54}
55
56int
57main (int argc, char **argv)
58{
59 char *cp;
60
61 initialize_main (&argc, &argv);
62 program_name = argv[0];
63 setlocale (LC_ALL, "");
64 bindtextdomain (PACKAGE, LOCALEDIR);
65 textdomain (PACKAGE);
66
67 atexit (close_stdout);
68
69 parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
70 usage, AUTHORS, (char const *) NULL);
71 if (getopt_long (argc, argv, "", NULL, NULL) != -1)
72 usage (EXIT_FAILURE);
73
74 if (optind < argc)
75 {
76 error (0, 0, _("extra operand %s"), quote (argv[optind]));
77 usage (EXIT_FAILURE);
78 }
79
80 /* POSIX requires using getlogin (or equivalent code). */