[BACK]Return to dirname.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / dirname

Annotation of src/usr.bin/dirname/dirname.c, Revision 1.15

1.15    ! deraadt     1: /*     $OpenBSD: dirname.c,v 1.14 2015/10/05 13:30:30 deraadt Exp $    */
1.1       deraadt     2:
1.3       millert     3: /*
                      4:  * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
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>
                     21: #include <locale.h>
1.1       deraadt    22: #include <stdio.h>
1.10      david      23: #include <stdlib.h>
1.11      otto       24: #include <unistd.h>
                     25:
                     26: void usage(void);
1.1       deraadt    27:
                     28: int
1.8       deraadt    29: main(int argc, char *argv[])
1.1       deraadt    30: {
1.11      otto       31:        int ch;
1.3       millert    32:        char *dir;
1.1       deraadt    33:
                     34:        setlocale(LC_ALL, "");
1.14      deraadt    35:
1.15    ! deraadt    36:        if (pledge("stdio", NULL) == -1)
        !            37:                err(1, "pledge");
1.1       deraadt    38:
1.11      otto       39:        while ((ch = getopt(argc, argv, "")) != -1) {
                     40:                switch (ch) {
                     41:                default:
                     42:                        usage();
                     43:                }
1.1       deraadt    44:        }
1.11      otto       45:        argc -= optind;
                     46:        argv += optind;
                     47:
                     48:        if (argc != 1)
                     49:                usage();
1.1       deraadt    50:
1.11      otto       51:        if ((dir = dirname(argv[0])) == NULL)
                     52:                err(1, "%s", argv[0]);
1.3       millert    53:        puts(dir);
1.1       deraadt    54:        exit(0);
1.11      otto       55: }
                     56:
                     57: extern char *__progname;
                     58:
                     59: void
                     60: usage(void)
                     61: {
1.13      sobrado    62:        (void)fprintf(stderr, "usage: %s pathname\n", __progname);
1.11      otto       63:        exit(1);
1.1       deraadt    64: }