summaryrefslogtreecommitdiffstats
path: root/cpukit/libmisc/stringto/stringto.h
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2009-07-22 14:26:25 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2009-07-22 14:26:25 +0000
commite8d59ca6af8991e23309bddd9b200f06c0e9d4a7 (patch)
treebb62e4d5839ba93747af34afc2ae28cce03c48f2 /cpukit/libmisc/stringto/stringto.h
parent2009-07-22 Joel Sherrill <joel.sherrill@oarcorp.com> (diff)
downloadrtems-e8d59ca6af8991e23309bddd9b200f06c0e9d4a7.tar.bz2
2009-07-22 Joel Sherrill <joel.sherrill@oarcorp.com>
* Makefile.am, preinstall.am, libmisc/Makefile.am, wrapup/Makefile.am: Add the stringto family of string to number converters. These are error checking wrappers for the strtoXXX methods and do their best to return false if the conversion failed. The error checking required for this is tedious and error prone. Hence better to have in a family of helper routines. * libmisc/stringto/stringto.h, libmisc/stringto/stringto_template.h, libmisc/stringto/stringtodouble.c, libmisc/stringto/stringtofloat.c, libmisc/stringto/stringtoint.c, libmisc/stringto/stringtolong.c, libmisc/stringto/stringtolonglong.c, libmisc/stringto/stringtounsignedchar.c, libmisc/stringto/stringtounsignedint.c, libmisc/stringto/stringtounsignedlong.c, libmisc/stringto/stringtounsignedlonglong.c: New files.
Diffstat (limited to 'cpukit/libmisc/stringto/stringto.h')
-rw-r--r--cpukit/libmisc/stringto/stringto.h176
1 files changed, 176 insertions, 0 deletions
diff --git a/cpukit/libmisc/stringto/stringto.h b/cpukit/libmisc/stringto/stringto.h
new file mode 100644
index 0000000000..2e7fe151c6
--- /dev/null
+++ b/cpukit/libmisc/stringto/stringto.h
@@ -0,0 +1,176 @@
+/*
+ * COPYRIGHT (c) 2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef __STRING_TO_A_TYPE_h__
+#define __STRING_TO_A_TYPE_h__
+
+/**
+ * @brief Convert String to Unsigned Character (with validation)
+ *
+ * This method converts a string to an unsigned character with
+ * range validation.
+ *
+ * @param[in] s is the string to convert
+ * @param[in] n points to the variable to place the converted output in
+ * @param[in] endptr is used to keep track of the position in the string
+ * @param[in] base is the expected base of the number
+ *
+ * @return This method returns true on successful conversion and *n is
+ * filled in.
+ */
+bool rtems_string_to_unsigned_char(
+ const char *s,
+ unsigned char *n,
+ char **endptr,
+ int base
+);
+
+/**
+ * @brief Convert String to Int (with validation)
+ *
+ * This method converts a string to an int with range validation.
+ *
+ * @param[in] s is the string to convert
+ * @param[in] n points to the variable to place the converted output in
+ * @param[in] endptr is used to keep track of the position in the string
+ * @param[in] base is the expected base of the number
+ *
+ * @return This method returns true on successful conversion and *n is
+ * filled in.
+ */
+bool rtems_string_to_int(
+ const char *s,
+ int *n,
+ char **endptr,
+ int base
+);
+
+/**
+ * @brief Convert String to Long (with validation)
+ *
+ * This method converts a string to a long with
+ * range validation.
+ *
+ * @param[in] s is the string to convert
+ * @param[in] n points to the variable to place the converted output in
+ * @param[in] endptr is used to keep track of the position in the string
+ * @param[in] base is the expected base of the number
+ *
+ * @return This method returns true on successful conversion and *n is
+ * filled in.
+ */
+bool rtems_string_to_long(
+ const char *s,
+ long *n,
+ char **endptr,
+ int base
+);
+
+/**
+ * @brief Convert String to Unsigned Long (with validation)
+ *
+ * This method converts a string to an unsigned long with
+ * range validation.
+ *
+ * @param[in] s is the string to convert
+ * @param[in] n points to the variable to place the converted output in
+ * @param[in] endptr is used to keep track of the position in the string
+ * @param[in] base is the expected base of the number
+ *
+ * @return This method returns true on successful conversion and *n is
+ * filled in.
+ */
+bool rtems_string_to_unsigned_long(
+ const char *s,
+ unsigned long *n,
+ char **endptr,
+ int base
+);
+
+/**
+ * @brief Convert String to Long Long (with validation)
+ *
+ * This method converts a string to a long long with
+ * range validation.
+ *
+ * @param[in] s is the string to convert
+ * @param[in] n points to the variable to place the converted output in
+ * @param[in] endptr is used to keep track of the position in the string
+ * @param[in] base is the expected base of the number
+ *
+ * @return This method returns true on successful conversion and *n is
+ * filled in.
+ */
+bool rtems_string_to_long_long(
+ const char *s,
+ long long *n,
+ char **endptr,
+ int base
+);
+
+/**
+ * @brief Convert String to Unsigned Long Long (with validation)
+ *
+ * This method converts a string to an unsigned character with
+ * range validation.
+ *
+ * @param[in] s is the string to convert
+ * @param[in] n points to the variable to place the converted output in
+ * @param[in] endptr is used to keep track of the position in the string
+ * @param[in] base is the expected base of the number
+ *
+ * @return This method returns true on successful conversion and *n is
+ * filled in.
+ */
+bool rtems_string_to_unsigned_long_long(
+ const char *s,
+ unsigned long long *n,
+ char **endptr,
+ int base
+);
+
+/**
+ * @brief Convert String to Float (with validation)
+ *
+ * This method converts a string to a float with range validation.
+ *
+ * @param[in] s is the string to convert
+ * @param[in] n points to the variable to place the converted output in
+ * @param[in] endptr is used to keep track of the position in the string
+ *
+ * @return This method returns true on successful conversion and *n is
+ * filled in.
+ */
+bool rtems_string_to_float(
+ const char *s,
+ float *n,
+ char **endptr
+);
+
+/**
+ * @brief Convert String to Double (with validation)
+ *
+ * This method converts a string to a double with range validation.
+ *
+ * @param[in] s is the string to convert
+ * @param[in] n points to the variable to place the converted output in
+ * @param[in] endptr is used to keep track of the position in the string
+ *
+ * @return This method returns true on successful conversion and *n is
+ * filled in.
+ */
+bool rtems_string_to_double(
+ const char *s,
+ double *n,
+ char **endptr
+);
+
+#endif