| 1 | /*
|
|---|
| 2 | * Copyright (c) 2011 Petr Koupy
|
|---|
| 3 | * Copyright (c) 2011 Jiri Zarevucky
|
|---|
| 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 Standard library definitions.
|
|---|
| 34 | */
|
|---|
| 35 |
|
|---|
| 36 | #ifndef POSIX_STDLIB_H_
|
|---|
| 37 | #define POSIX_STDLIB_H_
|
|---|
| 38 |
|
|---|
| 39 | #include "libc/stdlib.h"
|
|---|
| 40 |
|
|---|
| 41 | #ifndef NULL
|
|---|
| 42 | #define NULL ((void *) 0)
|
|---|
| 43 | #endif
|
|---|
| 44 |
|
|---|
| 45 | /* Process Termination */
|
|---|
| 46 | #undef EXIT_FAILURE
|
|---|
| 47 | #define EXIT_FAILURE 1
|
|---|
| 48 | #undef EXIT_SUCCESS
|
|---|
| 49 | #define EXIT_SUCCESS 0
|
|---|
| 50 | #define _Exit exit
|
|---|
| 51 | extern int posix_atexit(void (*func)(void));
|
|---|
| 52 |
|
|---|
| 53 | /* Absolute Value */
|
|---|
| 54 | extern int posix_abs(int i);
|
|---|
| 55 | extern long posix_labs(long i);
|
|---|
| 56 | extern long long posix_llabs(long long i);
|
|---|
| 57 |
|
|---|
| 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 */
|
|---|
| 77 | extern void posix_qsort(void *array, size_t count, size_t size,
|
|---|
| 78 | int (*compare)(const void *, const void *));
|
|---|
| 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 |
|
|---|
| 82 | /* Environment Access */
|
|---|
| 83 | extern char *posix_getenv(const char *name);
|
|---|
| 84 | extern int posix_putenv(char *string);
|
|---|
| 85 | extern int posix_system(const char *string);
|
|---|
| 86 |
|
|---|
| 87 | /* Symbolic Links */
|
|---|
| 88 | extern char *posix_realpath(const char *restrict name, char *restrict resolved);
|
|---|
| 89 |
|
|---|
| 90 | /* Floating Point Conversion */
|
|---|
| 91 | extern double posix_atof(const char *nptr);
|
|---|
| 92 | extern float posix_strtof(const char *restrict nptr, char **restrict endptr);
|
|---|
| 93 | extern double posix_strtod(const char *restrict nptr, char **restrict endptr);
|
|---|
| 94 | extern long double posix_strtold(const char *restrict nptr, char **restrict endptr);
|
|---|
| 95 |
|
|---|
| 96 | /* Integer Conversion */
|
|---|
| 97 | extern int posix_atoi(const char *nptr);
|
|---|
| 98 | extern long int posix_atol(const char *nptr);
|
|---|
| 99 | extern long long int posix_atoll(const char *nptr);
|
|---|
| 100 | extern long int posix_strtol(const char *restrict nptr,
|
|---|
| 101 | char **restrict endptr, int base);
|
|---|
| 102 | extern long long int posix_strtoll(const char *restrict nptr,
|
|---|
| 103 | char **restrict endptr, int base);
|
|---|
| 104 | extern unsigned long int posix_strtoul(const char *restrict nptr,
|
|---|
| 105 | char **restrict endptr, int base);
|
|---|
| 106 | extern unsigned long long int posix_strtoull(
|
|---|
| 107 | const char *restrict nptr, char **restrict endptr, int base);
|
|---|
| 108 |
|
|---|
| 109 | /* Memory Allocation */
|
|---|
| 110 | extern void *posix_malloc(size_t size);
|
|---|
| 111 | extern void *posix_calloc(size_t nelem, size_t elsize);
|
|---|
| 112 | extern void *posix_realloc(void *ptr, size_t size);
|
|---|
| 113 | extern void posix_free(void *ptr);
|
|---|
| 114 |
|
|---|
| 115 | /* Temporary Files */
|
|---|
| 116 | extern int posix_mkstemp(char *tmpl);
|
|---|
| 117 |
|
|---|
| 118 | /* Legacy Declarations */
|
|---|
| 119 | extern char *posix_mktemp(char *tmpl);
|
|---|
| 120 | extern int bsd_getloadavg(double loadavg[], int nelem);
|
|---|
| 121 |
|
|---|
| 122 | #ifndef LIBPOSIX_INTERNAL
|
|---|
| 123 | #define atexit posix_atexit
|
|---|
| 124 |
|
|---|
| 125 | #define abs posix_abs
|
|---|
| 126 | #define labs posix_labs
|
|---|
| 127 | #define llabs posix_llabs
|
|---|
| 128 |
|
|---|
| 129 | #define div_t posix_div_t
|
|---|
| 130 | #define ldiv_t posix_ldiv_t
|
|---|
| 131 | #define lldiv_t posix_lldiv_t
|
|---|
| 132 | #define div posix_div
|
|---|
| 133 | #define ldiv posix_ldiv
|
|---|
| 134 | #define lldiv posix_lldiv
|
|---|
| 135 |
|
|---|
| 136 | #define qsort posix_qsort
|
|---|
| 137 | #define bsearch posix_bsearch
|
|---|
| 138 |
|
|---|
| 139 | #define getenv posix_getenv
|
|---|
| 140 | #define putenv posix_putenv
|
|---|
| 141 | #define system posix_system
|
|---|
| 142 |
|
|---|
| 143 | #define realpath posix_realpath
|
|---|
| 144 |
|
|---|
| 145 | #define atof posix_atof
|
|---|
| 146 | #define strtof posix_strtof
|
|---|
| 147 | #define strtod posix_strtod
|
|---|
| 148 | #define strtold posix_strtold
|
|---|
| 149 |
|
|---|
| 150 | #define atoi posix_atoi
|
|---|
| 151 | #define atol posix_atol
|
|---|
| 152 | #define atoll posix_atoll
|
|---|
| 153 | #define strtol posix_strtol
|
|---|
| 154 | #define strtoll posix_strtoll
|
|---|
| 155 | #define strtoul posix_strtoul
|
|---|
| 156 | #define strtoull posix_strtoull
|
|---|
| 157 |
|
|---|
| 158 | #define malloc posix_malloc
|
|---|
| 159 | #define calloc posix_calloc
|
|---|
| 160 | #define realloc posix_realloc
|
|---|
| 161 | #define free posix_free
|
|---|
| 162 |
|
|---|
| 163 | #define mkstemp posix_mkstemp
|
|---|
| 164 |
|
|---|
| 165 | #define mktemp posix_mktemp
|
|---|
| 166 | #define getloadavg bsd_getloadavg
|
|---|
| 167 | #endif
|
|---|
| 168 |
|
|---|
| 169 | #endif // POSIX_STDLIB_H_
|
|---|
| 170 |
|
|---|
| 171 | /** @}
|
|---|
| 172 | */
|
|---|