1 /* dirname -- strip suffix from file name
3 Copyright (C) 1990-1997, 1999-2002, 2004, 2005 Free Software
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)
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
20 /* Written by David MacKenzie and Jim Meyering. */
25 #include <sys/types.h>
28 #include "long-options.h"
33 /* The official name of this program (e.g., no `g' prefix). */
34 #define PROGRAM_NAME "dirname"
36 #define AUTHORS "David MacKenzie", "Jim Meyering"
38 /* The name this program was run with. */
44 if (status != EXIT_SUCCESS)
45 fprintf (stderr, _("Try `%s --help' for more information.\n"),
53 program_name, program_name);
55 Print NAME with its trailing /component removed; if NAME contains no /'s,\n\
56 output `.' (meaning the current directory).\n\
59 fputs (HELP_OPTION_DESCRIPTION, stdout);
60 fputs (VERSION_OPTION_DESCRIPTION, stdout);
64 %s /usr/bin/sort Output \"/usr/bin\".\n\
65 %s stdio.h Output \".\".\n\
67 program_name, program_name);
68 printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
74 main (int argc, char **argv)
76 static char const dot = '.';
80 initialize_main (&argc, &argv);
81 program_name = argv[0];
82 setlocale (LC_ALL, "");
83 bindtextdomain (PACKAGE, LOCALEDIR);
86 atexit (close_stdout);
88 parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
89 usage, AUTHORS, (char const *) NULL);
90 if (getopt_long (argc, argv, "+", NULL, NULL) != -1)
93 if (argc < optind + 1)
95 error (0, 0, _("missing operand"));
99 if (optind + 1 < argc)
101 error (0, 0, _("extra operand %s"), quote (argv[optind + 1]));
102 usage (EXIT_FAILURE);
105 result = argv[optind];
106 len = dir_len (result);
114 fwrite (result, 1, len, stdout);