2008-11-16 17:36:30 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* include/stdlib.h
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2020-04-11 19:17:55 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2020-04-11 19:17:55 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2020-04-11 19:17:55 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2008-11-16 17:36:30 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-11-16 17:36:30 +01:00
|
|
|
#ifndef __INCLUDE_STDLIB_H
|
|
|
|
#define __INCLUDE_STDLIB_H
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-11-16 17:36:30 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2008-11-16 17:36:30 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-06-30 19:05:44 +02:00
|
|
|
#include <nuttx/config.h>
|
2010-10-09 23:12:49 +02:00
|
|
|
#include <nuttx/compiler.h>
|
2016-10-19 03:11:09 +02:00
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <sys/types.h>
|
2010-10-09 23:12:49 +02:00
|
|
|
#include <stdint.h>
|
2018-07-19 19:21:49 +02:00
|
|
|
#include <limits.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-11-16 17:36:30 +01:00
|
|
|
/****************************************************************************
|
2014-09-28 18:15:33 +02:00
|
|
|
* Pre-processor Definitions
|
2008-11-16 17:36:30 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2015-08-03 19:01:41 +02:00
|
|
|
/* The C standard specifies two constants, EXIT_SUCCESS and EXIT_FAILURE,
|
|
|
|
* that may be passed to exit() to indicate successful or unsuccessful
|
|
|
|
* termination, respectively.
|
2007-02-18 00:21:28 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define EXIT_SUCCESS 0
|
|
|
|
#define EXIT_FAILURE 1
|
|
|
|
|
2011-10-30 18:28:54 +01:00
|
|
|
/* The NULL pointer should be defined in this file but is currently defined
|
|
|
|
* in sys/types.h.
|
|
|
|
*/
|
|
|
|
|
2018-07-19 19:21:49 +02:00
|
|
|
/* Maximum value returned by rand(). Must be a minimum of 32767. */
|
2011-10-30 18:28:54 +01:00
|
|
|
|
2018-07-19 19:21:49 +02:00
|
|
|
#define RAND_MAX INT_MAX
|
2011-10-30 18:28:54 +01:00
|
|
|
|
|
|
|
/* Integer expression whose value is the maximum number of bytes in a
|
2014-04-13 22:32:20 +02:00
|
|
|
* character specified by the current locale.
|
2011-10-30 18:28:54 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define MB_CUR_MAX 1
|
|
|
|
|
2015-08-03 19:01:41 +02:00
|
|
|
/* The environ variable, normally 'char **environ;' is not implemented as a
|
|
|
|
* function call. However, get_environ_ptr() can be used in its place.
|
2007-06-30 19:05:44 +02:00
|
|
|
*/
|
|
|
|
|
2022-04-21 09:25:49 +02:00
|
|
|
#ifdef CONFIG_DISABLE_ENVIRON
|
|
|
|
# define environ NULL
|
|
|
|
#else
|
|
|
|
# define environ get_environ_ptr()
|
|
|
|
#endif
|
2007-06-30 19:05:44 +02:00
|
|
|
|
2021-07-21 05:46:21 +02:00
|
|
|
#if defined(CONFIG_FS_LARGEFILE) && defined(CONFIG_HAVE_LONG_LONG)
|
|
|
|
# define mkstemp64 mkstemp
|
|
|
|
# define mkostemp64 mkostemp
|
|
|
|
# define mkstemps64 mkstemps
|
|
|
|
# define mkostemps64 mkostemps
|
|
|
|
#endif
|
|
|
|
|
2021-07-28 16:44:44 +02:00
|
|
|
#define strtof_l(s, e, l) strtof(s, e)
|
|
|
|
#define strtod_l(s, e, l) strtod(s, e)
|
|
|
|
#define strtold_l(s, e, l) strtold(s, e)
|
|
|
|
#define strtoll_l(s, e, b, l) strtoll(s, e, b)
|
|
|
|
#define strtoull_l(s, e, b, l) strtoull(s, e, b)
|
|
|
|
|
2008-11-16 17:36:30 +01:00
|
|
|
/****************************************************************************
|
2015-08-03 19:01:41 +02:00
|
|
|
* Public Type Definitions
|
2008-11-16 17:36:30 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2015-08-14 16:35:01 +02:00
|
|
|
/* Structure type returned by the div() function. */
|
|
|
|
|
|
|
|
struct div_s
|
|
|
|
{
|
|
|
|
int quot; /* Quotient */
|
|
|
|
int rem; /* Remainder */
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct div_s div_t;
|
|
|
|
|
2015-08-14 16:45:59 +02:00
|
|
|
/* Structure type returned by the ldiv() function. */
|
|
|
|
|
|
|
|
struct ldiv_s
|
|
|
|
{
|
|
|
|
long quot; /* Quotient */
|
|
|
|
long rem; /* Remainder */
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct ldiv_s ldiv_t;
|
|
|
|
|
|
|
|
/* Structure type returned by the lldiv() function. */
|
|
|
|
|
|
|
|
struct lldiv_s
|
|
|
|
{
|
|
|
|
long quot; /* Quotient */
|
|
|
|
long rem; /* Remainder */
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct lldiv_s lldiv_t;
|
|
|
|
|
2008-11-16 17:36:30 +01:00
|
|
|
/****************************************************************************
|
2015-08-03 19:01:41 +02:00
|
|
|
* Public Function Prototypes
|
2008-11-16 17:36:30 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
#define EXTERN extern "C"
|
2013-03-08 21:36:18 +01:00
|
|
|
extern "C"
|
|
|
|
{
|
2007-02-18 00:21:28 +01:00
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Random number generation */
|
2007-02-27 22:17:21 +01:00
|
|
|
|
2013-03-08 21:36:18 +01:00
|
|
|
void srand(unsigned int seed);
|
|
|
|
int rand(void);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2018-07-19 19:21:49 +02:00
|
|
|
#define srandom(s) srand(s)
|
|
|
|
long random(void);
|
|
|
|
|
2020-12-12 07:16:07 +01:00
|
|
|
#ifdef CONFIG_CRYPTO_RANDOM_POOL
|
|
|
|
void arc4random_buf(FAR void *bytes, size_t nbytes);
|
|
|
|
#endif
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Environment variable support */
|
2007-02-27 22:17:21 +01:00
|
|
|
|
2015-11-18 20:22:43 +01:00
|
|
|
FAR char **get_environ_ptr(void);
|
2013-03-08 21:36:18 +01:00
|
|
|
FAR char *getenv(FAR const char *name);
|
|
|
|
int putenv(FAR const char *string);
|
|
|
|
int clearenv(void);
|
2015-11-18 20:22:43 +01:00
|
|
|
int setenv(FAR const char *name, FAR const char *value, int overwrite);
|
|
|
|
int unsetenv(FAR const char *name);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* Process exit functions */
|
2007-02-27 22:17:21 +01:00
|
|
|
|
2013-03-08 21:36:18 +01:00
|
|
|
void exit(int status) noreturn_function;
|
|
|
|
void abort(void) noreturn_function;
|
|
|
|
int atexit(CODE void (*func)(void));
|
|
|
|
int on_exit(CODE void (*func)(int, FAR void *), FAR void *arg);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-04-19 00:13:38 +02:00
|
|
|
/* _Exit() is a stdlib.h equivalent to the unistd.h _exit() function */
|
|
|
|
|
2020-06-26 08:40:13 +02:00
|
|
|
void _Exit(int status) noreturn_function;
|
2013-04-19 00:13:38 +02:00
|
|
|
|
2016-08-25 19:28:09 +02:00
|
|
|
/* System() command is not implemented in the NuttX libc because it is so
|
|
|
|
* entangled with shell logic. There is an experimental version at
|
|
|
|
* apps/system/system. system() is prototyped here, however, for
|
2016-08-25 20:36:19 +02:00
|
|
|
* standards compatibility.
|
2016-08-25 19:28:09 +02:00
|
|
|
*/
|
|
|
|
|
2016-08-25 20:36:19 +02:00
|
|
|
#ifndef __KERNEL__
|
2018-08-23 14:40:59 +02:00
|
|
|
int system(FAR const char *cmd);
|
2016-08-25 20:36:19 +02:00
|
|
|
#endif
|
2016-08-25 19:28:09 +02:00
|
|
|
|
2020-06-22 14:43:21 +02:00
|
|
|
FAR char *realpath(FAR const char *path, FAR char *resolved);
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* String to binary conversions */
|
2007-02-27 22:17:21 +01:00
|
|
|
|
2015-11-18 20:22:43 +01:00
|
|
|
long strtol(FAR const char *nptr, FAR char **endptr, int base);
|
|
|
|
unsigned long strtoul(FAR const char *nptr, FAR char **endptr, int base);
|
2009-06-14 17:36:18 +02:00
|
|
|
#ifdef CONFIG_HAVE_LONG_LONG
|
2015-11-18 20:22:43 +01:00
|
|
|
long long strtoll(FAR const char *nptr, FAR char **endptr, int base);
|
|
|
|
unsigned long long strtoull(FAR const char *nptr, FAR char **endptr,
|
|
|
|
int base);
|
2009-06-14 17:36:18 +02:00
|
|
|
#endif
|
2016-10-20 20:07:12 +02:00
|
|
|
float strtof(FAR const char *str, FAR char **endptr);
|
2016-10-22 21:02:55 +02:00
|
|
|
#ifdef CONFIG_HAVE_DOUBLE
|
|
|
|
double strtod(FAR const char *str, FAR char **endptr);
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
|
|
|
long double strtold(FAR const char *str, FAR char **endptr);
|
|
|
|
#endif
|
2009-06-14 17:36:18 +02:00
|
|
|
|
2020-08-29 05:03:19 +02:00
|
|
|
int atoi(FAR const char *nptr);
|
|
|
|
long atol(FAR const char *nptr);
|
2009-06-14 17:36:18 +02:00
|
|
|
#ifdef CONFIG_HAVE_LONG_LONG
|
2020-06-26 08:40:13 +02:00
|
|
|
long long atoll(FAR const char *nptr);
|
2020-06-01 08:19:26 +02:00
|
|
|
#endif
|
2017-02-10 16:32:55 +01:00
|
|
|
#ifdef CONFIG_HAVE_DOUBLE
|
2020-08-29 05:03:19 +02:00
|
|
|
double atof(FAR const char *nptr);
|
2017-02-10 16:32:55 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-03-14 19:30:06 +01:00
|
|
|
/* Binary to string conversions */
|
|
|
|
|
2015-11-18 20:22:43 +01:00
|
|
|
FAR char *itoa(int val, FAR char *str, int base);
|
2013-03-14 19:30:06 +01:00
|
|
|
|
2016-10-19 03:11:09 +02:00
|
|
|
/* Wide character operations */
|
|
|
|
|
|
|
|
#ifdef CONFIG_LIBC_WCHAR
|
2020-06-02 07:54:30 +02:00
|
|
|
int mblen(FAR const char *s, size_t n);
|
2016-10-19 03:11:09 +02:00
|
|
|
int mbtowc(FAR wchar_t *pwc, FAR const char *s, size_t n);
|
2020-06-02 07:54:30 +02:00
|
|
|
size_t mbstowcs(FAR wchar_t *dst, FAR const char *src, size_t len);
|
2016-10-19 03:11:09 +02:00
|
|
|
int wctomb(FAR char *s, wchar_t wchar);
|
2020-06-02 07:54:30 +02:00
|
|
|
size_t wcstombs(FAR char *dst, FAR const wchar_t *src, size_t len);
|
2016-10-19 03:11:09 +02:00
|
|
|
#endif
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Memory Management */
|
2007-02-27 22:17:21 +01:00
|
|
|
|
2013-03-08 21:36:18 +01:00
|
|
|
FAR void *malloc(size_t);
|
2021-02-07 07:31:54 +01:00
|
|
|
FAR void *valloc(size_t);
|
2015-11-18 20:22:43 +01:00
|
|
|
void free(FAR void *);
|
|
|
|
FAR void *realloc(FAR void *, size_t);
|
2013-03-08 21:36:18 +01:00
|
|
|
FAR void *memalign(size_t, size_t);
|
|
|
|
FAR void *zalloc(size_t);
|
|
|
|
FAR void *calloc(size_t, size_t);
|
2020-06-26 08:40:13 +02:00
|
|
|
FAR void *aligned_alloc(size_t, size_t);
|
2020-08-29 05:03:19 +02:00
|
|
|
int posix_memalign(FAR void **, size_t, size_t);
|
2020-06-01 08:21:15 +02:00
|
|
|
|
2016-07-15 16:33:47 +02:00
|
|
|
/* Pseudo-Terminals */
|
|
|
|
|
2021-05-06 20:34:12 +02:00
|
|
|
#ifdef CONFIG_PSEUDOTERM
|
2022-02-02 18:42:18 +01:00
|
|
|
int posix_openpt(int oflag);
|
2016-07-15 16:33:47 +02:00
|
|
|
FAR char *ptsname(int fd);
|
2020-08-29 05:03:19 +02:00
|
|
|
int ptsname_r(int fd, FAR char *buf, size_t buflen);
|
|
|
|
int unlockpt(int fd);
|
2016-07-15 17:39:33 +02:00
|
|
|
|
|
|
|
/* int grantpt(int fd); Not implemented */
|
|
|
|
|
|
|
|
#define grantpt(fd) (0)
|
2016-07-15 16:33:47 +02:00
|
|
|
#endif
|
|
|
|
|
2015-08-14 16:35:01 +02:00
|
|
|
/* Arithmetic */
|
2010-10-09 22:46:14 +02:00
|
|
|
|
2020-08-29 05:03:19 +02:00
|
|
|
int abs(int j);
|
|
|
|
long int labs(long int j);
|
2015-08-14 20:04:57 +02:00
|
|
|
#ifdef CONFIG_HAVE_LONG_LONG
|
|
|
|
long long int llabs(long long int j);
|
|
|
|
#endif
|
|
|
|
|
2020-08-29 05:03:19 +02:00
|
|
|
div_t div(int number, int denom);
|
|
|
|
ldiv_t ldiv(long number, long denom);
|
2015-08-14 16:45:59 +02:00
|
|
|
#ifdef CONFIG_HAVE_LONG_LONG
|
2020-08-29 05:03:19 +02:00
|
|
|
lldiv_t lldiv(long long number, long long denom);
|
2015-08-14 16:45:59 +02:00
|
|
|
#endif
|
2015-08-14 16:35:01 +02:00
|
|
|
|
|
|
|
/* Temporary files */
|
|
|
|
|
2020-09-17 10:03:38 +02:00
|
|
|
FAR char *mktemp(FAR char *path_template);
|
2020-08-29 05:03:19 +02:00
|
|
|
int mkstemp(FAR char *path_template);
|
2020-08-29 06:18:13 +02:00
|
|
|
FAR char *mkdtemp(FAR char *path_template);
|
2010-10-09 22:46:14 +02:00
|
|
|
|
2009-06-20 20:22:47 +02:00
|
|
|
/* Sorting */
|
|
|
|
|
2020-08-29 05:03:19 +02:00
|
|
|
void qsort(FAR void *base, size_t nel, size_t width,
|
|
|
|
CODE int (*compar)(FAR const void *, FAR const void *));
|
2009-06-20 20:22:47 +02:00
|
|
|
|
2015-10-02 20:33:58 +02:00
|
|
|
/* Binary search */
|
|
|
|
|
2020-08-29 05:03:19 +02:00
|
|
|
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 *));
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2021-11-29 05:46:00 +01:00
|
|
|
/* Current program name manipulation */
|
|
|
|
|
|
|
|
FAR const char *getprogname(void);
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-11-16 17:36:30 +01:00
|
|
|
#endif /* __INCLUDE_STDLIB_H */
|