Add atexit function to libc
We had exit but we didn't have atexit, and we were calling panic and
tf_printf from exit, which generated a dependency from exit to them.
Having atexit allows to set a different function pointer in every image.
Change-Id: I95b9556d680d96249ed3b14da159b6f417da7661
Signed-off-by: Roberto Vargas <roberto.vargas@arm.com>
diff --git a/lib/libc/exit.c b/lib/libc/exit.c
index afc3f93..b2fde9c 100644
--- a/lib/libc/exit.c
+++ b/lib/libc/exit.c
@@ -4,11 +4,23 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <debug.h>
#include <stdlib.h>
-void exit(int v)
+static void (*exitfun)(void);
+
+void exit(int status)
+{
+ if (exitfun)
+ (*exitfun)();
+ for (;;)
+ ;
+}
+
+int atexit(void (*fun)(void))
{
- ERROR("EXIT\n");
- panic();
+ if (exitfun)
+ return -1;
+ exitfun = fun;
+
+ return 0;
}