Tizen RT Libs&Environment  v1.0 D5
stdlib.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright 2016 Samsung Electronics All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an
13  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14  * either express or implied. See the License for the specific
15  * language governing permissions and limitations under the License.
16  *
17  ****************************************************************************/
18 /****************************************************************************
19  * include/stdlib.h
20  *
21  * Copyright (C) 2007-2014 Gregory Nutt. All rights reserved.
22  * Author: Gregory Nutt <gnutt@nuttx.org>
23  *
24  * Redistribution and use in source and binary forms, with or without
25  * modification, are permitted provided that the following conditions
26  * are met:
27  *
28  * 1. Redistributions of source code must retain the above copyright
29  * notice, this list of conditions and the following disclaimer.
30  * 2. Redistributions in binary form must reproduce the above copyright
31  * notice, this list of conditions and the following disclaimer in
32  * the documentation and/or other materials provided with the
33  * distribution.
34  * 3. Neither the name NuttX nor the names of its contributors may be
35  * used to endorse or promote products derived from this software
36  * without specific prior written permission.
37  *
38  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
39  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
40  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
41  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
42  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
43  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
44  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
45  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
46  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
47  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
48  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49  * POSSIBILITY OF SUCH DAMAGE.
50  *
51  ****************************************************************************/
59 
62 #ifndef __INCLUDE_STDLIB_H
63 #define __INCLUDE_STDLIB_H
64 
65 /****************************************************************************
66  * Included Files
67  ****************************************************************************/
68 
69 #include <tinyara/config.h>
70 #include <tinyara/compiler.h>
71 #include <sys/types.h>
72 #include <stdint.h>
73 
74 /****************************************************************************
75  * Pre-processor Definitions
76  ****************************************************************************/
77 
78 /* The C standard specifies two constants, EXIT_SUCCESS and
79  * EXIT_FAILURE, that may be passed to exit() to indicate
80  * successful or unsucessful termination, respectively.
81  */
82 
83 #define EXIT_SUCCESS 0
84 #define EXIT_FAILURE 1
85 
86 /* The NULL pointer should be defined in this file but is currently defined
87  * in sys/types.h.
88  */
89 
90 /* Maximum value returned by rand() */
91 
92 #define MAX_RAND 32767
93 
94 /* Integer expression whose value is the maximum number of bytes in a
95  * character specified by the current locale.
96  */
97 
98 #define MB_CUR_MAX 1
99 
100 /* The environ variable, normally 'extern char **environ;' is
101  * not implemented as a function call. However, get_environ_ptr()
102  * can be used in its place.
103  */
104 
105 #ifndef CONFIG_DISABLE_ENIVRON
106 #define environ get_environ_ptr()
107 #endif
108 
109 /****************************************************************************
110  * Global Type Definitions
111  ****************************************************************************/
113 struct mallinfo {
114  int arena; /* This is the total size of memory allocated
115  * for use by malloc in bytes. */
116  int ordblks; /* This is the number of free (not in use) chunks */
117  int mxordblk; /* Size of the largest free (not in use) chunk */
118  int uordblks; /* This is the total size of memory occupied by
119  * chunks handed out by malloc. */
120  int fordblks; /* This is the total size of memory occupied
121  * by free (not in use) chunks.*/
122 };
123 
124 /* Structure type returned by the div() function. */
125 
126 struct div_s {
127  int quot; /* Quotient */
128  int rem; /* Remainder */
129 };
130 
131 typedef struct div_s div_t;
132 
133 /* Structure type returned by the ldiv() function. */
134 
135 struct ldiv_s {
136  long quot; /* Quotient */
137  long rem; /* Remainder */
138 };
139 
140 typedef struct ldiv_s ldiv_t;
141 
142 /* Structure type returned by the lldiv() function. */
143 
144 struct lldiv_s {
145  long quot; /* Quotient */
146  long rem; /* Remainder */
147 };
148 
149 typedef struct lldiv_s lldiv_t;
153 /****************************************************************************
154  * Global Function Prototypes
155  ****************************************************************************/
156 
157 /****************************************************************************
158  * Global Function Prototypes
159  ****************************************************************************/
160 
161 #undef EXTERN
162 #if defined(__cplusplus)
163 #define EXTERN extern "C"
164 extern "C" {
165 #else
166 #define EXTERN extern
167 #endif
168 
169 /* Random number generation */
178 void srand(unsigned int seed);
184 int rand(void);
185 
186 /* Environment variable support */
187 
188 #ifndef CONFIG_DISABLE_ENIVRON
189 
196 FAR char *get_environ_ptr(size_t *envsize);
203 FAR char *getenv(FAR const char *name);
210 int putenv(FAR const char *string);
218 int clearenv(void);
225 int setenv(const char *name, const char *value, int overwrite);
232 int unsetenv(const char *name);
233 #endif
234 
235 /* Process exit functions */
242 void exit(int status) noreturn_function;
248 void abort(void) noreturn_function;
249 #ifdef CONFIG_SCHED_ATEXIT
250 
256 int atexit(CODE void (*func)(void));
257 #endif
258 #ifdef CONFIG_SCHED_ONEXIT
259 
270 int on_exit(CODE void (*func)(int, FAR void *), FAR void *arg);
271 #endif
272 
273 /* _Exit() is a stdlib.h equivalent to the unistd.h _exit() function */
278 void _exit(int status); /* See unistd.h */
282 #define _Exit(s) _exit(s)
283 
284 /* String to binary conversions */
290 long strtol(const char *, char **, int);
296 unsigned long strtoul(const char *, char **, int);
297 #ifdef CONFIG_HAVE_LONG_LONG
298 
303 long long strtoll(const char *, char **, int);
309 unsigned long long strtoull(const char *, char **, int);
310 #endif
311 
316 double_t strtod(const char *, char **);
317 
323 #define atoi(nptr) strtol((nptr), NULL, 10)
324 
329 #define atol(nptr) strtol((nptr), NULL, 10)
330 #ifdef CONFIG_HAVE_LONG_LONG
331 
336 #define atoll(nptr) strtoll((nptr), NULL, 10)
337 #endif
338 
343 #define atof(nptr) strtod((nptr), NULL)
344 
345 /* Binary to string conversions */
356 char *itoa(int value, char *str, int base);
357 
358 /* Memory Management */
364 FAR void *malloc(size_t);
370 void free(FAR void *);
376 FAR void *realloc(FAR void *, size_t);
386 FAR void *memalign(size_t, size_t);
395 FAR void *zalloc(size_t);
401 FAR void *calloc(size_t, size_t);
402 
403 /* Misc */
409 int abs(int j);
415 long int labs(long int j);
416 #ifdef CONFIG_HAVE_LONG_LONG
417 
422 long long int llabs(long long int j);
423 #endif
424 
425 #ifdef CONFIG_CAN_PASS_STRUCTS
426 
430 div_t div(int numer, int denom);
434 ldiv_t ldiv(long numer, long denom);
435 #ifdef CONFIG_HAVE_LONG_LONG
436 
439 lldiv_t lldiv(long long numer, long long denom);
440 #endif
441 #endif
442 
450 int mktemp(FAR char *path_template);
454 int mkstemp(FAR char *path_template);
459 /* Sorting */
465 void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
466 
467 /* Binary search */
472 FAR void *bsearch(FAR const void *key, FAR const void *base, size_t nel, size_t width, CODE int (*compar)(FAR const void *, FAR const void *));
477 #ifdef CONFIG_CAN_PASS_STRUCTS
478 
484 struct mallinfo mallinfo(void);
485 #else
486 
493 int mallinfo(struct mallinfo *info);
494 #endif
495 
496 #undef EXTERN
497 #if defined(__cplusplus)
498 }
499 #endif
500 
501 #endif /* __INCLUDE_STDLIB_H */
int arena
Definition: stdlib.h:114
FAR void * calloc(size_t, size_t)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int setenv(const char *name, const char *value, int overwrite)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int mallinfo(struct mallinfo *info)
returns a copy of updated current heap information for the user heap
int on_exit(CODE void(*func)(int, FAR void *), FAR void *arg)
register a function to be called at program exit
int fordblks
Definition: stdlib.h:120
unsigned long long strtoull(const char *, char **, int)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int quot
Definition: stdlib.h:127
int abs(int j)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int rand(void)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int rem
Definition: stdlib.h:128
long quot
Definition: stdlib.h:136
void abort(void) noreturn_function
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
void free(FAR void *)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
FAR char * get_environ_ptr(size_t *envsize)
Return a pointer to the thread specific environ variable.
int uordblks
Definition: stdlib.h:118
int putenv(FAR const char *string)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
void exit(int status) noreturn_function
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
unsigned long strtoul(const char *, char **, int)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
FAR void * memalign(size_t, size_t)
allocates size bytes and returns a pointer to the allocated memory
Definition: stdlib.h:126
void srand(unsigned int seed)
initialize random number generator
long long strtoll(const char *, char **, int)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int atexit(CODE void(*func)(void))
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
long long int llabs(long long int j)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *))
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
FAR void * realloc(FAR void *, size_t)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
FAR void * malloc(size_t)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int unsetenv(const char *name)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
char * itoa(int value, char *str, int base)
convert integer to string
FAR void * zalloc(size_t)
Allocate and zero memory from the user heap.
Definition: stdlib.h:135
long rem
Definition: stdlib.h:146
int clearenv(void)
clears the environment of all name-value pairs and sets the value of the external variable environ to...
long int labs(long int j)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
FAR char * getenv(FAR const char *name)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
structure of memory information
Definition: stdlib.h:113
int mxordblk
Definition: stdlib.h:117
long quot
Definition: stdlib.h:145
long strtol(const char *, char **, int)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int ordblks
Definition: stdlib.h:116
long rem
Definition: stdlib.h:137
double_t strtod(const char *, char **)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)