// //////////////////////////////////////////////////////////////////////////// const void *C_memchr(const void *buffer_ptr, int src_char, size_t data_length, const char *name_string) { CheckCountTypeAndValue(data_length, name_string); if (buffer_ptr == NULL) { std::ostringstream error_text; error_text << NullOrEmptyToStringWithColon(name_string, "") << "Invocation of 'memchr()' failed: buffer pointer is 'NULL'."; ThrowInvalidArgument(error_text); } if ((src_char < std::numeric_limits<unsigned char>::min()) || (src_char > std::numeric_limits<unsigned char>::max())) { std::ostringstream error_text; error_text << NullOrEmptyToStringWithColon(name_string, "") << "Invocation of 'memchr()' failed: search character ('" << src_char << "') is outside of the permissible range (" << std::numeric_limits<unsigned char>::min() << " to " << std::numeric_limits<unsigned char>::max() << ", inclusive)."; ThrowInvalidArgument(error_text); } return(::memchr(buffer_ptr, src_char, data_length)); }
// //////////////////////////////////////////////////////////////////////////// template <typename CountType> void CheckCountTypeAndValue(CountType in_count, const char *name_string = NULL) { #if defined(_Windows) && !defined(__MINGW32__) # pragma warning(disable:4127) #endif // #if defined(_Windows) && !defined(__MINGW32__) if (!std::numeric_limits<CountType>::is_integer) { std::ostringstream error_text; error_text << NullOrEmptyToStringWithColon(name_string, "") << "The count type specified is not an integral type."; ThrowInvalidArgument(error_text.str().c_str()); } if (IsValueNegative(in_count)) { std::ostringstream error_text; error_text << NullOrEmptyToStringWithColon(name_string, "") << "The count value specified (" << static_cast<int>(in_count) << ") is negative."; ThrowInvalidArgument(error_text.str().c_str()); } #if defined(_Windows) && !defined(__MINGW32__) # pragma warning(default:4127) #endif // #if defined(_Windows) && !defined(__MINGW32__) }
// //////////////////////////////////////////////////////////////////////////// int C_stricmp(char *ptr_1, const char *ptr_2, const char *name_string) { if (ptr_1 == NULL) { std::ostringstream error_text; error_text << NullOrEmptyToStringWithColon(name_string, "") << "Invocation of 'stricmp()' failed: destination string is 'NULL'."; ThrowInvalidArgument(error_text); } if (ptr_2 == NULL) { std::ostringstream error_text; error_text << NullOrEmptyToStringWithColon(name_string, "") << "Invocation of 'stricmp()' failed: souce string is 'NULL'."; ThrowInvalidArgument(error_text); } return(Utility_stricmp(ptr_1, ptr_2)); }
// //////////////////////////////////////////////////////////////////////////// char *C_strcpy(char *dst_string, const char *src_string, const char *name_string) { if (dst_string == NULL) { std::ostringstream error_text; error_text << NullOrEmptyToStringWithColon(name_string, "") << "Invocation of 'strcpy()' failed: destination string is 'NULL'."; ThrowInvalidArgument(error_text); } if (src_string == NULL) { std::ostringstream error_text; error_text << NullOrEmptyToStringWithColon(name_string, "") << "Invocation of 'strcpy()' failed: souce string is 'NULL'."; ThrowInvalidArgument(error_text); } return(::strcpy(dst_string, src_string)); }
// //////////////////////////////////////////////////////////////////////////// void *C_memcpy(void *dst_ptr, const void *src_ptr, size_t data_length, const char *name_string) { CheckCountTypeAndValue(data_length, name_string); if (dst_ptr == NULL) { std::ostringstream error_text; error_text << NullOrEmptyToStringWithColon(name_string, "") << "Invocation of 'memcpy()' failed: destination pointer is 'NULL'."; ThrowInvalidArgument(error_text); } if (src_ptr == NULL) { std::ostringstream error_text; error_text << NullOrEmptyToStringWithColon(name_string, "") << "Invocation of 'memcpy()' failed: source pointer is 'NULL'."; ThrowInvalidArgument(error_text); } return(::memcpy(dst_ptr, src_ptr, data_length)); }
// //////////////////////////////////////////////////////////////////////////// int C_memcmp(const void *ptr_1, const void *ptr_2, size_t data_length, const char *name_string) { CheckCountTypeAndValue(data_length, name_string); if (ptr_1 == NULL) { std::ostringstream error_text; error_text << NullOrEmptyToStringWithColon(name_string, "") << "Invocation of 'memcmp()' failed: first pointer is 'NULL'."; ThrowInvalidArgument(error_text); } if (ptr_2 == NULL) { std::ostringstream error_text; error_text << NullOrEmptyToStringWithColon(name_string, "") << "Invocation of 'memcmp()' failed: second pointer is 'NULL'."; ThrowInvalidArgument(error_text); } return(::memcmp(ptr_1, ptr_2, data_length)); }
// //////////////////////////////////////////////////////////////////////////// char *C_strdup(const char *src_string, const char *name_string) { if (src_string == NULL) { std::ostringstream error_text; error_text << NullOrEmptyToStringWithColon(name_string, "") << "Invocation of 'strdup()' failed: source string is 'NULL'."; ThrowInvalidArgument(error_text); } char *result_ptr = ::strdup(src_string); if (result_ptr == NULL) { std::ostringstream error_text; error_text << NullOrEmptyToStringWithColon(name_string, "") << "Invocation of 'strdup()' failed: source string of length " << (static_cast<unsigned int>(strlen(src_string)) + 1) << " bytes (including NUL terminator) couldn't be copied."; ThrowBadAlloc(error_text); } return(result_ptr); }
void CheckCongruenceCountAndList(CountType in_count, ListType in_list, const char *name_string = NULL) { CheckCountTypeAndValue(in_count, name_string); if ((in_count && (in_list == NULL)) || ((!(in_count)) && (in_list != NULL))){ std::ostringstream error_text; error_text << NullOrEmptyToStringWithColon(name_string, "") << "The count indicates the presence of " << in_count << " elements in the list, but the list pointer is " << ((in_list == NULL) ? "" : "not ") << "'NULL'."; ThrowInvalidArgument(error_text); } }