2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2018-10-24 13:43:52 +03:00
|
|
|
#pragma once
|
|
|
|
|
2021-12-19 22:59:21 +03:00
|
|
|
#include <bits/wchar.h>
|
2019-05-28 12:53:16 +03:00
|
|
|
#include <stddef.h>
|
2018-10-31 04:09:11 +03:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#include <sys/types.h>
|
2018-10-24 13:43:52 +03:00
|
|
|
|
2018-10-31 04:09:11 +03:00
|
|
|
__BEGIN_DECLS
|
2018-10-24 13:43:52 +03:00
|
|
|
|
2018-11-17 17:56:09 +03:00
|
|
|
#define EXIT_SUCCESS 0
|
|
|
|
#define EXIT_FAILURE 1
|
|
|
|
|
2022-01-08 17:32:59 +03:00
|
|
|
__attribute__((noreturn)) void _abort(void);
|
2021-12-16 19:58:07 +03:00
|
|
|
|
2019-02-16 00:37:20 +03:00
|
|
|
__attribute__((malloc)) __attribute__((alloc_size(1))) void* malloc(size_t);
|
|
|
|
__attribute__((malloc)) __attribute__((alloc_size(1, 2))) void* calloc(size_t nmemb, size_t);
|
2022-01-12 12:54:09 +03:00
|
|
|
size_t malloc_size(void const*);
|
2021-05-15 11:06:41 +03:00
|
|
|
size_t malloc_good_size(size_t);
|
2020-12-24 18:41:54 +03:00
|
|
|
void serenity_dump_malloc_stats(void);
|
2018-10-24 13:43:52 +03:00
|
|
|
void free(void*);
|
2020-08-13 20:14:28 +03:00
|
|
|
__attribute__((alloc_size(2))) void* realloc(void* ptr, size_t);
|
2022-04-01 20:58:27 +03:00
|
|
|
char* getenv(char const* name);
|
|
|
|
char* secure_getenv(char const* name);
|
2019-02-26 14:57:02 +03:00
|
|
|
int putenv(char*);
|
2023-02-04 18:44:33 +03:00
|
|
|
int serenity_putenv(char const* new_var, size_t length);
|
2022-04-01 20:58:27 +03:00
|
|
|
int unsetenv(char const*);
|
2020-12-24 18:41:54 +03:00
|
|
|
int clearenv(void);
|
2022-04-01 20:58:27 +03:00
|
|
|
int setenv(char const* name, char const* value, int overwrite);
|
|
|
|
char const* getprogname(void);
|
|
|
|
void setprogname(char const*);
|
|
|
|
int atoi(char const*);
|
|
|
|
long atol(char const*);
|
|
|
|
long long atoll(char const*);
|
|
|
|
double strtod(char const*, char** endptr);
|
|
|
|
long double strtold(char const*, char** endptr);
|
|
|
|
float strtof(char const*, char** endptr);
|
|
|
|
long strtol(char const*, char** endptr, int base);
|
|
|
|
long long strtoll(char const*, char** endptr, int base);
|
|
|
|
unsigned long long strtoull(char const*, char** endptr, int base);
|
|
|
|
unsigned long strtoul(char const*, char** endptr, int base);
|
|
|
|
void qsort(void* base, size_t nmemb, size_t size, int (*compar)(void const*, void const*));
|
|
|
|
void qsort_r(void* base, size_t nmemb, size_t size, int (*compar)(void const*, void const*, void*), void* arg);
|
2022-01-08 17:32:59 +03:00
|
|
|
int atexit(void (*function)(void));
|
2019-02-16 00:37:20 +03:00
|
|
|
__attribute__((noreturn)) void exit(int status);
|
2022-01-08 17:32:59 +03:00
|
|
|
__attribute__((noreturn)) void abort(void);
|
2019-01-15 08:30:19 +03:00
|
|
|
char* ptsname(int fd);
|
|
|
|
int ptsname_r(int fd, char* buffer, size_t);
|
2019-01-23 08:35:34 +03:00
|
|
|
int abs(int);
|
2019-02-25 12:05:32 +03:00
|
|
|
long labs(long);
|
2021-04-29 02:17:06 +03:00
|
|
|
long long int llabs(long long int);
|
2022-04-01 20:58:27 +03:00
|
|
|
double atof(char const*);
|
|
|
|
int system(char const* command);
|
2019-02-08 04:38:21 +03:00
|
|
|
char* mktemp(char*);
|
2019-11-16 13:34:20 +03:00
|
|
|
int mkstemp(char*);
|
2022-09-03 20:35:47 +03:00
|
|
|
int mkstemps(char*, int);
|
2019-09-12 14:43:52 +03:00
|
|
|
char* mkdtemp(char*);
|
2022-04-01 20:58:27 +03:00
|
|
|
void* bsearch(void const* key, void const* base, size_t nmemb, size_t size, int (*compar)(void const*, void const*));
|
2021-06-04 02:46:41 +03:00
|
|
|
int mblen(char const*, size_t);
|
2022-04-01 20:58:27 +03:00
|
|
|
size_t mbstowcs(wchar_t*, char const*, size_t);
|
|
|
|
int mbtowc(wchar_t*, char const*, size_t);
|
2019-10-13 04:47:25 +03:00
|
|
|
int wctomb(char*, wchar_t);
|
2022-04-01 20:58:27 +03:00
|
|
|
size_t wcstombs(char*, wchar_t const*, size_t);
|
|
|
|
char* realpath(char const* pathname, char* buffer);
|
2021-05-08 21:46:06 +03:00
|
|
|
__attribute__((noreturn)) void _Exit(int status);
|
2018-10-24 13:43:52 +03:00
|
|
|
|
2019-01-14 17:25:34 +03:00
|
|
|
#define RAND_MAX 32767
|
2022-01-08 17:32:59 +03:00
|
|
|
int rand(void);
|
2019-01-14 17:25:34 +03:00
|
|
|
void srand(unsigned seed);
|
|
|
|
|
2022-01-08 17:32:59 +03:00
|
|
|
long int random(void);
|
2019-02-01 18:03:21 +03:00
|
|
|
void srandom(unsigned seed);
|
|
|
|
|
2020-12-24 18:41:54 +03:00
|
|
|
uint32_t arc4random(void);
|
2019-10-13 18:26:42 +03:00
|
|
|
void arc4random_buf(void*, size_t);
|
|
|
|
uint32_t arc4random_uniform(uint32_t);
|
|
|
|
|
2019-05-28 12:53:16 +03:00
|
|
|
typedef struct {
|
|
|
|
int quot;
|
|
|
|
int rem;
|
|
|
|
} div_t;
|
2019-02-05 15:38:32 +03:00
|
|
|
div_t div(int, int);
|
2019-05-28 12:53:16 +03:00
|
|
|
typedef struct {
|
|
|
|
long quot;
|
|
|
|
long rem;
|
|
|
|
} ldiv_t;
|
2019-02-05 15:38:32 +03:00
|
|
|
ldiv_t ldiv(long, long);
|
2021-03-07 19:09:44 +03:00
|
|
|
typedef struct {
|
|
|
|
long long quot;
|
|
|
|
long long rem;
|
|
|
|
} lldiv_t;
|
|
|
|
lldiv_t lldiv(long long, long long);
|
2019-02-05 15:38:32 +03:00
|
|
|
|
2020-02-05 23:17:41 +03:00
|
|
|
int posix_openpt(int flags);
|
|
|
|
int grantpt(int fd);
|
|
|
|
int unlockpt(int fd);
|
|
|
|
|
2022-04-21 12:10:41 +03:00
|
|
|
int posix_memalign(void**, size_t alignment, size_t size);
|
LibC: Implement posix_memalign(3) and aligned_alloc(3)
Some ports linked against posix_memalign, but didn't use it, and others
used it if it was Available. So I decided to implement posix_memalign.
My implementation adds almost no overhead to regular mallocs. However,
if an alignment is specified, it will use the smallest ChunkedBlock, for
which aligned chunks exist, and simply use one of the chunks that is
aligned. If it cannot use a ChunkedBlock, for size or alignment reasons,
it will use a BigAllocationBlock, and return a pointer to the first
aligned address past the start of the block. This implementation
supports alignments up to 32768, due to the limitations of the
BigAllocationBlock technique.
2022-05-05 08:08:57 +03:00
|
|
|
__attribute__((malloc, alloc_size(2), alloc_align(1))) void* aligned_alloc(size_t alignment, size_t size);
|
2022-04-21 12:10:41 +03:00
|
|
|
|
2018-10-31 04:09:11 +03:00
|
|
|
__END_DECLS
|