view src/ploki/atechit.c @ 12268:6bbbe2a95120 draft

<b_jonas> slashlearn euclid//Euclid is a short geeky game in which the goal is to do Euclidean compass and straightedge constructions in as few steps as possible. It runs in the browser, found at "http://www.euclidthegame.com/". It was popular among #esoteric regulars in 2016-07.
author HackEso <hackeso@esolangs.org>
date Mon, 16 Dec 2019 23:02:52 +0000
parents ac0403686959
children
line wrap: on
line source

#include "zz.h"
#include "atechit.h"
#include "main.h"

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

enum {MAGIC = 23};
static size_t Aused;
static void (*Afunc[MAGIC])(void);

static void bah(void) {
	for (; Aused; Afunc[--Aused]())
		;
}

void atechit(void (*f)(void)) {
	if (Aused >= sizeof Afunc / sizeof *Afunc) {
		NOTREACHED;
	}
	Afunc[Aused++] = f;
	if (Aused == 1 && atexit(bah)) {
		fprintf(stderr, "%s: atexit(): error message\n", Prog);
		bah();
		exit(EXIT_FAILURE);
	}
}