Skip to content

Commit

Permalink
example2: 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 f92712b commit 13259c5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions example2/example2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#include <math.h>
#include <algorithm>

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

// CRN transcoder library.
#include "crn_decomp.h"
// .DDS file format definitions.
Expand Down Expand Up @@ -96,9 +100,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 file into memory.
printf("Loading source file: %s\n", pSrc_filename);
Expand Down

0 comments on commit 13259c5

Please sign in to comment.