| 1 |
2 |
drasko |
/*
|
| 2 |
|
|
* Australian Public Licence B (OZPLB)
|
| 3 |
|
|
*
|
| 4 |
|
|
* Version 1-0
|
| 5 |
|
|
*
|
| 6 |
|
|
* Copyright (c) 2004 National ICT Australia
|
| 7 |
|
|
*
|
| 8 |
|
|
* All rights reserved.
|
| 9 |
|
|
*
|
| 10 |
|
|
* Developed by: Embedded, Real-time and Operating Systems Program (ERTOS)
|
| 11 |
|
|
* National ICT Australia
|
| 12 |
|
|
* http://www.ertos.nicta.com.au
|
| 13 |
|
|
*
|
| 14 |
|
|
* Permission is granted by National ICT Australia, free of charge, to
|
| 15 |
|
|
* any person obtaining a copy of this software and any associated
|
| 16 |
|
|
* documentation files (the "Software") to deal with the Software without
|
| 17 |
|
|
* restriction, including (without limitation) the rights to use, copy,
|
| 18 |
|
|
* modify, adapt, merge, publish, distribute, communicate to the public,
|
| 19 |
|
|
* sublicense, and/or sell, lend or rent out copies of the Software, and
|
| 20 |
|
|
* to permit persons to whom the Software is furnished to do so, subject
|
| 21 |
|
|
* to the following conditions:
|
| 22 |
|
|
*
|
| 23 |
|
|
* * Redistributions of source code must retain the above copyright
|
| 24 |
|
|
* notice, this list of conditions and the following disclaimers.
|
| 25 |
|
|
*
|
| 26 |
|
|
* * Redistributions in binary form must reproduce the above
|
| 27 |
|
|
* copyright notice, this list of conditions and the following
|
| 28 |
|
|
* disclaimers in the documentation and/or other materials provided
|
| 29 |
|
|
* with the distribution.
|
| 30 |
|
|
*
|
| 31 |
|
|
* * Neither the name of National ICT Australia, nor the names of its
|
| 32 |
|
|
* contributors, may be used to endorse or promote products derived
|
| 33 |
|
|
* from this Software without specific prior written permission.
|
| 34 |
|
|
*
|
| 35 |
|
|
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
|
| 36 |
|
|
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
|
| 37 |
|
|
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
|
| 38 |
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
| 39 |
|
|
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
|
| 40 |
|
|
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
|
| 41 |
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
|
| 42 |
|
|
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
|
| 43 |
|
|
* ERRORS, WHETHER OR NOT DISCOVERABLE.
|
| 44 |
|
|
*
|
| 45 |
|
|
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
|
| 46 |
|
|
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
|
| 47 |
|
|
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
|
| 48 |
|
|
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
|
| 49 |
|
|
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
|
| 50 |
|
|
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
|
| 51 |
|
|
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
|
| 52 |
|
|
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
|
| 53 |
|
|
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
|
| 54 |
|
|
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
|
| 55 |
|
|
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
|
| 56 |
|
|
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
|
| 57 |
|
|
* DAMAGES OR OTHER LIABILITY.
|
| 58 |
|
|
*
|
| 59 |
|
|
* If applicable legislation implies representations, warranties, or
|
| 60 |
|
|
* conditions, or imposes obligations or liability on National ICT
|
| 61 |
|
|
* Australia or one of its contributors in respect of the Software that
|
| 62 |
|
|
* cannot be wholly or partly excluded, restricted or modified, the
|
| 63 |
|
|
* liability of National ICT Australia or the contributor is limited, to
|
| 64 |
|
|
* the full extent permitted by the applicable legislation, at its
|
| 65 |
|
|
* option, to:
|
| 66 |
|
|
* a. in the case of goods, any one or more of the following:
|
| 67 |
|
|
* i. the replacement of the goods or the supply of equivalent goods;
|
| 68 |
|
|
* ii. the repair of the goods;
|
| 69 |
|
|
* iii. the payment of the cost of replacing the goods or of acquiring
|
| 70 |
|
|
* equivalent goods;
|
| 71 |
|
|
* iv. the payment of the cost of having the goods repaired; or
|
| 72 |
|
|
* b. in the case of services:
|
| 73 |
|
|
* i. the supplying of the services again; or
|
| 74 |
|
|
* ii. the payment of the cost of having the services supplied again.
|
| 75 |
|
|
*
|
| 76 |
|
|
* The construction, validity and performance of this licence is governed
|
| 77 |
|
|
* by the laws in force in New South Wales, Australia.
|
| 78 |
|
|
*/
|
| 79 |
|
|
|
| 80 |
|
|
#ifndef _STDLIB_H_
|
| 81 |
|
|
#define _STDLIB_H_
|
| 82 |
|
|
|
| 83 |
|
|
#include <stdint.h>
|
| 84 |
|
|
#include <stddef.h>
|
| 85 |
|
|
|
| 86 |
|
|
/* ISOC99 7.20 General Utilities */
|
| 87 |
|
|
|
| 88 |
|
|
/* 7.20.2 div types */
|
| 89 |
|
|
typedef struct {
|
| 90 |
|
|
int quot, rem;
|
| 91 |
|
|
} div_t;
|
| 92 |
|
|
|
| 93 |
|
|
typedef struct {
|
| 94 |
|
|
long quot, rem;
|
| 95 |
|
|
} ldiv_t;
|
| 96 |
|
|
|
| 97 |
|
|
typedef struct {
|
| 98 |
|
|
long long quot, rem;
|
| 99 |
|
|
} lldiv_t;
|
| 100 |
|
|
|
| 101 |
|
|
|
| 102 |
|
|
/* 7.20.3 EXIT_ macros */
|
| 103 |
|
|
#define EXIT_FAILURE 1
|
| 104 |
|
|
#define EXIT_SUCCESS 0
|
| 105 |
|
|
|
| 106 |
|
|
#define RAND_MAX INT_MAX
|
| 107 |
|
|
#define MB_CUR_MAX 1
|
| 108 |
|
|
|
| 109 |
|
|
/* 7.20.1 Numeric conversion functions */
|
| 110 |
|
|
|
| 111 |
|
|
/* 7.20.1-3 The strtod, strtof and strtold functions */
|
| 112 |
|
|
double strtod(const char *s, char **endp);
|
| 113 |
|
|
float strtof(const char *s, char **endp);
|
| 114 |
|
|
long double strtold(const char *s, char **endp);
|
| 115 |
|
|
|
| 116 |
|
|
/* 7.20.1-4 The strtol, stroll, stroul, strtoull functions */
|
| 117 |
|
|
long strtol(const char *s, char **endp, int base);
|
| 118 |
|
|
long long strtoll(const char *s, char **endp, int base);
|
| 119 |
|
|
unsigned long strtoul(const char *s, char **endp, int base);
|
| 120 |
|
|
unsigned long long strtoull(const char *s, char **endp, int base);
|
| 121 |
|
|
|
| 122 |
|
|
/* 7.20.1-1 atof function */
|
| 123 |
|
|
static inline double atof(const char *nptr)
|
| 124 |
|
|
{
|
| 125 |
|
|
return strtod(nptr, (char **)NULL);
|
| 126 |
|
|
}
|
| 127 |
|
|
|
| 128 |
|
|
/* 7.20.1-2 The atoi, atol and atoll functions */
|
| 129 |
|
|
static inline int atoi(const char *nptr)
|
| 130 |
|
|
{
|
| 131 |
|
|
return (int) strtol(nptr, (char **)NULL, 10);
|
| 132 |
|
|
}
|
| 133 |
|
|
|
| 134 |
|
|
static inline long atol(const char *nptr)
|
| 135 |
|
|
{
|
| 136 |
|
|
return strtol(nptr, (char **)NULL, 10);
|
| 137 |
|
|
}
|
| 138 |
|
|
|
| 139 |
|
|
static inline long long atoll(const char *nptr)
|
| 140 |
|
|
{
|
| 141 |
|
|
return strtoll(nptr, (char **)NULL, 10);
|
| 142 |
|
|
}
|
| 143 |
|
|
|
| 144 |
|
|
/* 7.20.2 Pseudo-random sequence generation functions */
|
| 145 |
|
|
|
| 146 |
|
|
int rand(void);
|
| 147 |
|
|
void srand(unsigned int seed);
|
| 148 |
|
|
|
| 149 |
|
|
/* 7.20.3 Memory management functions */
|
| 150 |
|
|
|
| 151 |
|
|
void *malloc(size_t);
|
| 152 |
|
|
void free(void *);
|
| 153 |
|
|
void *calloc(size_t, size_t);
|
| 154 |
|
|
void *realloc(void *, size_t);
|
| 155 |
|
|
|
| 156 |
|
|
/* 7.20.4 Communcation with the environment */
|
| 157 |
|
|
|
| 158 |
|
|
void abort(void);
|
| 159 |
|
|
int atexit(void (*func)(void));
|
| 160 |
|
|
void exit(int status);
|
| 161 |
|
|
void _Exit(int status);
|
| 162 |
|
|
char *getenv(const char *name);
|
| 163 |
|
|
int system(const char *string);
|
| 164 |
|
|
|
| 165 |
|
|
/* 7.20.5 Searching and sortin utilities */
|
| 166 |
|
|
void *bsearch(const void *key, const void *base, size_t nmemb, size_t, int (*compar)(const void *, const void*));
|
| 167 |
|
|
void qsort(void *base, size_t nmemb, size_t, int (*compar)(const void *, const void*));
|
| 168 |
|
|
|
| 169 |
|
|
/* 7.20.6 Integer arithmetic function */
|
| 170 |
|
|
|
| 171 |
|
|
/* FIXME: (benjl) Gcc defines these, but if we aren't using gcc it probably
|
| 172 |
|
|
won't, but how do we know? Or maybe we should compile with -fnobuiltin? */
|
| 173 |
|
|
|
| 174 |
|
|
int abs(int);
|
| 175 |
|
|
long labs(long);
|
| 176 |
|
|
long long llabs(long long);
|
| 177 |
|
|
|
| 178 |
|
|
#if 0
|
| 179 |
|
|
static inline int
|
| 180 |
|
|
abs(int x)
|
| 181 |
|
|
{
|
| 182 |
|
|
return x < 0 ? -x : x;
|
| 183 |
|
|
}
|
| 184 |
|
|
|
| 185 |
|
|
static inline long
|
| 186 |
|
|
labs(long x)
|
| 187 |
|
|
{
|
| 188 |
|
|
return x < 0 ? -x : x;
|
| 189 |
|
|
}
|
| 190 |
|
|
|
| 191 |
|
|
static inline long long
|
| 192 |
|
|
llabs(long long x)
|
| 193 |
|
|
{
|
| 194 |
|
|
return x < 0 ? -x : x;
|
| 195 |
|
|
}
|
| 196 |
|
|
#endif
|
| 197 |
|
|
/* 7.20.7 Multibyte/wide character conversion functions */
|
| 198 |
|
|
#if 0 /* We don't have wide characters */
|
| 199 |
|
|
int mblen(const char *s, size_t n);
|
| 200 |
|
|
int mbtowc(wchar_t pwc, const char *s, size_t n);
|
| 201 |
|
|
int wctomb(char *s, wchat_t wc);
|
| 202 |
|
|
#endif
|
| 203 |
|
|
|
| 204 |
|
|
/* 7.20.8 Multibyte/wide string conversion functions */
|
| 205 |
|
|
#if 0 /* We don't have wide characters */
|
| 206 |
|
|
size_t mbstowcs(wchar_t *pwcs, const char *s, size_t n);
|
| 207 |
|
|
size_t wcstombs(char *s, constwchat_t *pwcs, size_t n);
|
| 208 |
|
|
#endif
|
| 209 |
|
|
|
| 210 |
|
|
#endif /* _STDLIB_H_ */
|