2006-04-06 11:04:34 +04:00
|
|
|
/*
|
2012-07-19 22:11:40 +04:00
|
|
|
* Copyright 2002-2012 Haiku, Inc. All Rights Reserved.
|
2006-04-06 11:04:34 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2002-10-25 15:50:13 +04:00
|
|
|
#ifndef _STDLIB_H_
|
|
|
|
#define _STDLIB_H_
|
|
|
|
|
2006-04-06 11:04:34 +04:00
|
|
|
|
|
|
|
#include <alloca.h>
|
2002-10-25 15:50:13 +04:00
|
|
|
#include <div_t.h>
|
|
|
|
#include <limits.h>
|
2006-04-06 11:04:34 +04:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <sys/types.h>
|
2014-12-14 14:57:33 +03:00
|
|
|
#include <sys/wait.h>
|
2006-04-06 11:04:34 +04:00
|
|
|
#include <wchar_t.h>
|
2002-10-25 15:50:13 +04:00
|
|
|
|
|
|
|
#define RAND_MAX 0x7fffffff
|
2011-11-22 20:32:39 +04:00
|
|
|
#define MB_CUR_MAX (__ctype_get_mb_cur_max())
|
2002-10-25 15:50:13 +04:00
|
|
|
|
|
|
|
#define EXIT_SUCCESS 0
|
|
|
|
#define EXIT_FAILURE 1
|
|
|
|
|
2002-10-26 02:02:50 +04:00
|
|
|
/* random data structures (for thread-safe random numbers) */
|
|
|
|
struct random_data {
|
2008-08-01 19:02:03 +04:00
|
|
|
int *fptr;
|
|
|
|
int *rptr;
|
|
|
|
int *state;
|
|
|
|
int rand_type;
|
|
|
|
int rand_deg;
|
|
|
|
int rand_sep;
|
|
|
|
int *end_ptr;
|
2002-10-26 02:02:50 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct drand48_data {
|
2008-08-01 19:02:03 +04:00
|
|
|
unsigned short int x[3];
|
|
|
|
unsigned short int a[3];
|
|
|
|
unsigned short int c;
|
|
|
|
unsigned short int old_x[3];
|
|
|
|
int init;
|
2002-10-26 02:02:50 +04:00
|
|
|
};
|
|
|
|
|
2002-10-25 15:50:13 +04:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2002-10-26 02:02:50 +04:00
|
|
|
/* memory allocation (see malloc.h for additional defines & prototypes) */
|
2007-08-16 14:04:44 +04:00
|
|
|
extern void *calloc(size_t numElements, size_t size);
|
2002-10-26 02:02:50 +04:00
|
|
|
extern void free(void *pointer);
|
|
|
|
extern void *malloc(size_t size);
|
2007-08-16 14:04:44 +04:00
|
|
|
extern int posix_memalign(void **_pointer, size_t alignment, size_t size);
|
|
|
|
extern void *realloc(void *oldPointer, size_t newSize);
|
2002-10-26 02:02:50 +04:00
|
|
|
|
|
|
|
/* process termination */
|
|
|
|
extern void abort(void);
|
|
|
|
extern int atexit(void (*func)(void));
|
|
|
|
extern int atfork(void (*func)(void));
|
2019-06-15 19:14:06 +03:00
|
|
|
extern void exit(int) __attribute__((noreturn));
|
|
|
|
extern void _Exit(int) __attribute__((noreturn));
|
2002-10-26 02:02:50 +04:00
|
|
|
|
|
|
|
/* misc functions */
|
|
|
|
extern char *realpath(const char *path, char *resolved);
|
|
|
|
|
|
|
|
extern int system(const char *command);
|
|
|
|
|
|
|
|
extern char *mktemp(char *name);
|
2009-01-25 20:11:22 +03:00
|
|
|
extern char *mkdtemp(char *templat);
|
2002-10-26 04:06:00 +04:00
|
|
|
extern int mkstemp(char *templat);
|
2002-10-26 02:02:50 +04:00
|
|
|
|
2008-02-06 20:11:02 +03:00
|
|
|
extern char *ecvt(double value, int digits, int *_decimalPoint, int *_sign);
|
|
|
|
extern char *fcvt(double value, int precision, int *_decimalPoint,
|
|
|
|
int *_sign);
|
|
|
|
extern char *gcvt(double value, int digits, char *buffer);
|
|
|
|
|
2014-12-14 14:57:33 +03:00
|
|
|
extern char *l64a(long n);
|
|
|
|
extern long a64l(const char *string);
|
|
|
|
|
2002-10-26 02:02:50 +04:00
|
|
|
/* environment variables */
|
|
|
|
extern char **environ;
|
2008-08-01 19:02:03 +04:00
|
|
|
extern int clearenv(void);
|
2002-10-26 02:02:50 +04:00
|
|
|
extern char *getenv(const char *name);
|
2019-07-18 23:14:54 +03:00
|
|
|
extern int putenv(char *string);
|
2002-10-26 02:02:50 +04:00
|
|
|
extern int setenv(char const *name, char const *value, int rewrite);
|
2003-08-02 08:55:14 +04:00
|
|
|
extern int unsetenv(const char *name);
|
2002-10-26 02:02:50 +04:00
|
|
|
|
|
|
|
/* ASCII string to number conversion */
|
|
|
|
extern double atof(const char *string);
|
|
|
|
extern int atoi(const char *string);
|
|
|
|
extern long atol(const char *string);
|
|
|
|
extern long long int atoll(const char *string);
|
|
|
|
extern unsigned int atoui(const char *string);
|
|
|
|
extern unsigned long atoul(const char *string);
|
|
|
|
|
|
|
|
extern double strtod(const char *string, char **end);
|
2010-09-18 20:42:59 +04:00
|
|
|
extern long double strtold(const char *string, char **end);
|
2009-07-29 21:33:30 +04:00
|
|
|
extern float strtof(const char *string, char **end);
|
2002-10-26 02:02:50 +04:00
|
|
|
extern long strtol(const char *string, char **end, int base);
|
|
|
|
extern unsigned long strtoul(const char *string, char **end, int base);
|
|
|
|
extern long long strtoll(const char *string, char **end, int base);
|
|
|
|
extern unsigned long long strtoull(const char *string, char **end, int base);
|
|
|
|
|
|
|
|
/* random number generation */
|
|
|
|
extern void srand(unsigned int seed);
|
|
|
|
extern int rand(void);
|
|
|
|
extern int random(void);
|
|
|
|
extern void srandom(unsigned int seed);
|
|
|
|
extern int rand_r(unsigned int *seed);
|
|
|
|
extern int random_r(struct random_data *data, int *result);
|
|
|
|
extern int srandom_r(unsigned int seed, struct random_data *data);
|
|
|
|
extern char *initstate(unsigned int seed, char *state, size_t size);
|
|
|
|
extern char *setstate(char *state);
|
2008-08-01 19:02:03 +04:00
|
|
|
extern int initstate_r(unsigned int seed, void *stateBuffer,
|
2002-10-26 02:02:50 +04:00
|
|
|
size_t stateLength, struct random_data *data);
|
|
|
|
extern int setstate_r(void *stateBuffer, struct random_data *data);
|
|
|
|
|
|
|
|
extern double drand48(void);
|
|
|
|
extern double erand48(unsigned short int xsubi[3]);
|
|
|
|
extern long lrand48(void);
|
|
|
|
extern long nrand48(unsigned short int xsubi[3]);
|
|
|
|
extern long mrand48(void);
|
|
|
|
extern long jrand48(unsigned short int xsubi[3]);
|
|
|
|
extern void srand48(long int seed);
|
|
|
|
extern unsigned short *seed48(unsigned short int seed16v[3]);
|
|
|
|
extern void lcong48(unsigned short int param[7]);
|
|
|
|
|
|
|
|
extern int drand48_r(struct drand48_data *data, double *result);
|
|
|
|
extern int erand48_r(unsigned short int xsubi[3],
|
|
|
|
struct drand48_data *data, double *result);
|
|
|
|
extern int lrand48_r(struct drand48_data *data, long int *result);
|
|
|
|
extern int nrand48_r(unsigned short int xsubi[3],
|
|
|
|
struct drand48_data *data, long int *result);
|
|
|
|
extern int mrand48_r(struct drand48_data *data, long int *result);
|
|
|
|
extern int jrand48_r(unsigned short int xsubi[3],
|
|
|
|
struct drand48_data *data, long int *result);
|
|
|
|
extern int srand48_r(long int seed, struct drand48_data *data);
|
|
|
|
extern int seed48_r(unsigned short int seed16v[3],
|
|
|
|
struct drand48_data *data);
|
|
|
|
extern int lcong48_r(unsigned short int param[7],
|
|
|
|
struct drand48_data *data);
|
|
|
|
|
|
|
|
/* search and sort functions */
|
|
|
|
typedef int (*_compare_function)(const void *, const void *);
|
|
|
|
|
|
|
|
extern void *bsearch(const void *key, const void *base, size_t numElements,
|
|
|
|
size_t sizeOfElement, _compare_function);
|
2008-02-06 20:11:02 +03:00
|
|
|
extern int heapsort(void *base, size_t numElements, size_t sizeOfElement,
|
|
|
|
_compare_function);
|
|
|
|
extern int mergesort(void *base, size_t numElements, size_t sizeOfElement,
|
|
|
|
_compare_function);
|
|
|
|
extern void qsort(void *base, size_t numElements, size_t sizeOfElement,
|
|
|
|
_compare_function);
|
|
|
|
extern int radixsort(u_char const **base, int numElements,
|
|
|
|
u_char const *table, u_int endByte);
|
|
|
|
extern int sradixsort(u_char const **base, int numElements,
|
|
|
|
u_char const *table, u_int endByte);
|
2002-10-26 02:02:50 +04:00
|
|
|
|
|
|
|
/* misc math functions */
|
|
|
|
extern int abs(int number);
|
|
|
|
extern long labs(long number);
|
|
|
|
extern long long llabs(long long number);
|
|
|
|
|
|
|
|
extern div_t div(int numerator, int denominator);
|
|
|
|
extern ldiv_t ldiv(long numerator, long denominator);
|
|
|
|
extern lldiv_t lldiv(long long numerator, long long denominator);
|
|
|
|
|
|
|
|
/* wide & multibyte string functions */
|
|
|
|
extern int mblen(const char *string, size_t maxSize);
|
|
|
|
extern int mbtowc(wchar_t *pwc, const char *string, size_t maxSize);
|
|
|
|
extern int wctomb(char *string, wchar_t wchar);
|
|
|
|
extern size_t mbstowcs(wchar_t *pwcs, const char *string, size_t maxSize);
|
|
|
|
extern size_t wcstombs(char *string, const wchar_t *pwcs, size_t maxSize);
|
2002-10-25 15:50:13 +04:00
|
|
|
|
2006-03-16 14:09:43 +03:00
|
|
|
/* crypt */
|
2008-08-01 19:02:03 +04:00
|
|
|
extern void setkey(const char *key);
|
2006-03-16 14:09:43 +03:00
|
|
|
|
2010-09-14 22:43:24 +04:00
|
|
|
/* sub-option parsing */
|
|
|
|
extern int getsubopt(char **optionp, char * const *keylistp,
|
|
|
|
char **valuep);
|
2008-04-25 01:29:13 +04:00
|
|
|
|
|
|
|
/* pty functions */
|
|
|
|
extern int posix_openpt(int openFlags);
|
|
|
|
extern int grantpt(int masterFD);
|
|
|
|
extern char* ptsname(int masterFD);
|
|
|
|
extern int unlockpt(int masterFD);
|
|
|
|
|
2011-11-22 20:32:39 +04:00
|
|
|
/* internal accessor to value for MB_CUR_MAX */
|
|
|
|
extern unsigned short __ctype_get_mb_cur_max(void);
|
|
|
|
|
2002-10-25 15:50:13 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} /* extern "C" */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _STDLIB_H_ */
|