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 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
37 main(int argc
, char **argv
)
43 * For better performance, defer the setlocale()/textdomain()
44 * calls until they get really required.
46 #if !defined(TEXT_DOMAIN)
47 #define TEXT_DOMAIN "SYS_TEST"
53 if (strcmp(argv
[1], "--") == 0) {
62 (void) setlocale(LC_ALL
, "");
63 (void) textdomain(TEXT_DOMAIN
);
64 (void) fprintf(stderr
, gettext("Usage: dirname [ path ]\n"));
70 if (*string
== '\0') {
75 /* remove trailing slashes */
76 p
= string
+ strlen(string
) - 1;
77 while (p
>= string
&& *p
== '/')
80 if (*string
== '\0') {
81 /* string contained only slashes */
86 /* remove non-slashes */
87 while (p
>= string
&& *p
!= '/')
90 if (*string
== '\0') {
91 /* string did not begin with a slash */
96 /* remove slashes delimiting dirname and basename */
97 while (p
>= string
&& *p
== '/')
100 if (*string
== '\0') {
101 /* no dirname part found */
105 /* now string points to dirname part */