Skip to content

Commit

Permalink
example3: make splitpath computation multiplatform
Browse files Browse the repository at this point in the history
  • Loading branch information
illwieckz committed Jun 28, 2024
1 parent 988cccc commit 2408d47
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions example3/example3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include <math.h>
#include <algorithm>

#if !defined(_WIN32)
#include <libgen.h>
#endif

// CRN transcoder library.
#include "crnlib.h"
// .DDS file format definitions.
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2408d47

Please sign in to comment.