// //////////////////////////////////////////////////////////////////////////// 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__) }
// //////////////////////////////////////////////////////////////////////////// TimeTM TimeTM::TimeLocal(const time_t in_time) { if (in_time < static_cast<time_t>(0)) ThrowInvalidArgument("Invalid 'time_t' encountered in invocation of " "method TimeTM::TimeLocal() (value = " + AnyToString(in_time) + ")."); struct tm out_time; struct tm *result_ptr; #ifdef _Windows if ((result_ptr = localtime(&in_time)) == NULL) TimeT_To_TimeTM_ConvertError("TimeLocal", "localtime", in_time, NULL, result_ptr); out_time = *result_ptr; #else # if defined(__EXTENSIONS__) || defined(_REENTRANT) || defined(_POSIX_C_SOURCE) if (((result_ptr = localtime_r(&in_time, &out_time)) == NULL) || (result_ptr != &out_time)) TimeT_To_TimeTM_ConvertError("TimeLocal", "localtime_r", in_time, &out_time, result_ptr); # else if ((result_ptr = localtime(&in_time)) == NULL) TimeT_To_TimeTM_ConvertError("TimeLocal", "localtime", in_time, NULL, result_ptr); out_time = *result_ptr; # endif /* #if defined(__EXTENSIONS__ || _REENTRANT || _POSIX_C_SOURCE) */ #endif /* #ifdef _Windows */ return(TimeTM(out_time)); }
// //////////////////////////////////////////////////////////////////////////// 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 AddToOffset(std::size_t added_offset) { if ((write_offset_ + added_offset) > mapping_size_) ThrowInvalidArgument("The value specified to 'LogHandlerFileMMap::" "AddToOffset()' (" + AnyToString(added_offset) + ") when added " "to the current 'write_offset_' value (" + AnyToString(write_offset_) + ") is greater than the " "'mapped_size_' member (" + AnyToString(mapping_size_) + ")."); write_offset_ += added_offset; }
// //////////////////////////////////////////////////////////////////////////// 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)); }
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); } }
// //////////////////////////////////////////////////////////////////////////// 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 ParseFromString(const char *in_date, time_t &out_secs, long &out_fractional, long fractional_places) { if (in_date == NULL) ThrowInvalidArgument("Specified date string pointer is 'NULL'."); try { size_t date_length = strlen(in_date); char date_buffer[Length_TimeSpec + 9 + 1]; if (date_length < 8) ThrowInvalidArgument("Unknown date format."); if (date_length == 8) { char *end_ptr; strtoul(in_date, &end_ptr, 10); if (end_ptr != (in_date + 8)) ThrowInvalidArgument("Invalid undelimited date string --- " "only numeric characters are valid."); strcat(nstrcat(strcat(nstrcat(strcat(nstrcpy(date_buffer, in_date, 4), "-"), in_date + 4, 2), "-"), in_date + 6, 2), " 00:00:00.000000000"); ParseFromString_Basic(date_buffer, out_secs, out_fractional, fractional_places); } else { if ((!isdigit(in_date[0])) || (!isdigit(in_date[1])) || (!isdigit(in_date[2])) || (!isdigit(in_date[3])) || (!isdigit(in_date[5])) || (!isdigit(in_date[6])) || (!isdigit(in_date[8])) || (!isdigit(in_date[9]))) ThrowInvalidArgument("Invalid delimited date string --- " "expected format for date portion is 'yyyy-mm-dd'."); if (((in_date[4] != '-') && (in_date[4] != '/')) || ((in_date[7] != '-') && (in_date[7] != '/'))) ThrowInvalidArgument("Invalid delimited date string --- " "expected format for date portion is 'yyyy-mm-dd'."); if (date_length == 10) { strcat(strcpy(date_buffer, in_date), " 00:00:00.000000000"); ParseFromString_Basic(date_buffer, out_secs, out_fractional, fractional_places); } else if (date_length <= Length_TimeSpec) { if (((date_length < 20) && (date_length != 13) && (date_length != 16) && (date_length != 19))) ThrowInvalidArgument("Unknown date format."); if (((in_date[10] != ' ') && (in_date[10] != '.')) || (!isdigit(in_date[11])) || (!isdigit(in_date[12]))) ThrowInvalidArgument("Invalid delimited date/time string."); if (date_length == 13) ParseFromString_Basic(strcat(strcpy(date_buffer, in_date), ":00:00.000000000"), out_secs, out_fractional, fractional_places); else { if (((in_date[13] != ':') && (in_date[13] != '.')) || (!isdigit(in_date[14])) || (!isdigit(in_date[15]))) ThrowInvalidArgument("Invalid delimited date/time string."); if (date_length == 16) ParseFromString_Basic(strcat(strcpy(date_buffer, in_date), ":00.000000000"), out_secs, out_fractional, fractional_places); else { if (((in_date[16] != ':') && (in_date[16] != '.')) || (!isdigit(in_date[17])) || (!isdigit(in_date[18]))) ThrowInvalidArgument("Invalid delimited date/time string."); else if (date_length == 19) ParseFromString_Basic(strcat(strcpy(date_buffer, in_date), ".000000000"), out_secs, out_fractional, fractional_places); else if (in_date[19] != '.') ThrowInvalidArgument("Invalid delimited date/time string."); else ParseFromString_Basic(nstrcat(strcpy(date_buffer, in_date), "000000000", Length_TimeSpec - date_length), out_secs, out_fractional, fractional_places); } } } else ThrowInvalidArgument("Date/time string length exceeds maximum " "permissible (" + AnyToString(Length_TimeSpec) + " characters)."); } } catch (const std::exception &except) { Rethrow(except, "Unable to parse date/time string '" + std::string(in_date) + "': " + std::string(except.what())); } }