GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.bin/arch/arch.c Lines: 13 26 50.0 %
Date: 2016-12-06 Branches: 6 14 42.9 %

Line Branch Exec Source
1
/*
2
 * Copyright (c) 1994 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
16
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
17
 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#include <sys/param.h>	/* MACHINE MACHINE_ARCH */
27
28
#include <stdio.h>
29
#include <stdlib.h>
30
#include <string.h>
31
#include <unistd.h>
32
33
static void __dead usage(void);
34
35
static int machine;
36
37
int
38
main(int argc, char *argv[])
39
3
{
40
	extern char *__progname;
41
3
	int short_form = 0, c;
42
	char *arch, *opts;
43
44
3
	machine = strcmp(__progname, "machine") == 0;
45
3
	if (machine) {
46
		arch = MACHINE;
47
		opts = "a";
48
		short_form = 1;
49
	} else {
50
3
		arch = MACHINE_ARCH;
51
3
		opts = "ks";
52
	}
53
5
	while ((c = getopt(argc, argv, opts)) != -1) {
54

2
		switch (c) {
55
		case 'a':
56
			arch = MACHINE_ARCH;
57
			break;
58
		case 'k':
59
2
			arch = MACHINE;
60
2
			break;
61
		case 's':
62
			short_form = 1;
63
			break;
64
		default:
65
			usage();
66
		}
67
	}
68
3
	if (optind != argc)
69
		usage();
70
71
3
	printf("%s%s\n", short_form ? "" : "OpenBSD.", arch);
72
3
	return (0);
73
}
74
75
static void __dead
76
usage(void)
77
{
78
	if (machine)
79
		fprintf(stderr, "usage: machine [-a]\n");
80
	else
81
		fprintf(stderr, "usage: arch [-ks]\n");
82
	exit(1);
83
}