Tizen RT Libs&Environment  v1.1 D4
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 RAND_MAX 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_ENVIRON
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;
154 /****************************************************************************
155  * Global Function Prototypes
156  ****************************************************************************/
157 
158 /****************************************************************************
159  * Global Function Prototypes
160  ****************************************************************************/
161 
162 #undef EXTERN
163 #if defined(__cplusplus)
164 #define EXTERN extern "C"
165 extern "C" {
166 #else
167 #define EXTERN extern
168 #endif
169 
170 /* Random number generation */
180 void srand(unsigned int seed);
188 int rand(void);
189 
190 /* Environment variable support */
191 
192 #ifndef CONFIG_DISABLE_ENVIRON
193 
203 FAR char *get_environ_ptr(size_t *envsize);
212 FAR char *getenv(FAR const char *name);
221 int putenv(FAR const char *string);
230 int clearenv(void);
239 int setenv(const char *name, const char *value, int overwrite);
248 int unsetenv(const char *name);
249 #endif
250 
251 /* Process exit functions */
260 void exit(int status) noreturn_function;
268 void abort(void) noreturn_function;
269 #ifdef CONFIG_SCHED_ATEXIT
270 
278 int atexit(CODE void (*func)(void));
279 #endif
280 #ifdef CONFIG_SCHED_ONEXIT
281 
293 int on_exit(CODE void (*func)(int, FAR void *), FAR void *arg);
294 #endif
295 
296 /* _Exit() is a stdlib.h equivalent to the unistd.h _exit() function */
301 void _exit(int status); /* See unistd.h */
305 #define _Exit(s) _exit(s)
306 
307 /* String to binary conversions */
315 long strtol(const char *, char **, int);
323 unsigned long strtoul(const char *, char **, int);
324 #ifdef CONFIG_HAVE_LONG_LONG
325 
332 long long strtoll(const char *, char **, int);
340 unsigned long long strtoull(const char *, char **, int);
341 #endif
342 
349 double_t strtod(const char *, char **);
350 
358 #define atoi(nptr) strtol((nptr), NULL, 10)
359 
366 #define atol(nptr) strtol((nptr), NULL, 10)
367 #ifdef CONFIG_HAVE_LONG_LONG
368 
375 #define atoll(nptr) strtoll((nptr), NULL, 10)
376 #endif
377 
384 #define atof(nptr) strtod((nptr), NULL)
385 
386 /* Binary to string conversions */
398 char *itoa(int value, char *str, int base);
399 
400 /* Memory Management */
408 FAR void *malloc(size_t);
416 void free(FAR void *);
424 FAR void *realloc(FAR void *, size_t);
435 FAR void *memalign(size_t, size_t);
445 FAR void *zalloc(size_t);
453 FAR void *calloc(size_t, size_t);
454 
455 /* Misc */
463 int abs(int j);
471 long int labs(long int j);
472 #ifdef CONFIG_HAVE_LONG_LONG
473 
480 long long int llabs(long long int j);
481 #endif
482 
483 #ifdef CONFIG_CAN_PASS_STRUCTS
484 
491 div_t div(int numer, int denom);
496 ldiv_t ldiv(long numer, long denom);
497 #ifdef CONFIG_HAVE_LONG_LONG
498 
501 lldiv_t lldiv(long long numer, long long denom);
502 #endif
503 #endif
504 
512 int mktemp(FAR char *path_template);
516 int mkstemp(FAR char *path_template);
521 /* Sorting */
529 void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
530 
531 /* Binary search */
539 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 *));
540 
541 #ifdef CONFIG_CAN_PASS_STRUCTS
542 
549 struct mallinfo mallinfo(void);
550 #else
551 
559 int mallinfo(struct mallinfo *info);
560 #endif
561 
562 #undef EXTERN
563 #if defined(__cplusplus)
564 }
565 #endif
566 
567 #endif /* __INCLUDE_STDLIB_H */
int arena
Definition: stdlib.h:114
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 *))
binary search a sorted table
FAR void * calloc(size_t, size_t)
a memory allocator
int setenv(const char *name, const char *value, int overwrite)
add or change environment variable
struct mallinfo mallinfo(void)
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)
convert a string to an unsigned long
int quot
Definition: stdlib.h:127
int abs(int j)
return an integer absolute value
int rand(void)
pseudo-random number generator
int rem
Definition: stdlib.h:128
long quot
Definition: stdlib.h:136
void abort(void) noreturn_function
generate an abnormal process abort
void free(FAR void *)
free allocated memory
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)
change or add a value to an environment
void exit(int status) noreturn_function
terminate a process
unsigned long strtoul(const char *, char **, int)
convert a string to an unsigned long
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)
convert a string to a long integer
int atexit(CODE void(*func)(void))
register a function to run at process termination
long long int llabs(long long int j)
return a long integer absolute value
void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *))
sort a table of data
FAR void * realloc(FAR void *, size_t)
memory reallocator
FAR void * malloc(size_t)
a memory allocator
int unsetenv(const char *name)
remove an environment variable
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
div_t div(int numer, int denom)
compute the quotient and remainder of an integer division
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)
return a long integer absolute value
FAR char * getenv(FAR const char *name)
get value of an environment variable
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)
convert a string to a long integer
int ordblks
Definition: stdlib.h:116
long rem
Definition: stdlib.h:137
double_t strtod(const char *, char **)
convert a string to a double-precision number