GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.bin/dirname/dirname.c Lines: 8 14 57.1 %
Date: 2017-11-07 Branches: 4 8 50.0 %

Line Branch Exec Source
1
/*	$OpenBSD: dirname.c,v 1.16 2016/10/28 07:22:59 schwarze 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 <stdio.h>
22
#include <stdlib.h>
23
#include <unistd.h>
24
25
static void __dead usage(void);
26
27
int
28
main(int argc, char *argv[])
29
{
30
	int ch;
31
	char *dir;
32
33
396
	if (pledge("stdio flock rpath cpath wpath", NULL) == -1)
34
		err(1, "pledge");
35
36
198
	while ((ch = getopt(argc, argv, "")) != -1) {
37
		switch (ch) {
38
		default:
39
			usage();
40
		}
41
	}
42
198
	argc -= optind;
43
198
	argv += optind;
44
45
198
	if (argc != 1)
46
		usage();
47
48
198
	if ((dir = dirname(argv[0])) == NULL)
49
		err(1, "%s", argv[0]);
50
198
	puts(dir);
51
198
	return 0;
52
}
53
54
extern char *__progname;
55
56
static void __dead
57
usage(void)
58
{
59
	(void)fprintf(stderr, "usage: %s pathname\n", __progname);
60
	exit(1);
61
}