diff options
Diffstat (limited to 'nuttx/lib')
-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 |
9 files changed, 635 insertions, 110 deletions
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 + |