GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.bin/dirname/dirname.c Lines: 10 16 62.5 %
Date: 2016-12-06 Branches: 4 8 50.0 %

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