From 7dc4898b5a0a14e859f0312fe625013ccb4424d0 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Fri, 28 Jun 2024 17:06:06 +0200 Subject: [PATCH] example3: make splitpath computation multiplatform --- example3/example3.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/example3/example3.cpp b/example3/example3.cpp index 346941b7..80189b49 100644 --- a/example3/example3.cpp +++ b/example3/example3.cpp @@ -9,6 +9,10 @@ #include #include +#if !defined(_WIN32) +#include +#endif + // CRN transcoder library. #include "crnlib.h" // .DDS file format definitions. @@ -132,9 +136,20 @@ int main(int argc, char* argv[]) { } // Split the source filename into its various components. +#if defined(_WIN32) char drive_buf[_MAX_DRIVE], dir_buf[_MAX_DIR], fname_buf[_MAX_FNAME], ext_buf[_MAX_EXT]; if (_splitpath_s(pSrc_filename, drive_buf, _MAX_DRIVE, dir_buf, _MAX_DIR, fname_buf, _MAX_FNAME, ext_buf, _MAX_EXT)) return error("Invalid source filename!\n"); +#else + char in_filename[FILENAME_MAX]; + strncpy(in_filename, pSrc_filename, FILENAME_MAX); + const char drive_buf[] = ""; + char *dir_buf = dirname(in_filename); + char *fname_buf = basename(in_filename); + char *dot = strrchr(fname_buf, '.'); + if (dot && dot != fname_buf) + *dot = '\0'; +#endif // Load the source image into memory. printf("Loading source file: %s\n", pSrc_filename);