summaryrefslogtreecommitdiffstats
path: root/testutil/get-signals.c
blob: 2a2ea0344d1b79d9e3ce1a14be3e10c65617c79f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* See LICENSE file for copyright and license details. */
#include "../libsyscalls.h"

#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>

#if defined(__clang__)
# pragma clang diagnostic ignored "-Wunsafe-buffer-usage" /* clang is just being silly */
#endif


int
main(int argc, char **argv)
{
	int os, arch, are_signed;
	const struct libsyscalls_named_number *signals;
	size_t i, nsignals;
	enum libsyscalls_error err;

	if (argc != 5) {
		fprintf(stderr, "usage error\n");
		return 3;
	}

	os = atoi(argv[1]);
	arch = atoi(argv[2]);

	err = libsyscalls_get_signals((enum libsyscalls_os)os, (enum libsyscalls_arch)arch,
	                              &signals, &nsignals, &are_signed);
	if (err == LIBSYSCALLS_E_OSNOSUP || err == LIBSYSCALLS_E_ARCHNOSUP) {
		printf("x\n");
		return 0;
	} else if (err == LIBSYSCALLS_E_NOSIGNALS) {
		return 0;
	} else if (err) {
		fprintf(stderr, "get-signals %s %s: ", argv[3], argv[4]);
		libsyscalls_perror(NULL, err);
		return 1;
	}

	if (are_signed) {
		for (i = 0; i < nsignals; i++)
			printf("%+lli %s\n", signals[i].number.s, signals[i].name);
	} else {
		for (i = 0; i < nsignals; i++)
			printf("%llu %s\n", signals[i].number.u, signals[i].name);
	}

	if (fflush(stdout) || fclose(stdout)) {
		perror(NULL);
		return 1;
	}
	return 0;
}