summaryrefslogtreecommitdiff
path: root/util/libreboot-utils/lottery.c
blob: fd39c68cffb2ccf70958b2ff5777690d3a63ea80 (plain)
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
57
58
59
60
61
62
63
64
65
66
67
/* SPDX-License-Identifier: MIT                                        ( >:3 )
 * Copyright (c) 2026 Leah Rowe <leah@libreboot.org>                    /| |\
   Something something non-determinism                                   / \ */

#include <ctype.h>
#include <stddef.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include "include/common.h"

static void
exit_cleanup(void);

int
main(int argc, char **argv)
{
	int same = 0;
	char *buf;
	size_t size = 8589934592;
	(void) argc, (void) argv;

	(void) errhook(exit_cleanup);
	(void) lbsetprogname(argv[0]);

	/* https://man.openbsd.org/pledge.2 */
	xpledgex("stdio", NULL);

	buf = rmalloc(size);
	if (!memcmp(buf, buf + (size >> 1), size >> 1))
		same = 1;

	if (argc < 2) /* no spew */
		spew_hex(buf, size);
	free_and_set_null(&buf);

	fprintf(stderr, "\n%s\n", same ? "You win!" : "You lose!");
	return same ^ 1;
}

static void
exit_cleanup(void)
{
#if defined(__OpenBSD__)
	fprintf(stderr, "OpenBSD wins\n");
#elif defined(__FreeBSD__)
	fprintf(stderr, "FreeBSD wins\n");
#elif defined(__NetBSD__)
	fprintf(stderr, "NetBSD wins\n");
#elif defined(__APPLE__)
	fprintf(stderr, "MacOS wins\n");
#elif defined(__DragonFly__)
	fprintf(stderr, "DragonFly BSD wins\n");
#elif defined(__linux__)
#if defined(__GLIBC__)
	fprintf(stderr, "GNU/Linux wins\n");
#elif defined(__MUSL__)
	fprintf(stderr, "Rich Felker wins\n");
#else
	fprintf(stderr, "Linux wins\n");
#endif
#else
	fprintf(stderr, "Your operating system wins\n");
#endif
	return;
}