dirname.c revision 65508
184447Sdfr/*- 284447Sdfr * Copyright (c) 1991, 1993, 1994 384447Sdfr * The Regents of the University of California. All rights reserved. 484447Sdfr * 584447Sdfr * Redistribution and use in source and binary forms, with or without 684447Sdfr * modification, are permitted provided that the following conditions 784447Sdfr * are met: 884447Sdfr * 1. Redistributions of source code must retain the above copyright 984447Sdfr * notice, this list of conditions and the following disclaimer. 1084447Sdfr * 2. Redistributions in binary form must reproduce the above copyright 1184447Sdfr * notice, this list of conditions and the following disclaimer in the 1284447Sdfr * documentation and/or other materials provided with the distribution. 1384447Sdfr * 3. All advertising materials mentioning features or use of this software 1484447Sdfr * must display the following acknowledgement: 1584447Sdfr * This product includes software developed by the University of 1684447Sdfr * California, Berkeley and its contributors. 1784447Sdfr * 4. Neither the name of the University nor the names of its contributors 1884447Sdfr * may be used to endorse or promote products derived from this software 1984447Sdfr * without specific prior written permission. 2084447Sdfr * 2184447Sdfr * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2284447Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2384447Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2484447Sdfr * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2584447Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2684447Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2784447Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2884447Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2984447Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3084447Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3184447Sdfr * SUCH DAMAGE. 3284447Sdfr * 33108026Smarcel * $FreeBSD: head/usr.bin/dirname/dirname.c 65508 2000-09-06 07:28:02Z des $ 34108026Smarcel */ 35108026Smarcel 3684447Sdfr#ifndef lint 3784447Sdfrstatic const char copyright[] = 3884447Sdfr"@(#) Copyright (c) 1991, 1993, 1994\n\ 3984447Sdfr The Regents of the University of California. All rights reserved.\n"; 4084447Sdfr#endif /* not lint */ 4184447Sdfr 42108026Smarcel#ifndef lint 43108026Smarcelstatic const char sccsid[] = "@(#)dirname.c 8.4 (Berkeley) 5/4/95"; 44108026Smarcel#endif /* not lint */ 45108026Smarcel 46108026Smarcel#include <err.h> 4784447Sdfr#include <libgen.h> 4884447Sdfr#include <stdio.h> 4984447Sdfr#include <unistd.h> 5084447Sdfr 5184447Sdfrvoid usage __P((void)); 5284447Sdfr 5384447Sdfrint 5484447Sdfrmain(argc, argv) 5584447Sdfr int argc; 5684447Sdfr char **argv; 5784447Sdfr{ 5884447Sdfr char *p; 5984447Sdfr int ch; 6084447Sdfr 6184447Sdfr while ((ch = getopt(argc, argv, "")) != -1) 6299149Siwasaki switch(ch) { 6384447Sdfr case '?': 6484447Sdfr default: 65108026Smarcel usage(); 66108026Smarcel } 67108026Smarcel argc -= optind; 68108026Smarcel argv += optind; 69108026Smarcel 70108026Smarcel if (argc != 1) 71108026Smarcel usage(); 72108026Smarcel 73108026Smarcel if ((p = dirname(*argv)) == NULL) 74108026Smarcel err(1, "%s", *argv); 75108026Smarcel (void)printf("%s\n", p); 76108026Smarcel exit(0); 77108026Smarcel} 7899149Siwasaki 7984447Sdfrvoid 80108026Smarcelusage() 81108026Smarcel{ 8285656Smarcel 8384447Sdfr (void)fprintf(stderr, "usage: dirname path\n"); 84 exit(1); 85} 86