exit.c 359 Bytes
Newer Older
1
/*
2
 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
3
 *
dp-arm's avatar
dp-arm committed
4
 * SPDX-License-Identifier: BSD-3-Clause
5
6
 */

7
#include <stdlib.h>
8

Roberto Vargas's avatar
Roberto Vargas committed
9
10
11
static void (*exitfun)(void);

void exit(int status)
12
{
13
	if (exitfun != NULL)
Roberto Vargas's avatar
Roberto Vargas committed
14
15
16
17
18
19
20
		(*exitfun)();
	for (;;)
		;
}

int atexit(void (*fun)(void))
{
21
	if (exitfun != NULL)
Roberto Vargas's avatar
Roberto Vargas committed
22
23
24
25
		return -1;
	exitfun = fun;

	return 0;
26
}