diff --git a/example1/example1.cpp b/example1/example1.cpp index 465ca3ac..72b65c0c 100644 --- a/example1/example1.cpp +++ b/example1/example1.cpp @@ -20,6 +20,7 @@ #include "dds_defs.h" #include "crn_core.h" +#include "crn_strutils.h" #include "crn_file_utils.h" // stb_image, for loading/saving image files. @@ -313,11 +314,7 @@ int main(int argc, char* argv[]) { if (++i >= argc) return error("Expected output filename!"); -#if defined(_WIN32) - strcpy_s(out_filename, sizeof(out_filename), argv[i]); -#else - strncpy(out_filename, argv[i], sizeof(out_filename)); -#endif + strcpy_safe(out_filename, sizeof(out_filename), argv[i]); } else if (!crnlib_stricmp(argv[i], "-nonsrgb")) srgb_colorspace = false; else if (!crnlib_stricmp(argv[i], "-nomips")) @@ -482,11 +479,7 @@ int main(int argc, char* argv[]) { char dst_filename[FILENAME_MAX]; crnlib_snprintf(dst_filename, sizeof(dst_filename), "%s%s%s%s", drive.get_ptr(), dir.get_ptr(), fname.get_ptr(), output_crn ? ".crn" : ".dds"); if (out_filename[0]) -#if defined(_WIN32) - strcpy_s(dst_filename, sizeof(dst_filename), out_filename); -#else - strncpy(dst_filename, out_filename, sizeof(dst_filename)); -#endif + strcpy_safe(dst_filename, sizeof(dst_filename), out_filename); printf("Writing %s file: %s\n", output_crn ? "CRN" : "DDS", dst_filename); FILE* pFile = NULL; @@ -516,11 +509,7 @@ int main(int argc, char* argv[]) { char dst_filename[FILENAME_MAX]; crnlib_snprintf(dst_filename, sizeof(dst_filename), "%s%s%s.dds", drive.get_ptr(), dir.get_ptr(), fname.get_ptr()); if (out_filename[0]) -#if defined(_WIN32) - strcpy_s(dst_filename, sizeof(dst_filename), out_filename); -#else - strncpy(dst_filename, out_filename, sizeof(dst_filename)); -#endif + strcpy_safe(dst_filename, sizeof(dst_filename), out_filename); printf("Writing file: %s\n", dst_filename); FILE* pFile = NULL; diff --git a/example2/example2.cpp b/example2/example2.cpp index 3c6d845d..18033277 100644 --- a/example2/example2.cpp +++ b/example2/example2.cpp @@ -96,11 +96,7 @@ int main(int argc, char* argv[]) { if (++i >= argc) return error("Expected output filename!"); -#if defined(_WIN32) - strcpy_s(out_filename, sizeof(out_filename), argv[i]); -#else - strncpy(out_filename, argv[i], sizeof(out_filename)); -#endif + example2_strncpy(out_filename, argv[i], sizeof(out_filename)); } else return error("Invalid option: %s\n", argv[i]); } @@ -143,7 +139,7 @@ int main(int argc, char* argv[]) { // Now create the DDS file. char dst_filename[FILENAME_MAX]; if (out_filename[0]) { - strcpy(dst_filename, out_filename); + example2_strncpy(dst_filename, out_filename, FILENAME_MAX); } else { unsigned int stripped_length = UINT32_MAX; const char* ext_begin = strrchr(pSrc_filename, '.'); diff --git a/example3/example3.cpp b/example3/example3.cpp index 685af177..aa11da45 100644 --- a/example3/example3.cpp +++ b/example3/example3.cpp @@ -19,6 +19,7 @@ #include "dds_defs.h" #include "crn_core.h" +#include "crn_strutils.h" #include "crn_file_utils.h" // stb_image, for loading/saving image files. @@ -94,11 +95,7 @@ int main(int argc, char* argv[]) { if (++i >= argc) return error("Expected output filename!"); -#if defined(_WIN32) - strcpy_s(out_filename, sizeof(out_filename), argv[i]); -#else - strncpy(out_filename, argv[i], sizeof(out_filename)); -#endif + strcpy_safe(out_filename, sizeof(out_filename), argv[i]); } else if (!crnlib_stricmp(argv[i], "-nonsrgb")) srgb_colorspace = false; else if (!crnlib_stricmp(argv[i], "-pixelformat")) { @@ -233,11 +230,7 @@ int main(int argc, char* argv[]) { char dst_filename[FILENAME_MAX]; crnlib_snprintf(dst_filename, sizeof(dst_filename), "%s%s%s.dds", drive.get_ptr(), dir.get_ptr(), fname.get_ptr()); if (out_filename[0]) -#if defined(_WIN32) - strcpy_s(dst_filename, sizeof(dst_filename), out_filename); -#else - strncpy(dst_filename, out_filename, sizeof(dst_filename)); -#endif + strcpy_safe(dst_filename, sizeof(dst_filename), out_filename); printf("Writing DDS file: %s\n", dst_filename);