mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-11 14:02:52 +02:00
7b5349e85d
i should probably test musl as well, on linux libreboot-utils is stable on the glibc systems i tested with linux. it is quite buggy on bsd systems. it's irresponsible to let users compile this until i've properly tested the code. putting this error in for now. i made lbmk use the old nvmutil version for now, and retro fitted several improvements to i/o there from lbutils, changes that i know are stable on bsd. Signed-off-by: Leah Rowe <leah@libreboot.org>
75 lines
1.7 KiB
C
75 lines
1.7 KiB
C
/* 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)
|
|
{
|
|
#ifndef __linux__
|
|
#error This code is currently buggy on BSD systems. Only use on Linux.
|
|
#endif
|
|
int same = 0;
|
|
char *buf;
|
|
size_t size = BUFSIZ;
|
|
(void) argc, (void) argv;
|
|
|
|
(void) errhook(exit_cleanup);
|
|
(void) lbsetprogname(argv[0]);
|
|
|
|
#ifdef __OpenBSD__
|
|
/* https://man.openbsd.org/pledge.2 */
|
|
if (pledge("stdio", NULL) == -1)
|
|
exitf("pledge");
|
|
#endif
|
|
|
|
buf = rmalloc(size);
|
|
if (!vcmp(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 ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
}
|
|
|
|
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;
|
|
}
|