several additions to libroot:

added abs.c (abs, labs)
  added div.c (div, ldiv)
  added abort() to exit.c


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1636 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Daniel Reinhold
2002-10-24 20:05:09 +00:00
parent 8c75beefbf
commit cd6a80d8c9
5 changed files with 133 additions and 13 deletions
+6 -2
View File
@@ -253,9 +253,11 @@ KernelStaticLibraryObjects libc.a :
<$(SOURCE_GRIST)!libroot!posix!stdio>wbuf.o
<$(SOURCE_GRIST)!libroot!posix!stdio>wsetup.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>assert.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>abs.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>assert.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>atoi.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>bsearch.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>div.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>env.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>exit.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>heapsort.o
@@ -398,9 +400,11 @@ KernelLd libroot.so :
<$(SOURCE_GRIST)!libroot!posix!stdio>wbuf.o
<$(SOURCE_GRIST)!libroot!posix!stdio>wsetup.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>assert.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>abs.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>assert.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>atoi.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>bsearch.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>div.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>env.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>exit.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>heapsort.o
+2
View File
@@ -1,9 +1,11 @@
SubDir OBOS_TOP src kernel libroot posix stdlib ;
KernelObjects
<$(SOURCE_GRIST)>abs.c
<$(SOURCE_GRIST)>assert.c
<$(SOURCE_GRIST)>atoi.c
<$(SOURCE_GRIST)>bsearch.c
<$(SOURCE_GRIST)>div.c
<$(SOURCE_GRIST)>env.c
<$(SOURCE_GRIST)>exit.c
<$(SOURCE_GRIST)>heapsort.c
+36
View File
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2002, OpenBeOS Project.
* All rights reserved.
* Distributed under the terms of the OpenBeOS license.
*
*
* abs.c:
* implements the standard C library functions:
* abs, labs
*
*
* Author(s):
* Daniel Reinhold ([email protected])
*
*/
// ToDo: these are supposed to be declared in <stdlib.h>
// - - - - - - - - - - - - - - -
int abs(int);
long labs(long);
// - - - - - - - - - - - - - - -
int
abs(int i)
{
return ((i < 0) ? -i : i);
}
long
labs(long i)
{
return ((i < 0) ? -i : i);
}
+58
View File
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2002, OpenBeOS Project.
* All rights reserved.
* Distributed under the terms of the OpenBeOS license.
*
*
* div.c:
* implements the standard C library functions:
* div, ldiv
*
*
* Author(s):
* Daniel Reinhold ([email protected])
*
*/
// ToDo: these are supposed to be declared in <stdlib.h>
// - - - - - - - - - - - - - - -
#include <div_t.h>
div_t div(int, int);
ldiv_t ldiv(long, long);
// - - - - - - - - - - - - - - -
div_t
div(int numerator, int denominator)
{
div_t val;
val.quot = numerator / denominator;
val.rem = numerator - denominator * val.quot;
if ((val.rem > 0) && (val.quot < 0)) {
val.rem -= denominator;
++val.quot;
}
return val;
}
ldiv_t
ldiv(long numerator, long denominator)
{
ldiv_t val;
val.quot = numerator / denominator;
val.rem = numerator - denominator * val.quot;
if ((val.rem > 0) && (val.quot < 0)) {
val.rem -= denominator;
++val.quot;
}
return val;
}
+31 -11
View File
@@ -1,39 +1,59 @@
/*
* Copyright (c) 2002, OpenBeOS Project
*
* This file is part of the OpenBeOS system interface.
* It is distributed under the terms of the OpenBeOS license.
* Copyright (c) 2002, OpenBeOS Project.
* All rights reserved.
* Distributed under the terms of the OpenBeOS license.
*
*
* Author(s):
* Daniel Reinhold ([email protected])
* exit.c:
* implements the standard C library functions:
* abort, atexit, exit
*
*
* Author(s):
* Daniel Reinhold ([email protected])
*
*/
#include <syscalls.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <limits.h>
// ToDo: move this puppy to a more standard location
#include "../stdio/local.h"
// ToDo: this is supposed to be declared in <stdlib.h>
// ToDo: these are supposed to be declared in <stdlib.h>
// - - - - - - - - - - - - - - -
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
void abort(void);
int atexit(void (*func)(void));
// - - - - - - - - - - - - - - -
#define _EXIT_STACK_SIZE_ 32
static void (*_Exit_Stack[_EXIT_STACK_SIZE_])(void) = {0};
static void (*_Exit_Stack[ATEXIT_MAX])(void) = {0};
static int _Exit_SP = 0;
void
abort()
{
// ToDo: uncomment the raise() call once it is implemented
//raise(SIGABRT);
exit(EXIT_FAILURE);
}
int
atexit(void (*func)(void))
{
// push the function pointer onto the exit stack
if (_Exit_SP < _EXIT_STACK_SIZE_) {
if (_Exit_SP < ATEXIT_MAX) {
_Exit_Stack[_Exit_SP++] = func;
return 0;
}