File: config-test.c

package info (click to toggle)
hexer 1.0.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 864 kB
  • sloc: ansic: 11,408; python: 290; makefile: 120; sh: 8
file content (56 lines) | stat: -rw-r--r-- 957 bytes parent folder | download
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
56
/*-
 * SPDX-FileCopyrightText: 2016, 2018 Peter Pentchev
 * SPDX-License-Identifier: BSD-3-Clause
 */

#if defined(TEST_SIGTYPE_INT)
#include <signal.h>
#elif defined(TEST_ALLOCA_H)
#include <alloca.h>
#elif defined(TEST_VASPRINTF)
#define _GNU_SOURCE
#include <stdarg.h>
#include <stdio.h>
#else
#error No option to test
#endif

#if defined(TEST_SIGTYPE_INT)
static int handler(void)
{
	return 1;
}
#endif

#if defined(TEST_VASPRINTF)
static const char *run_vasprintf(char * const dst, ...)
{
	char *res;
	int ret;
	va_list v;

	va_start(v, dst);
	ret = vasprintf(&res, "%d", v);
	va_end(v);

	return (ret == -1? "0": res);
}
#endif

int main(void)
{
	char buf[128] = "1";

#if defined(TEST_SIGTYPE_INT)
	buf[0] = '0' + (signal(SIGINT, handler) != SIG_ERR);
#elif defined(TEST_ALLOCA_H)
	buf[0] = '1';
#elif defined(TEST_VASPRINTF)
	const char * const res = run_vasprintf(buf, 1);
	buf[0] = res[0];
#else
#error No option to test
#endif

	return buf[0];
}