mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-11 05:52:36 +02:00
d2abde5303
where possible, try not to clobber sys errno. override it only when relatively safe. also: when a syscall succeeds, it may set errno. this is rare, but permitted (nothing specified against it in specs, and the specs say that errno is undefined on success). i'm not libc, but i'm wrapping around it, so i need to be careful in how i handle the errno value. also: i removed the requirement for directories to be executable, in mkhtemp.c, because this isn't required and will only break certain setups. in world_writeable and sticky, i made the checks stricter: the faccessat check was being skipped on some paths, so i've closed that loophole now. i also generally cleaned up some code, as part of the errno handling refactoring, where it made sense to do so, plus a few other bits of code cleanup. Signed-off-by: Leah Rowe <leah@libreboot.org>
69 lines
1.5 KiB
C
69 lines
1.5 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)
|
|
{
|
|
int same = 0;
|
|
char *buf;
|
|
size_t size = BUFSIZ;
|
|
(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 (!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;
|
|
}
|