Relicense Sortix to the ISC license.
I hereby relicense all my work on Sortix under the ISC license as below.
All Sortix contributions by other people are already under this license,
are not substantial enough to be copyrightable, or have been removed.
All imported code from other projects is compatible with this license.
All GPL licensed code from other projects had previously been removed.
Copyright 2011-2016 Jonas 'Sortie' Termansen and contributors.
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2016-03-02 17:38:16 -05:00
|
|
|
/*
|
2017-07-10 15:38:10 -04:00
|
|
|
* Copyright (c) 2011-2017 Jonas 'Sortie' Termansen.
|
Relicense Sortix to the ISC license.
I hereby relicense all my work on Sortix under the ISC license as below.
All Sortix contributions by other people are already under this license,
are not substantial enough to be copyrightable, or have been removed.
All imported code from other projects is compatible with this license.
All GPL licensed code from other projects had previously been removed.
Copyright 2011-2016 Jonas 'Sortie' Termansen and contributors.
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2016-03-02 17:38:16 -05:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* stdlib.h
|
|
|
|
* Standard library definitions.
|
|
|
|
*/
|
2011-08-05 08:25:00 -04:00
|
|
|
|
2013-04-21 16:46:44 -04:00
|
|
|
#ifndef _STDLIB_H
|
|
|
|
#define _STDLIB_H 1
|
2011-08-05 08:25:00 -04:00
|
|
|
|
2013-10-13 07:04:27 -04:00
|
|
|
#include <sys/cdefs.h>
|
2013-09-23 10:37:33 -04:00
|
|
|
|
2017-07-10 15:38:10 -04:00
|
|
|
#if __USE_SORTIX || __USE_POSIX
|
2013-09-23 10:37:33 -04:00
|
|
|
#include <sys/__/types.h>
|
2017-07-10 15:38:10 -04:00
|
|
|
#endif
|
2013-09-23 10:37:33 -04:00
|
|
|
|
2014-07-19 15:08:25 -04:00
|
|
|
#if __USE_SORTIX
|
|
|
|
#include <stdint.h>
|
|
|
|
#endif
|
|
|
|
|
2013-01-14 13:24:37 -05:00
|
|
|
#include <sortix/wait.h>
|
2011-08-05 08:25:00 -04:00
|
|
|
|
|
|
|
#define EXIT_SUCCESS (0)
|
|
|
|
#define EXIT_FAILURE (1)
|
|
|
|
|
|
|
|
/* TODO: This random interface is stupid. What should a good value be? */
|
|
|
|
#define RAND_MAX 32767
|
|
|
|
|
2015-08-17 17:16:05 -04:00
|
|
|
#define MB_CUR_MAX 4
|
2012-03-11 15:49:50 -04:00
|
|
|
|
2013-03-19 03:59:26 -04:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int quot;
|
|
|
|
int rem;
|
|
|
|
} div_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
long quot;
|
|
|
|
long rem;
|
|
|
|
} ldiv_t;
|
|
|
|
|
2017-07-10 15:38:10 -04:00
|
|
|
#if 1999 <= __USE_C || defined(__cplusplus)
|
2013-03-19 03:59:26 -04:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
long long quot;
|
|
|
|
long long rem;
|
|
|
|
} lldiv_t;
|
2017-07-10 15:38:10 -04:00
|
|
|
#endif
|
2011-08-05 08:25:00 -04:00
|
|
|
|
2013-12-26 19:44:03 -05:00
|
|
|
#ifndef NULL
|
|
|
|
#define __need_NULL
|
|
|
|
#include <stddef.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __size_t_defined
|
|
|
|
#define __size_t_defined
|
|
|
|
#define __need_size_t
|
|
|
|
#include <stddef.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __wchar_t_defined
|
|
|
|
#define __wchar_t_defined
|
|
|
|
#define __need_wchar_t
|
|
|
|
#include <stddef.h>
|
|
|
|
#endif
|
2011-08-05 08:25:00 -04:00
|
|
|
|
2017-07-10 15:38:10 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2013-03-19 04:05:09 -04:00
|
|
|
void abort(void) __attribute__ ((__noreturn__));
|
2012-03-27 10:24:51 -04:00
|
|
|
int abs(int value);
|
2012-05-28 18:05:27 -04:00
|
|
|
int atexit(void (*function)(void));
|
2013-03-19 17:10:27 -04:00
|
|
|
double atof(const char* value);
|
2011-11-09 17:48:26 -05:00
|
|
|
int atoi(const char*);
|
2012-03-05 06:53:58 -05:00
|
|
|
long atol(const char*);
|
2012-09-07 07:00:59 -04:00
|
|
|
void* bsearch(const void*, const void*, size_t, size_t, int (*)(const void*, const void*));
|
2011-12-23 22:05:38 -05:00
|
|
|
void* calloc(size_t, size_t);
|
2013-03-19 12:23:41 -04:00
|
|
|
char* canonicalize_file_name(const char* path);
|
|
|
|
char* canonicalize_file_name_at(int dirfd, const char* path);
|
2014-01-16 19:14:29 -05:00
|
|
|
int clearenv(void);
|
2013-03-19 03:59:26 -04:00
|
|
|
div_t div(int, int);
|
2013-03-19 04:05:09 -04:00
|
|
|
void exit(int) __attribute__ ((__noreturn__));
|
|
|
|
void _Exit(int status) __attribute__ ((__noreturn__));
|
2011-08-05 08:25:00 -04:00
|
|
|
void free(void*);
|
2014-01-16 19:14:29 -05:00
|
|
|
char* getenv(const char*);
|
2012-03-27 10:24:51 -04:00
|
|
|
long labs(long);
|
2013-03-19 03:59:26 -04:00
|
|
|
ldiv_t ldiv(long, long);
|
2011-08-05 08:25:00 -04:00
|
|
|
void* malloc(size_t);
|
2013-04-22 04:16:09 -04:00
|
|
|
int mblen(const char*, size_t);
|
2013-04-07 11:27:11 -04:00
|
|
|
size_t mbstowcs(wchar_t* __restrict, const char* __restrict, size_t);
|
|
|
|
int mbtowc(wchar_t *__restrict, const char* __restrict, size_t);
|
2015-02-06 10:18:36 -05:00
|
|
|
char* mkdtemp(char*);
|
2015-06-02 07:33:32 -04:00
|
|
|
char* mkdtemps(char*, size_t);
|
2015-02-06 10:03:24 -05:00
|
|
|
int mkostemp(char*, int);
|
|
|
|
int mkostemps(char*, int, int);
|
2013-09-18 14:07:30 -04:00
|
|
|
int mkstemp(char*);
|
2015-02-06 10:03:24 -05:00
|
|
|
int mkstemps(char*, int);
|
2012-05-28 18:05:27 -04:00
|
|
|
int on_exit(void (*function)(int, void*), void* arg);
|
2012-03-05 06:37:59 -05:00
|
|
|
void qsort(void*, size_t, size_t, int (*)(const void*, const void*));
|
2014-03-09 11:08:01 -04:00
|
|
|
void qsort_r(void*, size_t, size_t, int (*)(const void*, const void*, void*), void*);
|
2014-12-09 09:23:27 -05:00
|
|
|
#if !defined(__is_sortix_libc) /* not a warning inside libc */
|
|
|
|
__attribute__((__warning__("rand() isn't random, use arc4random()")))
|
|
|
|
#endif
|
2011-11-10 06:27:31 -05:00
|
|
|
int rand(void);
|
2012-02-12 18:31:05 -05:00
|
|
|
void* realloc(void*, size_t);
|
2013-04-07 11:27:11 -04:00
|
|
|
char* realpath(const char* __restrict, char* __restrict);
|
2012-04-03 14:15:34 -04:00
|
|
|
int setenv(const char*, const char*, int);
|
2014-12-09 09:23:27 -05:00
|
|
|
#if !defined(__is_sortix_libc) /* not a warning inside libc */
|
|
|
|
__attribute__((__warning__("srand() isn't random, use arc4random()")))
|
|
|
|
#endif
|
2013-03-19 08:48:59 -04:00
|
|
|
void srand(unsigned);
|
2013-03-23 14:20:44 -04:00
|
|
|
double strtod(const char* __restrict, char** __restrict);
|
|
|
|
float strtof(const char* __restrict, char** __restrict);
|
2013-04-07 11:27:11 -04:00
|
|
|
long strtol(const char* __restrict, char** __restrict, int);
|
2013-03-23 14:20:44 -04:00
|
|
|
long double strtold(const char* __restrict, char** __restrict);
|
2013-04-07 11:27:11 -04:00
|
|
|
unsigned long strtoul(const char* __restrict, char** __restrict, int);
|
2013-01-14 13:27:19 -05:00
|
|
|
int system(const char*);
|
2012-04-03 14:15:34 -04:00
|
|
|
int unsetenv(const char*);
|
2013-04-07 11:27:11 -04:00
|
|
|
size_t wcstombs(char* __restrict, const wchar_t *__restrict, size_t);
|
2012-12-20 08:42:28 -05:00
|
|
|
int wctomb(char*, wchar_t);
|
2012-04-03 14:15:34 -04:00
|
|
|
|
2017-07-10 15:38:10 -04:00
|
|
|
#if 1999 <= __USE_C || defined(__cplusplus)
|
|
|
|
long long atoll(const char*);
|
|
|
|
long long llabs(long long);
|
|
|
|
lldiv_t lldiv(long long, long long);
|
|
|
|
unsigned long long strtoull(const char* __restrict, char** __restrict, int);
|
|
|
|
long long strtoll(const char* __restrict, char** __restrict, int);
|
|
|
|
#endif
|
|
|
|
|
2014-01-18 10:21:46 -05:00
|
|
|
#if defined(__is_sortix_libc)
|
2013-10-21 14:11:34 -04:00
|
|
|
struct exit_handler
|
|
|
|
{
|
|
|
|
void (*hook)(int, void*);
|
|
|
|
void* param;
|
|
|
|
struct exit_handler* next;
|
|
|
|
};
|
|
|
|
extern struct exit_handler* __exit_handler_stack;
|
|
|
|
#endif
|
|
|
|
|
2012-09-28 18:53:50 -04:00
|
|
|
/* TODO: These are not implemented in sortix libc yet. */
|
2013-09-23 10:57:22 -04:00
|
|
|
#if 0
|
2011-08-05 08:25:00 -04:00
|
|
|
long a64l(const char* s);
|
|
|
|
double drand48(void);
|
|
|
|
double erand48(unsigned short [3]);
|
|
|
|
int getsubopt(char**, char* const *, char**);
|
|
|
|
char* initstate(unsigned, char*, size_t);
|
|
|
|
long jrand48(unsigned short [3]);
|
|
|
|
char* l64a(long);
|
|
|
|
void lcong48(unsigned short [7]);
|
|
|
|
long lrand48(void);
|
|
|
|
long mrand48(void);
|
|
|
|
long nrand48(unsigned short[3]);
|
|
|
|
int posix_memalign(void**, size_t, size_t);
|
|
|
|
long random(void);
|
2013-09-22 18:43:42 -04:00
|
|
|
int rand_r(unsigned *);
|
2011-08-05 08:25:00 -04:00
|
|
|
unsigned short *seed48(unsigned short [3]);
|
|
|
|
void setkey(const char*);
|
|
|
|
char* setstate(char*);
|
|
|
|
void srand48(long);
|
|
|
|
void srandom(unsigned);
|
|
|
|
#endif
|
|
|
|
|
2016-11-19 15:04:10 -05:00
|
|
|
#if __USE_SORTIX || __USE_XOPEN
|
|
|
|
int grantpt(int);
|
2016-11-19 15:15:29 -05:00
|
|
|
int unlockpt(int);
|
2016-11-19 15:22:29 -05:00
|
|
|
char* ptsname(int);
|
2016-11-19 15:04:10 -05:00
|
|
|
#endif
|
|
|
|
|
2016-11-19 14:45:53 -05:00
|
|
|
#if __USE_SORTIX || 600 <= __USE_XOPEN
|
|
|
|
int posix_openpt(int);
|
|
|
|
#endif
|
|
|
|
|
2014-07-19 15:08:25 -04:00
|
|
|
/* Functions copied from elsewhere. */
|
|
|
|
#if __USE_SORTIX
|
|
|
|
uint32_t arc4random(void);
|
|
|
|
void arc4random_buf(void*, size_t);
|
|
|
|
uint32_t arc4random_uniform(uint32_t);
|
2014-06-20 12:48:50 -04:00
|
|
|
void* reallocarray(void*, size_t, size_t);
|
2016-11-19 15:38:20 -05:00
|
|
|
int ptsname_r(int, char*, size_t);
|
2014-07-19 15:08:25 -04:00
|
|
|
#endif
|
|
|
|
|
2015-05-13 12:11:02 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} /* extern "C" */
|
|
|
|
#endif
|
2011-08-05 08:25:00 -04:00
|
|
|
|
|
|
|
#endif
|