summaryrefslogtreecommitdiffstats
path: root/usr.bin/dirname
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2000-09-03 17:10:00 +0000
committerdes <des@FreeBSD.org>2000-09-03 17:10:00 +0000
commit1e9405b4a8a1ff7d0815ea9c216df8c816c31e10 (patch)
treec68ae527ebafe72214b6ca02214f158a83f1f38e /usr.bin/dirname
parent1846ba7eb2fe7818584ba51ef5cbc47eb8b2337c (diff)
downloadFreeBSD-src-1e9405b4a8a1ff7d0815ea9c216df8c816c31e10.zip
FreeBSD-src-1e9405b4a8a1ff7d0815ea9c216df8c816c31e10.tar.gz
Use dirname(3).
Diffstat (limited to 'usr.bin/dirname')
-rw-r--r--usr.bin/dirname/dirname.c72
1 files changed, 4 insertions, 68 deletions
diff --git a/usr.bin/dirname/dirname.c b/usr.bin/dirname/dirname.c
index 056dc51..cb5adbd 100644
--- a/usr.bin/dirname/dirname.c
+++ b/usr.bin/dirname/dirname.c
@@ -29,6 +29,8 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
+ *
+ * $FreeBSD$
*/
#ifndef lint
@@ -41,8 +43,8 @@ static const char copyright[] =
static const char sccsid[] = "@(#)dirname.c 8.4 (Berkeley) 5/4/95";
#endif /* not lint */
+#include <libgen.h>
#include <stdio.h>
-#include <stdlib.h>
#include <unistd.h>
void usage __P((void));
@@ -52,7 +54,6 @@ main(argc, argv)
int argc;
char **argv;
{
- char *p;
int ch;
while ((ch = getopt(argc, argv, "")) != -1)
@@ -67,72 +68,7 @@ main(argc, argv)
if (argc != 1)
usage();
- /*
- * (1) If string is //, skip steps (2) through (5).
- * (2) If string consists entirely of slash characters, string
- * shall be set to a single slash character. In this case,
- * skip steps (3) through (8).
- */
- for (p = *argv;; ++p) {
- if (!*p) {
- if (p > *argv)
- (void)printf("/\n");
- else
- (void)printf(".\n");
- exit(0);
- }
- if (*p != '/')
- break;
- }
-
- /*
- * (3) If there are any trailing slash characters in string, they
- * shall be removed.
- */
- for (; *p; ++p);
- while (*--p == '/')
- continue;
- *++p = '\0';
-
- /*
- * (4) If there are no slash characters remaining in string,
- * string shall be set to a single period character. In this
- * case skip steps (5) through (8).
- *
- * (5) If there are any trailing nonslash characters in string,
- * they shall be removed.
- */
- while (--p >= *argv)
- if (*p == '/')
- break;
- ++p;
- if (p == *argv) {
- (void)printf(".\n");
- exit(0);
- }
-
- /*
- * (6) If the remaining string is //, it is implementation defined
- * whether steps (7) and (8) are skipped or processed.
- *
- * This case has already been handled, as part of steps (1) and (2).
- */
-
- /*
- * (7) If there are any trailing slash characters in string, they
- * shall be removed.
- */
- while (--p >= *argv)
- if (*p != '/')
- break;
- ++p;
-
- /*
- * (8) If the remaining string is empty, string shall be set to
- * a single slash character.
- */
- *p = '\0';
- (void)printf("%s\n", p == *argv ? "/" : *argv);
+ (void)printf("%s\n", dirname(*argv));
exit(0);
}
OpenPOWER on IntegriCloud