Annotation of src/usr.bin/dirname/dirname.c, Revision 1.17
1.17 ! millert 1: /* $OpenBSD: dirname.c,v 1.16 2016/10/28 07:22:59 schwarze Exp $ */
1.1 deraadt 2:
1.3 millert 3: /*
1.17 ! millert 4: * Copyright (c) 1997 Todd C. Miller <millert@openbsd.org>
1.1 deraadt 5: *
1.7 millert 6: * Permission to use, copy, modify, and distribute this software for any
7: * purpose with or without fee is hereby granted, provided that the above
8: * copyright notice and this permission notice appear in all copies.
1.1 deraadt 9: *
1.9 millert 10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1 deraadt 17: */
18:
1.5 pjanzen 19: #include <err.h>
1.3 millert 20: #include <libgen.h>
1.1 deraadt 21: #include <stdio.h>
1.10 david 22: #include <stdlib.h>
1.11 otto 23: #include <unistd.h>
24:
1.16 schwarze 25: static void __dead usage(void);
1.1 deraadt 26:
27: int
1.8 deraadt 28: main(int argc, char *argv[])
1.1 deraadt 29: {
1.11 otto 30: int ch;
1.3 millert 31: char *dir;
1.1 deraadt 32:
1.15 deraadt 33: if (pledge("stdio", NULL) == -1)
34: err(1, "pledge");
1.1 deraadt 35:
1.11 otto 36: while ((ch = getopt(argc, argv, "")) != -1) {
37: switch (ch) {
38: default:
39: usage();
40: }
1.1 deraadt 41: }
1.11 otto 42: argc -= optind;
43: argv += optind;
44:
45: if (argc != 1)
46: usage();
1.1 deraadt 47:
1.11 otto 48: if ((dir = dirname(argv[0])) == NULL)
49: err(1, "%s", argv[0]);
1.3 millert 50: puts(dir);
1.16 schwarze 51: return 0;
1.11 otto 52: }
53:
54: extern char *__progname;
55:
1.16 schwarze 56: static void __dead
1.11 otto 57: usage(void)
58: {
1.13 sobrado 59: (void)fprintf(stderr, "usage: %s pathname\n", __progname);
1.11 otto 60: exit(1);
1.1 deraadt 61: }