diff --git a/crnlib/crn_arealist.cpp b/crnlib/crn_arealist.cpp index f2d3ce7c..d21ed0cb 100644 --- a/crnlib/crn_arealist.cpp +++ b/crnlib/crn_arealist.cpp @@ -13,11 +13,7 @@ static void area_fatal_error(const char*, const char* pMsg, ...) { va_start(args, pMsg); char buf[512]; -#if defined(_WIN32) - vsnprintf_s(buf, sizeof(buf), pMsg, args); -#else - vsnprintf(buf, sizeof(buf), pMsg, args); -#endif + crnlib_vsnprintf(buf, sizeof(buf), pMsg, args); va_end(args); diff --git a/crnlib/crn_assert.cpp b/crnlib/crn_assert.cpp index feb5e504..c4474f25 100644 --- a/crnlib/crn_assert.cpp +++ b/crnlib/crn_assert.cpp @@ -15,7 +15,7 @@ void crnlib_enable_fail_exceptions(bool enabled) { void crnlib_assert(const char* pExp, const char* pFile, unsigned line) { char buf[512]; - sprintf_s(buf, sizeof(buf), "%s(%u): Assertion failed: \"%s\"\n", pFile, line, pExp); + crnlib_snprintf(buf, sizeof(buf), "%s(%u): Assertion failed: \"%s\"\n", pFile, line, pExp); crnlib_output_debug_string(buf); @@ -28,7 +28,7 @@ void crnlib_assert(const char* pExp, const char* pFile, unsigned line) { void crnlib_fail(const char* pExp, const char* pFile, unsigned line) { char buf[512]; - sprintf_s(buf, sizeof(buf), "%s(%u): Failure: \"%s\"\n", pFile, line, pExp); + crnlib_snprintf(buf, sizeof(buf), "%s(%u): Failure: \"%s\"\n", pFile, line, pExp); crnlib_output_debug_string(buf); @@ -49,7 +49,7 @@ void crnlib_fail(const char* pExp, const char* pFile, unsigned line) { void trace(const char* pFmt, va_list args) { if (crnlib_is_debugger_present()) { char buf[512]; - vsprintf_s(buf, sizeof(buf), pFmt, args); + crnlib_snprintf(buf, sizeof(buf), pFmt, args); crnlib_output_debug_string(buf); } diff --git a/crnlib/crn_console.cpp b/crnlib/crn_console.cpp index cf334dcf..5af4ee00 100644 --- a/crnlib/crn_console.cpp +++ b/crnlib/crn_console.cpp @@ -51,7 +51,7 @@ void console::vprintf(eConsoleMessageType type, const char* p, va_list args) { m_num_messages[type]++; char buf[cConsoleBufSize]; - vsprintf_s(buf, cConsoleBufSize, p, args); + crnlib_vsnprintf(buf, cConsoleBufSize, p, args); bool handled = false; diff --git a/crnlib/crn_dynamic_string.cpp b/crnlib/crn_dynamic_string.cpp index 2b8763ce..bc96223f 100644 --- a/crnlib/crn_dynamic_string.cpp +++ b/crnlib/crn_dynamic_string.cpp @@ -71,7 +71,7 @@ void dynamic_string::optimize() { int dynamic_string::compare(const char* p, bool case_sensitive) const { CRNLIB_ASSERT(p); - const int result = (case_sensitive ? strcmp : crn_stricmp)(get_ptr_priv(), p); + const int result = (case_sensitive ? strcmp : crnlib_stricmp)(get_ptr_priv(), p); if (result < 0) return -1; @@ -236,22 +236,14 @@ dynamic_string& dynamic_string::truncate(uint new_len) { dynamic_string& dynamic_string::tolower() { if (m_len) { -#if defined(_WIN32) - _strlwr_s(get_ptr_priv(), m_buf_size); -#else - strlwr(get_ptr_priv()); -#endif + crnlib_strnlwr(get_ptr_priv(), m_buf_size); } return *this; } dynamic_string& dynamic_string::toupper() { if (m_len) { -#if defined(_WIN32) - _strupr_s(get_ptr_priv(), m_buf_size); -#else - strupr(get_ptr_priv()); -#endif + crnlib_strnupr(get_ptr_priv(), m_buf_size); } return *this; } @@ -303,7 +295,7 @@ dynamic_string& dynamic_string::format_args(const char* p, va_list args) { #if defined(_WIN32) int l = vsnprintf_s(buf, cBufSize, _TRUNCATE, p, args); #else - int l = vsnprintf(buf, cBufSize, p, args); + int l = crnlib_vsnprintf(buf, cBufSize, p, args); #endif if (l <= 0) clear(); @@ -387,7 +379,7 @@ int dynamic_string::find_left(const char* p, bool case_sensitive) const { const int p_len = (int)strlen(p); for (int i = 0; i <= (m_len - p_len); i++) - if ((case_sensitive ? strncmp : _strnicmp)(p, &m_pStr[i], p_len) == 0) + if ((case_sensitive ? strncmp : crnlib_strnicmp)(p, &m_pStr[i], p_len) == 0) return i; return -1; @@ -424,7 +416,7 @@ int dynamic_string::find_right(const char* p, bool case_sensitive) const { const int p_len = (int)strlen(p); for (int i = m_len - p_len; i >= 0; i--) - if ((case_sensitive ? strncmp : _strnicmp)(p, &m_pStr[i], p_len) == 0) + if ((case_sensitive ? strncmp : crnlib_strnicmp)(p, &m_pStr[i], p_len) == 0) return i; return -1; diff --git a/crnlib/crn_platform.cpp b/crnlib/crn_platform.cpp index a9480f76..0fdce6a9 100644 --- a/crnlib/crn_platform.cpp +++ b/crnlib/crn_platform.cpp @@ -7,49 +7,18 @@ #endif #if !defined(_WIN32) -int sprintf_s(char* buffer, size_t sizeOfBuffer, const char* format, ...) { - if (!sizeOfBuffer) - return 0; - - va_list args; - va_start(args, format); - int c = vsnprintf(buffer, sizeOfBuffer, format, args); - va_end(args); - - buffer[sizeOfBuffer - 1] = '\0'; - - if (c < 0) - return sizeOfBuffer - 1; - - return CRNLIB_MIN(c, (int)sizeOfBuffer - 1); -} - -int vsprintf_s(char* buffer, size_t sizeOfBuffer, const char* format, va_list args) { - if (!sizeOfBuffer) - return 0; - - int c = vsnprintf(buffer, sizeOfBuffer, format, args); - - buffer[sizeOfBuffer - 1] = '\0'; - - if (c < 0) - return sizeOfBuffer - 1; - - return CRNLIB_MIN(c, (int)sizeOfBuffer - 1); -} - -char* strlwr(char* p) { +char* crnlib_strnlwr(char* p, size_t n) { char* q = p; - while (*q) { + for (size_t i = 0; i < n && *q; i++) { char c = *q; *q++ = tolower(c); } return p; } -char* strupr(char* p) { +char* crnlib_strnupr(char* p, size_t n) { char* q = p; - while (*q) { + for (size_t i = 0; i < n && *q; i++) { char c = *q; *q++ = toupper(c); } diff --git a/crnlib/crn_platform.h b/crnlib/crn_platform.h index a120f321..07124214 100644 --- a/crnlib/crn_platform.h +++ b/crnlib/crn_platform.h @@ -66,13 +66,20 @@ const bool c_crnlib_big_endian_platform = !c_crnlib_little_endian_platform; #define CRNLIB_GET_ALIGNMENT(v) ((!sizeof(v)) ? 1 : (__alignof(v) ? __alignof(v) : sizeof(uint32))) -#if !defined(_WIN32) -int sprintf_s(char* buffer, size_t sizeOfBuffer, const char* format, ...); -int vsprintf_s(char* buffer, size_t sizeOfBuffer, const char* format, va_list args); -char* strlwr(char* p); -char* strupr(char* p); -#define _stricmp strcasecmp -#define _strnicmp strncasecmp +#if defined(_WIN32) +#define crnlib_snprintf sprintf_s +#define crnlib_vsnprintf vsprintf_s +#define crnlib_strnlwr _strlwr_s +#define crnlib_strnupr _strupr_s +#define crnlib_stricmp _stricmp +#define crnlib_strnicmp _strnicmp +#else +#define crnlib_snprintf snprintf +#define crnlib_vsnprintf vsnprintf +char* crnlib_strnlwr(char* p, size_t n); +char* crnlib_strnupr(char* p, size_t n); +#define crnlib_stricmp strcasecmp +#define crnlib_strnicmp strncasecmp #endif inline bool crnlib_is_little_endian() { diff --git a/crnlib/crn_resample_filters.cpp b/crnlib/crn_resample_filters.cpp index 6b4ef40d..254915bf 100644 --- a/crnlib/crn_resample_filters.cpp +++ b/crnlib/crn_resample_filters.cpp @@ -296,7 +296,7 @@ const int g_num_resample_filters = sizeof(g_resample_filters) / sizeof(g_resampl int find_resample_filter(const char* pName) { for (int i = 0; i < g_num_resample_filters; i++) - if (_stricmp(pName, g_resample_filters[i].name) == 0) + if (crnlib_stricmp(pName, g_resample_filters[i].name) == 0) return i; return cInvalidIndex; } diff --git a/crnlib/crn_strutils.cpp b/crnlib/crn_strutils.cpp index 6e9ab281..8801d1d6 100644 --- a/crnlib/crn_strutils.cpp +++ b/crnlib/crn_strutils.cpp @@ -16,10 +16,6 @@ char* crn_strdup(const char* pStr) { return p; } -int crn_stricmp(const char* p, const char* q) { - return _stricmp(p, q); -} - char* strcpy_safe(char* pDst, uint dst_len, const char* pSrc) { CRNLIB_ASSERT(pDst && pSrc && dst_len); if (!dst_len) @@ -310,10 +306,10 @@ bool string_to_bool(const char* p, bool& value) { value = false; - if (_stricmp(p, "false") == 0) + if (crnlib_stricmp(p, "false") == 0) return true; - if (_stricmp(p, "true") == 0) { + if (crnlib_stricmp(p, "true") == 0) { value = true; return true; } diff --git a/crnlib/crn_strutils.h b/crnlib/crn_strutils.h index b0acc437..def3d329 100644 --- a/crnlib/crn_strutils.h +++ b/crnlib/crn_strutils.h @@ -10,7 +10,6 @@ namespace crnlib { char* crn_strdup(const char* pStr); -int crn_stricmp(const char* p, const char* q); char* strcpy_safe(char* pDst, uint dst_len, const char* pSrc); diff --git a/crnlib/crn_value.h b/crnlib/crn_value.h index 4d7f808a..dfd147ac 100644 --- a/crnlib/crn_value.h +++ b/crnlib/crn_value.h @@ -166,10 +166,10 @@ class value { return false; } - if (_stricmp(p, "false") == 0) { + if (crnlib_stricmp(p, "false") == 0) { set_bool(false); return true; - } else if (_stricmp(p, "true") == 0) { + } else if (crnlib_stricmp(p, "true") == 0) { set_bool(true); return true; } diff --git a/crnlib/lzham_timer.h b/crnlib/lzham_timer.h index f5608a9f..93407078 100644 --- a/crnlib/lzham_timer.h +++ b/crnlib/lzham_timer.h @@ -62,7 +62,7 @@ class scoped_perf_section { : m_start_ticks(lzham_timer::get_ticks()) { va_list args; va_start(args, pName); - vsprintf_s(m_name, sizeof(m_name), pName, args); + crnlib_vsnprintf(m_name, sizeof(m_name), pName, args); va_end(args); lzham_buffered_printf("Thread: 0x%08X, BEGIN Time: %3.3fms, Section: %s\n", GetCurrentThreadId(), lzham_timer::ticks_to_ms(m_start_ticks), m_name); diff --git a/crunch/crunch.cpp b/crunch/crunch.cpp index c1bd16ac..996a5462 100644 --- a/crunch/crunch.cpp +++ b/crunch/crunch.cpp @@ -1137,7 +1137,7 @@ class crunch { static bool check_for_option(int argc, char* argv[], const char* pOption) { for (int i = 1; i < argc; i++) { if ((argv[i][0] == '/') || (argv[i][0] == '-')) { - if (crn_stricmp(&argv[i][1], pOption) == 0) + if (crnlib_stricmp(&argv[i][1], pOption) == 0) return true; } } diff --git a/example1/example1.cpp b/example1/example1.cpp index 6174d01e..fa0afb98 100644 --- a/example1/example1.cpp +++ b/example1/example1.cpp @@ -14,6 +14,8 @@ // .DDS file format definitions. #include "dds_defs.h" +#include "crn_platform.h" + // stb_image, for loading/saving image files. #ifdef _MSC_VER #pragma warning(disable : 4244) // conversion from 'int' to 'uint8', possible loss of data @@ -71,7 +73,7 @@ static int error(const char* pMsg, ...) { va_list args; va_start(args, pMsg); char buf[512]; - vsprintf_s(buf, sizeof(buf), pMsg, args); + crnlib_vsnprintf(buf, sizeof(buf), pMsg, args); va_end(args); printf("%s", buf); return EXIT_FAILURE; @@ -82,7 +84,7 @@ static crn_uint8* read_file_into_buffer(const char* pFilename, crn_uint32& size) size = 0; FILE* pFile = NULL; - fopen_s(&pFile, pFilename, "rb"); + crn_fopen(&pFile, pFilename, "rb"); if (!pFile) return NULL; @@ -260,19 +262,19 @@ int main(int argc, char* argv[]) { if (argv[i][0] == '/') argv[i][0] = '-'; - if (!_stricmp(argv[i], "-crn")) { + if (!crnlib_stricmp(argv[i], "-crn")) { output_crn = true; - } else if (!_stricmp(argv[i], "-pixelformat")) { + } else if (!crnlib_stricmp(argv[i], "-pixelformat")) { if (++i >= argc) return error("Expected pixel format!"); - if (!_stricmp(argv[i], "dxt1a")) { + if (!crnlib_stricmp(argv[i], "dxt1a")) { enable_dxt1a = true; fmt = cCRNFmtDXT1; } else { uint f; for (f = 0; f < cCRNFmtTotal; f++) { - if (!_stricmp(argv[i], crn_get_format_string(static_cast(f)))) { + if (!crnlib_stricmp(argv[i], crn_get_format_string(static_cast(f)))) { fmt = static_cast(f); break; } @@ -280,34 +282,34 @@ int main(int argc, char* argv[]) { if (f == cCRNFmtTotal) return error("Unrecognized pixel format: %s\n", argv[i]); } - } else if (!_stricmp(argv[i], "-bitrate")) { + } else if (!crnlib_stricmp(argv[i], "-bitrate")) { if (++i >= argc) return error("Invalid bitrate!"); bitrate = (float)atof(argv[i]); if ((bitrate < .1f) || (bitrate > 8.0f)) return error("Invalid bitrate!"); - } else if (!_stricmp(argv[i], "-quality")) { + } else if (!crnlib_stricmp(argv[i], "-quality")) { if (++i >= argc) return error("Invalid quality level!"); quality_level = atoi(argv[i]); if ((quality_level < 0) || (quality_level > cCRNMaxQualityLevel)) return error("Invalid quality level!"); - } else if (!_stricmp(argv[i], "-out")) { + } else if (!crnlib_stricmp(argv[i], "-out")) { if (++i >= argc) return error("Expected output filename!"); strcpy_s(out_filename, sizeof(out_filename), argv[i]); - } else if (!_stricmp(argv[i], "-nonsrgb")) + } else if (!crnlib_stricmp(argv[i], "-nonsrgb")) srgb_colorspace = false; - else if (!_stricmp(argv[i], "-nomips")) + else if (!crnlib_stricmp(argv[i], "-nomips")) create_mipmaps = false; - else if (!_stricmp(argv[i], "-noAdaptiveBlocks")) + else if (!crnlib_stricmp(argv[i], "-noAdaptiveBlocks")) use_adaptive_block_sizes = false; - else if (!_stricmp(argv[i], "-setalphatoluma")) + else if (!crnlib_stricmp(argv[i], "-setalphatoluma")) set_alpha_to_luma = true; - else if (!_stricmp(argv[i], "-converttoluma")) + else if (!crnlib_stricmp(argv[i], "-converttoluma")) convert_to_luma = true; else return error("Invalid option: %s\n", argv[i]); @@ -326,12 +328,12 @@ int main(int argc, char* argv[]) { if (mode == 'i') { // Information - if (_stricmp(ext_buf, ".crn") == 0) { + if (crnlib_stricmp(ext_buf, ".crn") == 0) { if (!print_crn_info(pSrc_file_data, src_file_size)) { free(pSrc_file_data); return error("Not a CRN file!\n"); } - } else if (_stricmp(ext_buf, ".dds") == 0) { + } else if (crnlib_stricmp(ext_buf, ".dds") == 0) { if (!print_dds_info(pSrc_file_data, src_file_size)) { free(pSrc_file_data); return error("Not a DDS file!\n"); @@ -355,9 +357,9 @@ int main(int argc, char* argv[]) { if (out_filename[0]) { char out_fname_buf[_MAX_FNAME], out_ext_buf[_MAX_EXT]; _splitpath_s(out_filename, NULL, 0, NULL, 0, out_fname_buf, _MAX_FNAME, out_ext_buf, _MAX_EXT); - if (!_stricmp(out_ext_buf, ".crn")) + if (!crnlib_stricmp(out_ext_buf, ".crn")) output_crn = true; - else if (!_stricmp(out_ext_buf, ".dds")) + else if (!crnlib_stricmp(out_ext_buf, ".dds")) output_crn = false; } @@ -450,12 +452,13 @@ int main(int argc, char* argv[]) { // Write the output file. char dst_filename[FILENAME_MAX]; - sprintf_s(dst_filename, sizeof(dst_filename), "%s%s%s%s", drive_buf, dir_buf, fname_buf, output_crn ? ".crn" : ".dds"); + crnlib_snprintf(dst_filename, sizeof(dst_filename), "%s%s%s%s", drive_buf, dir_buf, fname_buf, output_crn ? ".crn" : ".dds"); if (out_filename[0]) strcpy(dst_filename, out_filename); printf("Writing %s file: %s\n", output_crn ? "CRN" : "DDS", dst_filename); - FILE* pFile = fopen(dst_filename, "wb"); + FILE* pFile = NULL; + crn_fopen(&pFile, dst_filename, "wb"); if ((!pFile) || (fwrite(pOutput_file_data, output_file_size, 1, pFile) != 1) || (fclose(pFile) == EOF)) { free(pSrc_file_data); crn_free_block(pOutput_file_data); @@ -465,7 +468,7 @@ int main(int argc, char* argv[]) { crn_free_block(pOutput_file_data); stbi_image_free(pSrc_image); - } else if (_stricmp(ext_buf, ".crn") == 0) { + } else if (crnlib_stricmp(ext_buf, ".crn") == 0) { // Decompress/transcode CRN to DDS. printf("Decompressing CRN to DDS\n"); @@ -479,12 +482,13 @@ int main(int argc, char* argv[]) { // Now write the DDS file to disk. char dst_filename[FILENAME_MAX]; - sprintf_s(dst_filename, sizeof(dst_filename), "%s%s%s.dds", drive_buf, dir_buf, fname_buf); + crnlib_snprintf(dst_filename, sizeof(dst_filename), "%s%s%s.dds", drive_buf, dir_buf, fname_buf); if (out_filename[0]) strcpy(dst_filename, out_filename); printf("Writing file: %s\n", dst_filename); - FILE* pFile = fopen(dst_filename, "wb"); + FILE* pFile = NULL; + crn_fopen(&pFile, dst_filename, "wb"); if ((!pFile) || (fwrite(pDDS_file_data, dds_file_size, 1, pFile) != 1) || (fclose(pFile) == EOF)) { crn_free_block(pDDS_file_data); free(pSrc_file_data); @@ -496,7 +500,7 @@ int main(int argc, char* argv[]) { print_dds_info(pDDS_file_data, dds_file_size); crn_free_block(pDDS_file_data); - } else if (_stricmp(ext_buf, ".dds") == 0) { + } else if (crnlib_stricmp(ext_buf, ".dds") == 0) { // Unpack DDS to one or more TGA's. if (out_filename[0]) _splitpath_s(out_filename, drive_buf, _MAX_DRIVE, dir_buf, _MAX_DIR, fname_buf, _MAX_FNAME, ext_buf, _MAX_EXT); @@ -521,7 +525,7 @@ int main(int argc, char* argv[]) { int height = std::max(1U, tex_desc.m_height >> level_index); char dst_filename[FILENAME_MAX]; - sprintf_s(dst_filename, sizeof(dst_filename), "%s%s%s_face%u_mip%u.tga", drive_buf, dir_buf, fname_buf, face_index, level_index); + crnlib_snprintf(dst_filename, sizeof(dst_filename), "%s%s%s_face%u_mip%u.tga", drive_buf, dir_buf, fname_buf, face_index, level_index); printf("Writing file: %s\n", dst_filename); if (!stbi_write_tga(dst_filename, width, height, 4, pImages[level_index + face_index * tex_desc.m_levels])) { diff --git a/example2/example2.cpp b/example2/example2.cpp index 72fa2923..7973d965 100644 --- a/example2/example2.cpp +++ b/example2/example2.cpp @@ -20,6 +20,8 @@ // A simple high-precision, platform independent timer class. #include "timer.h" +#include "crn_platform.h" + using namespace crnlib; static int print_usage() { @@ -35,7 +37,7 @@ static int error(const char* pMsg, ...) { va_list args; va_start(args, pMsg); char buf[512]; - vsprintf_s(buf, sizeof(buf), pMsg, args); + crnlib_vsnprintf(buf, sizeof(buf), pMsg, args); va_end(args); printf("%s", buf); return EXIT_FAILURE; @@ -46,7 +48,7 @@ static crn_uint8* read_file_into_buffer(const char* pFilename, crn_uint32& size) size = 0; FILE* pFile = NULL; - fopen_s(&pFile, pFilename, "rb"); + crn_fopen(&pFile, pFilename, "rb"); if (!pFile) return NULL; @@ -80,7 +82,7 @@ int main(int argc, char* argv[]) { if (argv[i][0] == '/') argv[i][0] = '-'; - if (!_stricmp(argv[i], "-out")) { + if (!crnlib_stricmp(argv[i], "-out")) { if (++i >= argc) return error("Expected output filename!"); @@ -131,13 +133,14 @@ int main(int argc, char* argv[]) { // Now create the DDS file. char dst_filename[FILENAME_MAX]; - sprintf_s(dst_filename, sizeof(dst_filename), "%s%s%s.dds", drive_buf, dir_buf, fname_buf); + crnlib_snprintf(dst_filename, sizeof(dst_filename), "%s%s%s.dds", drive_buf, dir_buf, fname_buf); if (out_filename[0]) strcpy(dst_filename, out_filename); printf("Writing DDS file: %s\n", dst_filename); - FILE* pDDS_file = fopen(dst_filename, "wb"); + FILE* pDDS_file = NULL; + crn_fopen(&pDDS_file, dst_filename, "wb"); if (!pDDS_file) { crnd::crnd_unpack_end(pContext); free(pSrc_file_data); diff --git a/example3/example3.cpp b/example3/example3.cpp index db35e468..c6fae24b 100644 --- a/example3/example3.cpp +++ b/example3/example3.cpp @@ -14,6 +14,8 @@ // .DDS file format definitions. #include "dds_defs.h" +#include "crn_platform.h" + // stb_image, for loading/saving image files. #ifdef _MSC_VER #pragma warning(disable : 4244) // conversion from 'int' to 'uint8', possible loss of data @@ -58,7 +60,7 @@ static int error(const char* pMsg, ...) { va_list args; va_start(args, pMsg); char buf[512]; - vsprintf_s(buf, sizeof(buf), pMsg, args); + crnlib_vsnprintf(buf, sizeof(buf), pMsg, args); va_end(args); printf("%s", buf); return EXIT_FAILURE; @@ -83,43 +85,43 @@ int main(int argc, char* argv[]) { if (argv[i][0] == '/') argv[i][0] = '-'; - if (!_stricmp(argv[i], "-out")) { + if (!crnlib_stricmp(argv[i], "-out")) { if (++i >= argc) return error("Expected output filename!"); strcpy_s(out_filename, sizeof(out_filename), argv[i]); - } else if (!_stricmp(argv[i], "-nonsrgb")) + } else if (!crnlib_stricmp(argv[i], "-nonsrgb")) srgb_colorspace = false; - else if (!_stricmp(argv[i], "-pixelformat")) { + else if (!crnlib_stricmp(argv[i], "-pixelformat")) { if (++i >= argc) return error("Expected pixel format!"); uint f; for (f = 0; f < cCRNFmtTotal; f++) { crn_format actual_fmt = crn_get_fundamental_dxt_format(static_cast(f)); - if (!_stricmp(argv[i], crn_get_format_string(actual_fmt))) { + if (!crnlib_stricmp(argv[i], crn_get_format_string(actual_fmt))) { fmt = actual_fmt; break; } } if (f == cCRNFmtTotal) return error("Unrecognized pixel format: %s\n", argv[i]); - } else if (!_stricmp(argv[i], "-dxtquality")) { + } else if (!crnlib_stricmp(argv[i], "-dxtquality")) { if (++i >= argc) return error("Expected DXTn quality!\n"); uint q; for (q = 0; q < cCRNDXTQualityTotal; q++) { - if (!_stricmp(argv[i], crn_get_dxt_quality_string(static_cast(q)))) { + if (!crnlib_stricmp(argv[i], crn_get_dxt_quality_string(static_cast(q)))) { dxt_quality = static_cast(q); break; } } if (q == cCRNDXTQualityTotal) return error("Unrecognized DXTn quality: %s\n", argv[i]); - } else if (!_stricmp(argv[i], "-setalphatoluma")) + } else if (!crnlib_stricmp(argv[i], "-setalphatoluma")) set_alpha_to_luma = true; - else if (!_stricmp(argv[i], "-converttoluma")) + else if (!crnlib_stricmp(argv[i], "-converttoluma")) convert_to_luma = true; else return error("Invalid option: %s\n", argv[i]); @@ -220,13 +222,14 @@ int main(int argc, char* argv[]) { // Now create the DDS file. char dst_filename[FILENAME_MAX]; - sprintf_s(dst_filename, sizeof(dst_filename), "%s%s%s.dds", drive_buf, dir_buf, fname_buf); + crnlib_snprintf(dst_filename, sizeof(dst_filename), "%s%s%s.dds", drive_buf, dir_buf, fname_buf); if (out_filename[0]) strcpy(dst_filename, out_filename); printf("Writing DDS file: %s\n", dst_filename); - FILE* pDDS_file = fopen(dst_filename, "wb"); + FILE* pDDS_file = NULL; + crn_fopen(&pDDS_file, dst_filename, "wb"); if (!pDDS_file) { free(pCompressed_data); return error("Failed creating destination file!\n");