2021-05-09 23:00:11 +02:00
|
|
|
#ifndef __STDLIB_H__
|
|
|
|
# define __STDLIB_H__
|
2020-09-17 19:27:01 +02:00
|
|
|
|
2021-06-28 15:49:05 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2020-09-17 19:27:01 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
2021-05-29 16:45:35 +02:00
|
|
|
#include <bits/exit.h>
|
2020-09-17 19:27:01 +02:00
|
|
|
|
2021-05-18 21:25:45 +02:00
|
|
|
/* Dynamic memory management. */
|
|
|
|
|
2020-10-14 11:45:08 +02:00
|
|
|
/* Allocate SIZE bytes of memory. */
|
2021-05-19 10:12:41 +02:00
|
|
|
extern void *malloc(size_t __size);
|
2020-10-14 11:45:08 +02:00
|
|
|
|
|
|
|
/* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
|
2021-05-19 10:12:41 +02:00
|
|
|
extern void *calloc(size_t __nmemb, size_t __size);
|
2020-10-14 11:45:08 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Re-allocate the previously allocated block in PTR, making the new block
|
|
|
|
** SIZE bytes long.
|
|
|
|
*/
|
2021-05-19 10:12:41 +02:00
|
|
|
extern void *realloc(void *__ptr, size_t __size);
|
2020-10-14 11:45:08 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Re-allocate the previously allocated block in PTR, making the new block large
|
|
|
|
** enough for NMEMB elements of SIZE bytes each.
|
|
|
|
*/
|
2021-05-19 10:12:41 +02:00
|
|
|
extern void *reallocarray(void *__ptr, size_t __nmemb, size_t __size);
|
2020-10-14 11:45:08 +02:00
|
|
|
|
|
|
|
/* Free a block allocated by `malloc', `realloc' or `calloc'. */
|
2021-05-19 10:12:41 +02:00
|
|
|
extern void free(void *__ptr);
|
2020-09-17 19:27:01 +02:00
|
|
|
|
2021-05-29 16:45:35 +02:00
|
|
|
/* Communication with the environment. */
|
|
|
|
|
2021-05-29 18:26:33 +02:00
|
|
|
/* Abort execution; raises SIGABRT and leaves quickly with _Exit(). */
|
2021-05-30 08:59:06 +02:00
|
|
|
__attribute__((noreturn))
|
2021-06-07 21:54:55 +02:00
|
|
|
extern void abort(void);
|
2021-05-29 18:26:33 +02:00
|
|
|
|
2022-09-07 21:03:53 +02:00
|
|
|
/* Register a function to be called at program exit. */
|
2022-08-13 00:01:00 +02:00
|
|
|
extern int atexit(void (*__func)(void));
|
|
|
|
|
2021-05-29 16:45:35 +02:00
|
|
|
/* Exit; calls handlers, flushes and closes streams and temporary files. */
|
2021-05-30 08:59:06 +02:00
|
|
|
__attribute__((noreturn))
|
2021-06-07 21:54:55 +02:00
|
|
|
extern void exit(int __status);
|
2021-05-29 16:45:35 +02:00
|
|
|
|
|
|
|
/* Exit immediately, bypassing exit handlers or signal handlers. */
|
2021-05-30 08:59:06 +02:00
|
|
|
__attribute__((noreturn))
|
2021-06-07 21:54:55 +02:00
|
|
|
extern void _Exit(int __status);
|
2021-05-29 16:45:35 +02:00
|
|
|
|
2022-08-13 00:01:00 +02:00
|
|
|
extern char *getenv(char const *__name);
|
|
|
|
|
|
|
|
extern int system(char const *__string);
|
|
|
|
|
2021-05-18 21:25:45 +02:00
|
|
|
/* Integer arithmetic functions. */
|
|
|
|
|
|
|
|
extern int abs(int __j);
|
|
|
|
#define abs(j) ({ \
|
|
|
|
int __j = (j); \
|
|
|
|
(__j >= 0) ? __j : -(__j); \
|
|
|
|
})
|
|
|
|
|
|
|
|
extern long int labs(long int __j);
|
|
|
|
#define labs(j) ({ \
|
|
|
|
long int __j = (j); \
|
|
|
|
(__j >= 0) ? __j : -(__j); \
|
|
|
|
})
|
|
|
|
|
|
|
|
extern long long int llabs(long long int __j);
|
|
|
|
#define llabs(j) ({ \
|
|
|
|
long long int __j = (j); \
|
|
|
|
(__j >= 0) ? __j : -(__j); \
|
|
|
|
})
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int quot, rem;
|
|
|
|
} div_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
long int quot, rem;
|
|
|
|
} ldiv_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
long long int quot, rem;
|
|
|
|
} lldiv_t;
|
|
|
|
|
2021-06-07 21:54:55 +02:00
|
|
|
extern div_t div(int __num, int __denom);
|
|
|
|
extern ldiv_t ldiv(long int __num, long int __denom);
|
|
|
|
extern lldiv_t lldiv(long long int __num, long long int __denom);
|
2021-05-18 21:25:45 +02:00
|
|
|
|
2021-05-20 11:11:24 +02:00
|
|
|
/* Simplified numeric conversion functions. */
|
|
|
|
|
|
|
|
/* ASCII to int. */
|
|
|
|
extern int atoi(char const *__ptr);
|
|
|
|
|
|
|
|
/* ASCII to long int. */
|
|
|
|
extern long int atol(char const *__ptr);
|
|
|
|
|
|
|
|
/* ASCII to long long int. */
|
|
|
|
extern long long int atoll(char const *__ptr);
|
|
|
|
|
2021-05-19 21:39:33 +02:00
|
|
|
/* Numeric conversion functions. */
|
|
|
|
|
2021-05-21 23:52:54 +02:00
|
|
|
/* ASCII to floating-point. */
|
|
|
|
extern double atof(char const *__ptr);
|
|
|
|
|
2021-05-19 21:39:33 +02:00
|
|
|
/* Parse a long int from a string. */
|
|
|
|
extern long int strtol(
|
2021-06-13 16:51:47 +02:00
|
|
|
char const * __restrict__ __ptr,
|
|
|
|
char ** __restrict__ __endptr,
|
2021-05-19 21:39:33 +02:00
|
|
|
int __base);
|
|
|
|
|
|
|
|
/* Parse a long unsigned int from a string. */
|
|
|
|
extern unsigned long int strtoul(
|
2021-06-13 16:51:47 +02:00
|
|
|
char const * __restrict__ __ptr,
|
|
|
|
char ** __restrict__ __endptr,
|
2021-05-19 21:39:33 +02:00
|
|
|
int __base);
|
|
|
|
|
|
|
|
/* Parse a long long int from a string. */
|
|
|
|
extern long long int strtoll(
|
2021-06-13 16:51:47 +02:00
|
|
|
char const * __restrict__ __ptr,
|
|
|
|
char ** __restrict__ __endptr,
|
2021-05-19 21:39:33 +02:00
|
|
|
int __base);
|
|
|
|
|
|
|
|
/* Parse a long long unsigned int from a string. */
|
|
|
|
extern unsigned long long int strtoull(
|
2021-06-13 16:51:47 +02:00
|
|
|
char const * __restrict__ __ptr,
|
|
|
|
char ** __restrict__ __endptr,
|
2021-05-19 21:39:33 +02:00
|
|
|
int __base);
|
|
|
|
|
|
|
|
/* Parse a double from a string. */
|
|
|
|
extern double strtod(
|
2021-06-13 16:51:47 +02:00
|
|
|
char const * __restrict__ __ptr,
|
|
|
|
char ** __restrict__ __endptr);
|
2021-05-19 21:39:33 +02:00
|
|
|
|
|
|
|
/* Parse a float from a string. */
|
|
|
|
extern float strtof(
|
2021-06-13 16:51:47 +02:00
|
|
|
char const * __restrict__ __ptr,
|
|
|
|
char ** __restrict__ __endptr);
|
2021-05-19 21:39:33 +02:00
|
|
|
|
|
|
|
/* Parse a long double from a string. */
|
|
|
|
extern long double strtold(
|
2021-06-13 16:51:47 +02:00
|
|
|
char const * __restrict__ __ptr,
|
|
|
|
char ** __restrict__ __endptr);
|
2021-05-19 21:39:33 +02:00
|
|
|
|
2021-06-07 21:54:55 +02:00
|
|
|
/* Pseudo-random sequence generation functions. */
|
|
|
|
|
|
|
|
#define RAND_MAX 0x7fffffff
|
|
|
|
|
|
|
|
/* Seed the PRNG. */
|
2022-08-13 00:01:00 +02:00
|
|
|
extern void srand(unsigned int __seed);
|
2021-06-07 21:54:55 +02:00
|
|
|
|
|
|
|
/* Generate a pseudo-random number between 0 and RAND_MAX. */
|
|
|
|
extern int rand(void);
|
|
|
|
|
2021-06-28 15:49:05 +02:00
|
|
|
/* Searching and sorting utilities. */
|
|
|
|
|
2022-08-13 00:01:00 +02:00
|
|
|
extern void *bsearch(void const *__key,
|
|
|
|
void const *__base, size_t __nmemb, size_t __size,
|
|
|
|
int (*__compare)(void const *, void const *));
|
|
|
|
|
|
|
|
extern void qsort(
|
|
|
|
void *__base, size_t __nmemb, size_t __size,
|
|
|
|
int (*__compare)(void const *, void const *));
|
2021-06-28 15:49:05 +02:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-05-09 23:00:11 +02:00
|
|
|
#endif /*__STDLIB_H__*/
|