4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
25 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
35 main(int argc
, char **argv
)
42 * For better performance, defer the setlocale()/textdomain()
43 * calls until they get really required.
45 #if !defined(TEXT_DOMAIN)
46 #define TEXT_DOMAIN "SYS_TEST"
53 if (strcmp(argv
[1], "--") == 0) {
63 (void) setlocale(LC_ALL
, "");
64 (void) textdomain(TEXT_DOMAIN
);
65 (void) fputs(gettext("Usage: basename string [ suffix ]\n"),
71 suffix
= (argc
== 2) ? NULL
: argv
[2];
73 if (*string
== '\0') {
78 /* remove trailing slashes */
79 p
= string
+ strlen(string
) - 1;
80 while (p
>= string
&& *p
== '/')
83 if (*string
== '\0') {
88 /* skip to one past last slash */
89 if ((p
= strrchr(string
, '/')) != NULL
)
98 * if a suffix is present and is not the same as the remaining
99 * string and is identical to the last characters in the remaining
100 * string, remove those characters from the string.
102 if (strcmp(string
, suffix
) != 0) {
103 p
= string
+ strlen(string
) - strlen(suffix
);
104 if (strcmp(p
, suffix
) == 0)