xref: /rk3399_ARM-atf/lib/libc/exit.c (revision 6c3733456706809d5c9fb78a9746bf2fa484fb91)
161f72a34SRoberto Vargas /*
261f72a34SRoberto Vargas  * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
361f72a34SRoberto Vargas  *
461f72a34SRoberto Vargas  * SPDX-License-Identifier: BSD-3-Clause
561f72a34SRoberto Vargas  */
661f72a34SRoberto Vargas 
761f72a34SRoberto Vargas #include <stdlib.h>
861f72a34SRoberto Vargas 
9*6c373345SRoberto Vargas static void (*exitfun)(void);
10*6c373345SRoberto Vargas 
11*6c373345SRoberto Vargas void exit(int status)
1261f72a34SRoberto Vargas {
13*6c373345SRoberto Vargas 	if (exitfun)
14*6c373345SRoberto Vargas 		(*exitfun)();
15*6c373345SRoberto Vargas 	for (;;)
16*6c373345SRoberto Vargas 		;
17*6c373345SRoberto Vargas }
18*6c373345SRoberto Vargas 
19*6c373345SRoberto Vargas int atexit(void (*fun)(void))
20*6c373345SRoberto Vargas {
21*6c373345SRoberto Vargas 	if (exitfun)
22*6c373345SRoberto Vargas 		return -1;
23*6c373345SRoberto Vargas 	exitfun = fun;
24*6c373345SRoberto Vargas 
25*6c373345SRoberto Vargas 	return 0;
2661f72a34SRoberto Vargas }
27