Files
kolibrios/programs/develop/ktcc/libc.obj/include/stdlib.h
T
Egor00fandBurer d486c6b33a libc.obj: update exit (#340)
## New functions:
+ implement `_exit`/`_Exit`.
+ implement `atexit`.
+ implement `abort`.
`abort` write `Aborted pid: %d` to debug board

## Changes:

### call `exit` after main.
Just calling `exit`

### `exit` write exit code
If exit code isn't 0 `exit` will write exit code to debug board.

### use `con_exit(0)`
use
```c
con_exit(0)
```
instead of
```c
con_exit(status);
```
[from console.obj readme](310999dcc4/programs/develop/libraries/console_coff/console_en.txt (L15)).
I think the console window shouldn't be so dependent on the exit code. It's must only always close or always stay on screen

### `exit` writing exit code to debug board
Since the exit code is not used anywhere right now, I think it's better to just show it on the debug board.

for auto rebuild `crt0.o` need #339

from #311

---------

Co-authored-by: Burer <burer@kolibrios.org>
Reviewed-on: KolibriOS/kolibrios#340
Reviewed-by: Mikhail Frolov <mixa.frolov2003@gmail.com>
Reviewed-by: Burer <burer@kolibrios.org>
Co-authored-by: Egor00f <y.yarin@inbox.ru>
Co-committed-by: Egor00f <y.yarin@inbox.ru>
2026-05-19 10:30:46 +00:00

81 lines
1.6 KiB
C

#ifndef _STDLIB_H_
#define _STDLIB_H_
#include <stddef.h>
#define RAND_MAX 65535
#ifndef NULL
#define NULL ((void*)0)
#endif
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
typedef struct {
int quot;
int rem;
} div_t;
typedef struct {
long quot;
long rem;
} ldiv_t;
typedef struct {
long long quot;
long long rem;
} lldiv_t;
static inline div_t div(int num, int den)
{
return (div_t) { num / den, num % den };
}
static inline ldiv_t ldiv(long num, long den)
{
return (ldiv_t) { num / den, num % den };
}
static inline lldiv_t lldiv(long long num, long long den)
{
return (lldiv_t) { num / den, num % den };
}
DLLAPI void* malloc(size_t size);
DLLAPI void* calloc(size_t num, size_t size);
DLLAPI void* realloc(void* ptr, size_t newsize);
DLLAPI void free(void* ptr);
DLLAPI long int strtol(const char* str, char** endptr, int base);
DLLAPI int atexit(void (*func)(void));
DLLAPI void exit(int status);
DLLAPI void _exit(int status);
#ifndef _Exit
#define _Exit(status) _exit(status)
#endif
DLLAPI void abort(void);
DLLAPI void srand(unsigned s);
DLLAPI int rand(void);
DLLAPI void __assert_fail(const char* expr, const char* file, int line, const char* func);
DLLAPI void qsort(void* base0, size_t n, size_t size, int (*compar)(const void*, const void*));
DLLAPI double strtod(const char* s, char** sret);
DLLAPI double atof(const char* ascii);
DLLAPI int atoi(const char* s);
DLLAPI long atol(const char*);
DLLAPI long long atoll(const char*);
DLLAPI void itoa(int n, char* s);
DLLAPI int abs(int);
DLLAPI long labs(long);
DLLAPI long long llabs(long long);
#endif