[2fc5072] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Petr Koupy
|
---|
[ceebf0a] | 3 | * Copyright (c) 2011 Jiri Zarevucky
|
---|
[2fc5072] | 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | /** @addtogroup libposix
|
---|
| 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /** @file
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | #ifndef POSIX_STDLIB_H_
|
---|
| 37 | #define POSIX_STDLIB_H_
|
---|
| 38 |
|
---|
[acc3f82c] | 39 | #include "libc/stdlib.h"
|
---|
[2fc5072] | 40 |
|
---|
| 41 | #ifndef NULL
|
---|
| 42 | #define NULL ((void *) 0)
|
---|
| 43 | #endif
|
---|
| 44 |
|
---|
[4f4b4e7] | 45 | /* Process Termination */
|
---|
[2fc5072] | 46 | #undef EXIT_FAILURE
|
---|
| 47 | #define EXIT_FAILURE 1
|
---|
| 48 | #undef EXIT_SUCCESS
|
---|
| 49 | #define EXIT_SUCCESS 0
|
---|
[1eee1283] | 50 | #define _Exit exit
|
---|
[823a929] | 51 | extern int posix_atexit(void (*func)(void));
|
---|
| 52 |
|
---|
| 53 | /* Absolute Value */
|
---|
| 54 | extern int posix_abs(int i);
|
---|
[2b83add] | 55 | extern long posix_labs(long i);
|
---|
| 56 | extern long long posix_llabs(long long i);
|
---|
[1eee1283] | 57 |
|
---|
[cc3652db] | 58 | /* Integer division */
|
---|
| 59 |
|
---|
| 60 | typedef struct {
|
---|
| 61 | int quot, rem;
|
---|
| 62 | } posix_div_t;
|
---|
| 63 |
|
---|
| 64 | typedef struct {
|
---|
| 65 | long quot, rem;
|
---|
| 66 | } posix_ldiv_t;
|
---|
| 67 |
|
---|
| 68 | typedef struct {
|
---|
| 69 | long long quot, rem;
|
---|
| 70 | } posix_lldiv_t;
|
---|
| 71 |
|
---|
| 72 | extern posix_div_t posix_div(int numer, int denom);
|
---|
| 73 | extern posix_ldiv_t posix_ldiv(long numer, long denom);
|
---|
| 74 | extern posix_lldiv_t posix_lldiv(long long numer, long long denom);
|
---|
| 75 |
|
---|
| 76 | /* Array Functions */
|
---|
[4f4b4e7] | 77 | extern void posix_qsort(void *array, size_t count, size_t size,
|
---|
| 78 | int (*compare)(const void *, const void *));
|
---|
[cc3652db] | 79 | extern void *posix_bsearch(const void *key, const void *base,
|
---|
| 80 | size_t nmemb, size_t size, int (*compar)(const void *, const void *));
|
---|
| 81 |
|
---|
[2fc5072] | 82 |
|
---|
| 83 | /* Environment Access */
|
---|
| 84 | extern char *posix_getenv(const char *name);
|
---|
[823a929] | 85 | extern int posix_putenv(char *string);
|
---|
[2fc5072] | 86 |
|
---|
[cc3652db] | 87 | extern int posix_system(const char *string);
|
---|
| 88 |
|
---|
| 89 |
|
---|
[2fc5072] | 90 | /* Symbolic Links */
|
---|
| 91 | extern char *posix_realpath(const char *restrict name, char *restrict resolved);
|
---|
| 92 |
|
---|
[4f4b4e7] | 93 | /* Floating Point Conversion */
|
---|
[2b83add] | 94 | extern double posix_atof(const char *nptr);
|
---|
[ceebf0a] | 95 | extern float posix_strtof(const char *restrict nptr, char **restrict endptr);
|
---|
| 96 | extern double posix_strtod(const char *restrict nptr, char **restrict endptr);
|
---|
| 97 | extern long double posix_strtold(const char *restrict nptr, char **restrict endptr);
|
---|
| 98 |
|
---|
[4f4b4e7] | 99 | /* Integer Conversion */
|
---|
[2b83add] | 100 | extern int posix_atoi(const char *nptr);
|
---|
| 101 | extern long int posix_atol(const char *nptr);
|
---|
| 102 | extern long long int posix_atoll(const char *nptr);
|
---|
| 103 |
|
---|
| 104 | extern long int posix_strtol(const char *restrict nptr,
|
---|
| 105 | char **restrict endptr, int base);
|
---|
| 106 | extern long long int posix_strtoll(const char *restrict nptr,
|
---|
| 107 | char **restrict endptr, int base);
|
---|
| 108 | extern unsigned long int posix_strtoul(const char *restrict nptr,
|
---|
| 109 | char **restrict endptr, int base);
|
---|
| 110 | extern unsigned long long int posix_strtoull(
|
---|
| 111 | const char *restrict nptr, char **restrict endptr, int base);
|
---|
| 112 |
|
---|
[09b0b1fb] | 113 |
|
---|
[823a929] | 114 | /* Memory Allocation */
|
---|
| 115 | extern void *posix_malloc(size_t size);
|
---|
| 116 | extern void *posix_calloc(size_t nelem, size_t elsize);
|
---|
| 117 | extern void *posix_realloc(void *ptr, size_t size);
|
---|
| 118 | extern void posix_free(void *ptr);
|
---|
| 119 |
|
---|
| 120 | /* Legacy Declarations */
|
---|
| 121 | extern char *posix_mktemp(char *tmpl);
|
---|
[3acff69] | 122 | extern int bsd_getloadavg(double loadavg[], int nelem);
|
---|
[823a929] | 123 |
|
---|
[4d10fc8] | 124 | #ifndef LIBPOSIX_INTERNAL
|
---|
[823a929] | 125 | #define atexit posix_atexit
|
---|
| 126 |
|
---|
| 127 | #define abs posix_abs
|
---|
[2b83add] | 128 | #define labs posix_labs
|
---|
| 129 | #define llabs posix_llabs
|
---|
[823a929] | 130 |
|
---|
[cc3652db] | 131 | #define div_t posix_div_t
|
---|
| 132 | #define ldiv_t posix_ldiv_t
|
---|
| 133 | #define lldiv_t posix_lldiv_t
|
---|
| 134 | #define div posix_div
|
---|
| 135 | #define ldiv posix_ldiv
|
---|
| 136 | #define lldiv posix_lldiv
|
---|
| 137 |
|
---|
[4d10fc8] | 138 | #define qsort posix_qsort
|
---|
[cc3652db] | 139 | #define bsearch posix_bsearch
|
---|
[823a929] | 140 |
|
---|
[4d10fc8] | 141 | #define getenv posix_getenv
|
---|
[2b83add] | 142 | #define putenv posix_putenv
|
---|
[cc3652db] | 143 | #define system posix_system
|
---|
[823a929] | 144 |
|
---|
[4d10fc8] | 145 | #define realpath posix_realpath
|
---|
[ceebf0a] | 146 |
|
---|
[2b83add] | 147 | #define atof posix_atof
|
---|
[ceebf0a] | 148 | #define strtof posix_strtof
|
---|
| 149 | #define strtod posix_strtod
|
---|
| 150 | #define strtold posix_strtold
|
---|
[09b0b1fb] | 151 |
|
---|
| 152 | #define atoi posix_atoi
|
---|
[2b83add] | 153 | #define atol posix_atol
|
---|
| 154 | #define atoll posix_atoll
|
---|
| 155 | #define strtol posix_strtol
|
---|
| 156 | #define strtoll posix_strtoll
|
---|
| 157 | #define strtoul posix_strtoul
|
---|
| 158 | #define strtoull posix_strtoull
|
---|
[823a929] | 159 |
|
---|
| 160 | #define malloc posix_malloc
|
---|
| 161 | #define calloc posix_calloc
|
---|
| 162 | #define realloc posix_realloc
|
---|
| 163 | #define free posix_free
|
---|
| 164 |
|
---|
| 165 | #define mktemp posix_mktemp
|
---|
[3acff69] | 166 | #define getloadavg bsd_getloadavg
|
---|
[4d10fc8] | 167 | #endif
|
---|
| 168 |
|
---|
[2fc5072] | 169 | #endif // POSIX_STDLIB_H_
|
---|
| 170 |
|
---|
| 171 | /** @}
|
---|
| 172 | */
|
---|