diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2009-06-14 15:36:18 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2009-06-14 15:36:18 +0000 |
commit | 6ee68a773a24586f6e6cfaccdf7dce064d213e88 (patch) | |
tree | b58f7a0c1a757afd69497ec1acd90d07ef722701 | |
parent | e1c5f0014d78d36039793087273d4f2925134eaf (diff) | |
download | nuttx-6ee68a773a24586f6e6cfaccdf7dce064d213e88.tar.gz nuttx-6ee68a773a24586f6e6cfaccdf7dce064d213e88.tar.bz2 nuttx-6ee68a773a24586f6e6cfaccdf7dce064d213e88.zip |
Add strtoul, strtoll, strtoull, atol, and atoll.
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1883 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r-- | nuttx/ChangeLog | 2 | ||||
-rw-r--r-- | nuttx/Documentation/NuttX.html | 4 | ||||
-rw-r--r-- | nuttx/TODO | 9 | ||||
-rw-r--r-- | nuttx/include/stdlib.h | 14 | ||||
-rw-r--r-- | nuttx/lib/Makefile | 15 | ||||
-rw-r--r-- | nuttx/lib/lib_checkbase.c | 114 | ||||
-rw-r--r-- | nuttx/lib/lib_internal.h | 12 | ||||
-rw-r--r-- | nuttx/lib/lib_isbasedigit.c | 103 | ||||
-rw-r--r-- | nuttx/lib/lib_skipspace.c | 69 | ||||
-rw-r--r-- | nuttx/lib/lib_strtol.c | 131 | ||||
-rw-r--r-- | nuttx/lib/lib_strtoll.c | 105 | ||||
-rw-r--r-- | nuttx/lib/lib_strtoul.c | 97 | ||||
-rw-r--r-- | nuttx/lib/lib_strtoull.c | 99 |
13 files changed, 660 insertions, 114 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index c863f37d8..3fac74613 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -775,3 +775,5 @@ 0.4.8 2009-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> + * Add strtoll() and strtoull(); Add macros for atol() and atoll(). + diff --git a/nuttx/Documentation/NuttX.html b/nuttx/Documentation/NuttX.html index 3235811d5..044938d8d 100644 --- a/nuttx/Documentation/NuttX.html +++ b/nuttx/Documentation/NuttX.html @@ -8,7 +8,7 @@ <tr align="center" bgcolor="#e4e4e4"> <td> <h1><big><font color="#3c34ec"><i>NuttX RTOS</i></font></big></h1> - <p>Last Updated: June 13, 2009</p> + <p>Last Updated: June 14, 2009</p> </td> </tr> </table> @@ -1470,6 +1470,8 @@ buildroot-0.1.6 2009-xx-xx <spudmonkey@racsa.co.cr> <pre><ul> nuttx-0.4.9 2009-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> + * Add strtoll() and strtoull(); Add macros for atol() and atoll(). + pascal-0.1.3 2009-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> buildroot-0.1.7 2009-xx-xx <spudmonkey@racsa.co.cr> diff --git a/nuttx/TODO b/nuttx/TODO index 001e511bb..78c687000 100644 --- a/nuttx/TODO +++ b/nuttx/TODO @@ -18,7 +18,7 @@ NuttX TODO List (Last updated April 12, 2009) (2) NuttShell (NSH) (examples/nsh) (3) Other Applications & Tests (examples/) (1) Linux/Cywgin simulation (arch/sim) - (2) ARM (arch/arm/) + (3) ARM (arch/arm/) (1) ARM/C5471 (arch/arm/src/c5471/) (3) ARM/DM320 (arch/arm/src/dm320/) (2) ARM/i.MX (arch/arm/src/imx/) @@ -428,6 +428,13 @@ o ARM (arch/arm/) Status: Open Priority: Low + Description: The Cortex-M3 user context swich logic uses SVCall instructions. + This user context switching time could be improved by eliminating + the SVCalls and developing assembly language implementations + of the context save and restore logic. + Status: Open + Priority: Low + o ARM/C5471 (arch/arm/src/c5471/) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/nuttx/include/stdlib.h b/nuttx/include/stdlib.h index 92437a574..645998754 100644 --- a/nuttx/include/stdlib.h +++ b/nuttx/include/stdlib.h @@ -120,9 +120,19 @@ EXTERN int atexit(void (*func)(void)); /* String to binary conversions */ -#define atoi(nptr) strtol((nptr), (FAR char**)NULL, 10) EXTERN long strtol(const char *, char **, int); -EXTERN double_t strtod(const char *, char **); +EXTERN unsigned long strtoul(const char *, char **, int); +#ifdef CONFIG_HAVE_LONG_LONG +EXTERN long long strtoll(const char *, char **, int); +EXTERN unsigned long long strtoull(const char *, char **, int); +#endif +EXTERN double_t strtod(const char *, char **); + +#define atoi(nptr) strtol((nptr), NULL, 10); +#define atol(nptr) strtol((nptr), NULL, 10); +#ifdef CONFIG_HAVE_LONG_LONG +#define atoll(nptr) strtoll((nptr), NULL, 10); +#endif /* Memory Management */ diff --git a/nuttx/lib/Makefile b/nuttx/lib/Makefile index 9b023d04e..bef36aad8 100644 --- a/nuttx/lib/Makefile +++ b/nuttx/lib/Makefile @@ -1,7 +1,7 @@ ############################################################################ # lib/Makefile # -# Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. +# Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. # Author: Gregory Nutt <spudmonkey@racsa.co.cr> # # Redistribution and use in source and binary forms, with or without @@ -43,12 +43,13 @@ ifneq ($(CONFIG_NFILE_STREAMS),0) MISC_SRCS += lib_streamsem.c endif -STRING_SRCS = lib_memset.c lib_memcpy.c lib_memcmp.c lib_memmove.c \ - lib_strcpy.c lib_strncpy.c lib_strcmp.c lib_strncmp.c \ - lib_strcasecmp.c lib_strncasecmp.c lib_strlen.c lib_strdup.c \ - lib_strcat.c lib_strncat.c lib_strtol.c lib_strchr.c \ - lib_strrchr.c lib_strspn.c lib_strcspn.c lib_strtok.c \ - lib_strtokr.c lib_strerror.c +STRING_SRCS = lib_checkbase.c lib_isbasedigit.c lib_memset.c lib_memcpy.c \ + lib_memcmp.c lib_memmove.c lib_skipspace.c lib_strcasecmp.c \ + lib_strcat.c lib_strchr.c lib_strcpy.c lib_strcmp.c lib_strcspn.c \ + lib_strdup.c lib_strerror.c lib_strlen.c lib_strncasecmp.c \ + lib_strncat.c lib_strncmp.c lib_strncpy.c lib_strrchr.c \ + lib_strspn.c lib_strtok.c lib_strtokr.c lib_strtol.c lib_strtoll.c \ + lib_strtoul.c lib_strtoull.c CTYPE_SRCS = diff --git a/nuttx/lib/lib_checkbase.c b/nuttx/lib/lib_checkbase.c new file mode 100644 index 000000000..bf4dadf02 --- /dev/null +++ b/nuttx/lib/lib_checkbase.c @@ -0,0 +1,114 @@ +/**************************************************************************** + * lib_checkbase.c + * + * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <sys/types.h> +#include <string.h> +#include <ctype.h> +#include "lib_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_checkbase + * + * Description: + * This is part of the strol() family implementation. This function checks + * the initial part of a string to see if it can determine the numeric + * base that is represented. + * + * Assumptions: + * *ptr points to the first, non-whitespace character in the string. + * + ****************************************************************************/ + +int lib_checkbase(int base, const char **pptr) +{ + const char *ptr = *pptr; + + /* Check for unspecified base */ + + if (!base) + { + /* Assume base 10 */ + + base = 10; + + /* Check for leading '0' - that would signify octal or hex (or binary) */ + + if (*ptr == '0') + { + /* Assume octal */ + + base = 8; + ptr++; + + /* Check for hexidecimal */ + + if ((*ptr == 'X' || *ptr == 'x') && + lib_isbasedigit(ptr[1], 16, NULL)) + { + base = 16; + ptr++; + } + } + } + + /* If it a hexidecimal representation, than discard any leading "0X" or "0x" */ + + else if (base == 16) + { + if (ptr[0] == '0' && (ptr[1] == 'X' || ptr[1] == 'x')) + { + ptr += 2; + } + } + + /* Return the updated pointer and base */ + + *pptr = ptr; + return base; +} + diff --git a/nuttx/lib/lib_internal.h b/nuttx/lib/lib_internal.h index f6eabe6bc..9e5b55f93 100644 --- a/nuttx/lib/lib_internal.h +++ b/nuttx/lib/lib_internal.h @@ -131,4 +131,16 @@ extern void lib_give_semaphore(FAR struct file_struct *stream); extern int lib_getbase(const char *nptr, const char **endptr); +/* Defined in lib_skipspace.c */ + +extern void lib_skipspace(const char **pptr); + +/* Defined in lib_isbasedigit.c */ + +extern boolean lib_isbasedigit(int ch, int base, int *value); + +/* Defined in lib_checkbase.c */ + +extern int lib_checkbase(int base, const char **pptr); + #endif /* __LIB_INTERNAL_H */ diff --git a/nuttx/lib/lib_isbasedigit.c b/nuttx/lib/lib_isbasedigit.c new file mode 100644 index 000000000..c3976ea86 --- /dev/null +++ b/nuttx/lib/lib_isbasedigit.c @@ -0,0 +1,103 @@ +/**************************************************************************** + * lib/lib_isbasedigit.c + * + * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <sys/types.h> +#include <string.h> +#include <ctype.h> +#include "lib_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_isbasedigit + * + * Description: + * Given an ASCII character, ch, and a base (1-36) do two + * things: 1) Determine if ch is a valid charcter, and 2) + * convert ch to its binary value. + * + ****************************************************************************/ + +boolean lib_isbasedigit(int ch, int base, int *value) +{ + boolean ret = FALSE; + int tmp = 0; + + if (base <= 10) + { + if (ch >= '0' && ch <= base + '0' - 1) + { + tmp = ch - '0'; + ret = TRUE; + } + } + else if (base <= 36) + { + if (ch >= '0' && ch <= '9') + { + tmp = ch - '0'; + ret =TRUE; + } + else if (ch >= 'a' && ch <= 'a' + base - 11) + { + tmp = ch - 'a' + 10; + ret = TRUE; + } + else if (ch >= 'A' && ch <= 'A' + base - 11) + { + tmp = ch - 'A' + 10; + ret = TRUE; + } + } + + if (value) + { + *value = tmp; + } + return ret; +} + + diff --git a/nuttx/lib/lib_skipspace.c b/nuttx/lib/lib_skipspace.c new file mode 100644 index 000000000..d111645e7 --- /dev/null +++ b/nuttx/lib/lib_skipspace.c @@ -0,0 +1,69 @@ +/**************************************************************************** + * lib/lib_skipspace.c + * + * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <sys/types.h> +#include <string.h> +#include <ctype.h> +#include "lib_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_skipspace + * + * Description: + * Skip over leading whitespace + * + ****************************************************************************/ + +void lib_skipspace(const char **pptr) +{ + const char *ptr = *pptr; + while (isspace(*ptr)) ptr++; + *pptr = ptr; +} + + diff --git a/nuttx/lib/lib_strtol.c b/nuttx/lib/lib_strtol.c index 8e2d26f3f..dcd376523 100644 --- a/nuttx/lib/lib_strtol.c +++ b/nuttx/lib/lib_strtol.c @@ -1,4 +1,4 @@ -/************************************************************ +/**************************************************************************** * lib_strtol.c * * Copyright (C) 2007 Gregory Nutt. All rights reserved. @@ -14,7 +14,7 @@ * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * 3. Neither the name Gregory Nutt nor the names of its contributors may be + * 3. Neither the name NuttX nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * @@ -31,80 +31,41 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Included Files - ************************************************************/ + ****************************************************************************/ #include <nuttx/config.h> #include <sys/types.h> -#include <string.h> -#include <ctype.h> +#include <stdlib.h> +#include "lib_internal.h" -/************************************************************ +/**************************************************************************** * Private Functions - ************************************************************/ + ****************************************************************************/ -/* Skip leading spaces */ - -static void lib_skipspace(const char **nptr) -{ - register const char *tmp = *nptr; - while (isspace(*tmp)) tmp++; - *nptr = tmp; -} - -static int lib_isbasedigit(int c, int base, int *value) -{ - int tmp = 0; - int ret = 0; - - if (base <= 10) - { - if (c >= '0' && c <= base + '0' - 1) - { - tmp = c - '0'; - ret = 1; - } - } - else if (base <= 36) - { - if (c >= '0' && c <= '9') - { - tmp = c - '0'; - ret = 1; - } - else if (c >= 'a' && c <= 'a' + base - 11) - { - tmp = c - 'a' + 10; - ret = 1; - } - else if (c >= 'A' && c <= 'A' + base - 11) - { - tmp = c - 'A' + 10; - ret = 1; - } - } - - if (value) - { - *value = tmp; - } - return ret; -} - -/************************************************************ +/**************************************************************************** * Public Functions - ************************************************************/ - -/* Limited to base 1-36 */ + ****************************************************************************/ +/**************************************************************************** + * Name: strtol + * + * Description: + * The strtol() function converts the initial part of the string in + * nptr to a long integer value according to the given base, which must be + * between 2 and 36 inclusive, or be the special value 0. + * + * Warning: does not check for integer overflow! + * + ****************************************************************************/ + long strtol(const char *nptr, char **endptr, int base) { unsigned long accum = 0; - int value; - int negate = 0; + boolean negate = FALSE; if (nptr) { @@ -116,51 +77,19 @@ long strtol(const char *nptr, char **endptr, int base) if (*nptr == '-') { - negate = 1; + negate = TRUE; nptr++; - lib_skipspace(&nptr); } else if (*nptr == '+') { nptr++; - lib_skipspace(&nptr); } - /* Check for unspecified base */ + /* Get the unsigned value */ - if (!base) - { - base = 10; - if (*nptr == '0') - { - base = 8; - nptr++; - if ((*nptr == 'X' || *nptr == 'x') && - lib_isbasedigit(nptr[1], 16, NULL)) - { - base = 16; - nptr++; - } - } - } - else if (base == 16) - { - if (nptr[0] == '0' && (nptr[1] == 'X' || nptr[1] == 'x')) - { - nptr += 2; - } - } + accum = strtoul(nptr, endptr, base); - while (lib_isbasedigit(*nptr, base, &value)) - { - accum = accum*base + value; - nptr++; - } - - if (endptr) - { - *endptr = (char *)nptr; - } + /* Correct the sign of the result */ if (negate) { @@ -170,7 +99,3 @@ long strtol(const char *nptr, char **endptr, int base) return (long)accum; } -unsigned long strtoul(const char *nptr, char **endptr, int base) -{ - return (unsigned long)strtol(nptr, endptr, base); -} diff --git a/nuttx/lib/lib_strtoll.c b/nuttx/lib/lib_strtoll.c new file mode 100644 index 000000000..6566d75c6 --- /dev/null +++ b/nuttx/lib/lib_strtoll.c @@ -0,0 +1,105 @@ +/**************************************************************************** + * lib_strtoll.c + * + * Copyright (C) 2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <sys/types.h> +#include <stdlib.h> +#include "lib_internal.h" + +#ifdef CONFIG_HAVE_LONG_LONG + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: strtoll + * + * Description: + * The strtol() function converts the initial part of the string in + * nptr to a long long integer value according to the given base, which + * must be between 2 and 36 inclusive, or be the special value 0. + * + * Warning: does not check for integer overflow! + * + ****************************************************************************/ + +long long strtoll(const char *nptr, char **endptr, int base) +{ + unsigned long long accum = 0; + boolean negate = FALSE; + + if (nptr) + { + /* Skip leading spaces */ + + lib_skipspace(&nptr); + + /* Check for leading + or - */ + + if (*nptr == '-') + { + negate = TRUE; + nptr++; + } + else if (*nptr == '+') + { + nptr++; + } + + /* Get the unsigned value */ + + accum = strtoull(nptr, endptr, base); + + /* Correct the sign of the result */ + + if (negate) + { + return -(long long)accum; + } + } + return (long long)accum; +} + +#endif + diff --git a/nuttx/lib/lib_strtoul.c b/nuttx/lib/lib_strtoul.c new file mode 100644 index 000000000..6479d60c1 --- /dev/null +++ b/nuttx/lib/lib_strtoul.c @@ -0,0 +1,97 @@ +/**************************************************************************** + * lib/lib_strtoul.c + * + * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <sys/types.h> +#include <stdlib.h> +#include "lib_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: strtoul + * + * Description: + * The strtol() function converts the initial part of the string in + * nptr to a long unsigned integer value according to the given base, which + * must be between 2 and 36 inclusive, or be the special value 0. + * + * Warning: does not check for integer overflow! + * + ****************************************************************************/ + +unsigned long strtoul(const char *nptr, char **endptr, int base) +{ + unsigned long accum = 0; + int value; + + if (nptr) + { + /* Skip leading spaces */ + + lib_skipspace(&nptr); + + /* Check for unspecified base */ + + base = lib_checkbase(base, &nptr); + + /* Accumulate each "digit" */ + + while (lib_isbasedigit(*nptr, base, &value)) + { + accum = accum*base + value; + nptr++; + } + + /* Return the final pointer to the unused value */ + + if (endptr) + { + *endptr = (char *)nptr; + } + } + return accum; +} + diff --git a/nuttx/lib/lib_strtoull.c b/nuttx/lib/lib_strtoull.c new file mode 100644 index 000000000..2a135b3c8 --- /dev/null +++ b/nuttx/lib/lib_strtoull.c @@ -0,0 +1,99 @@ +/**************************************************************************** + * lib/lib_strtoull.c + * + * Copyright (C) 2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <nuttx/compiler.h> +#include <sys/types.h> +#include <stdlib.h> +#include "lib_internal.h" + +#ifdef CONFIG_HAVE_LONG_LONG + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: strtoull + * + * Description: + * The strtol() function converts the initial part of the string in + * nptr to a long unsigned integer value according to the given base, which + * must be between 2 and 36 inclusive, or be the special value 0. + * + ****************************************************************************/ + +unsigned long long strtoull(const char *nptr, char **endptr, int base) +{ + unsigned long long accum = 0; + int value; + + if (nptr) + { + /* Skip leading spaces */ + + lib_skipspace(&nptr); + + /* Check for unspecified base */ + + base = lib_checkbase(base, &nptr); + + /* Accumulate each "digit" */ + + while (lib_isbasedigit(*nptr, base, &value)) + { + accum = accum*base + value; + nptr++; + } + + /* Return the final pointer to the unused value */ + + if (endptr) + { + *endptr = (char *)nptr; + } + } + return accum; +} +#endif + |