/*!
- \brief Turn a string into a number (default if NULL)
+ \brief Turn a string into an integer (default if NULL)
\param nptr the string
\param dft the default
- \return the number version of the string or the default
+ \return the integer version of the string or the default
*/
static inline int switch_safe_atoi(const char *nptr, int dft)
{
}
+/*!
+ \brief Turn a string into a long integer (default if NULL)
+ \param nptr the string
+ \param dft the default
+ \return the long integer version of the string or the default
+*/
+static inline long int switch_safe_atol(const char *nptr, long int dft)
+{
+ return nptr ? atol(nptr) : dft;
+}
+
+
+/*!
+ \brief Turn a string into a long long integer (default if NULL)
+ \param nptr the string
+ \param dft the default
+ \return the long long integer version of the string or the default
+*/
+static inline long long int switch_safe_atoll(const char *nptr, long long int dft)
+{
+ return nptr ? atoll(nptr) : dft;
+}
+
+
/*!
\brief Free a pointer and set it to NULL unless it already is NULL
\param it the pointer
#endif
}
FST_TEST_END()
+
+ FST_TEST_BEGIN(test_switch_safe_atoXX)
+ {
+ fst_check_int_equals(switch_safe_atoi("1", 0), 1);
+ fst_check_int_equals(switch_safe_atoi("", 2), 0);
+ fst_check_int_equals(switch_safe_atoi(0, 3), 3);
+
+ fst_check_int_equals(switch_safe_atol("9275806", 0), 9275806);
+ fst_check_int_equals(switch_safe_atol("", 2), 0);
+ fst_check_int_equals(switch_safe_atol(0, 3), 3);
+
+ fst_check_int_equals(switch_safe_atoll("9275806", 0), 9275806);
+ fst_check_int_equals(switch_safe_atoll("", 2), 0);
+ fst_check_int_equals(switch_safe_atoll(0, 3), 3);
+ }
+ FST_TEST_END()
}
FST_SUITE_END()
}