added exit() to stdlib

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1611 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Daniel Reinhold 2002-10-23 07:27:19 +00:00
parent 23d098b60b
commit 997a2a4349
3 changed files with 60 additions and 0 deletions

View File

@ -255,6 +255,7 @@ KernelStaticLibraryObjects libc.a :
<$(SOURCE_GRIST)!libroot!posix!stdlib>atoi.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>bsearch.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>env.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>exit.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>heapsort.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>merge.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>multibyte.o
@ -399,6 +400,7 @@ KernelLd libroot.so :
<$(SOURCE_GRIST)!libroot!posix!stdlib>atoi.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>bsearch.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>env.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>exit.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>heapsort.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>merge.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>multibyte.o

View File

@ -5,6 +5,7 @@ KernelObjects
<$(SOURCE_GRIST)>atoi.c
<$(SOURCE_GRIST)>bsearch.c
<$(SOURCE_GRIST)>env.c
<$(SOURCE_GRIST)>exit.c
<$(SOURCE_GRIST)>heapsort.c
<$(SOURCE_GRIST)>merge.c
<$(SOURCE_GRIST)>multibyte.c

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) 2002, OpenBeOS Project
*
* This file is part of the OpenBeOS system interface.
* It is distributed under the terms of the OpenBeOS license.
*
*
* Author(s):
* Daniel Reinhold (danielre@users.sf.net)
*
*/
#include <syscalls.h>
#include <stdio.h>
#include <stdlib.h>
// ToDo: move this puppy to a more standard location
#include "../stdio/local.h"
// ToDo: this is supposed to be declared in <stdlib.h>
int atexit(void (*func)(void));
#define _EXIT_STACK_SIZE_ 32
static void (*_Exit_Stack[_EXIT_STACK_SIZE_])(void) = {0};
static int _Exit_SP = 0;
int
atexit(void (*func)(void))
{
// push the function pointer onto the exit stack
if (_Exit_SP < _EXIT_STACK_SIZE_) {
_Exit_Stack[_Exit_SP++] = func;
return 0;
}
return -1;
}
void
exit(int status)
{
// unwind the exit stack, calling the registered functions
while (_Exit_SP > 0)
(*_Exit_Stack[--_Exit_SP])();
// close all open files
(*__cleanup)();
// exit with status code
sys_exit(status);
}