From 79fb7cbf3ee035f05471b75697f526740e24b2a4 Mon Sep 17 00:00:00 2001 From: relnev Date: Wed, 8 Jan 2003 06:26:20 +0000 Subject: convenient filename hacks git-svn-id: svn://svn.icculus.org/blackshades/trunk@41 5198baeb-e213-0410-be47-fc2ff85ca46f --- Source/Support.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 10 deletions(-) (limited to 'Source/Support.cpp') diff --git a/Source/Support.cpp b/Source/Support.cpp index a05a0a4..75288df 100644 --- a/Source/Support.cpp +++ b/Source/Support.cpp @@ -51,9 +51,66 @@ STUB_FUNCTION; #define O_BINARY 0 #endif +#ifndef MAX_PATH +#define MAX_PATH 256 +#endif + +static void fix_filename(const char *original, char *fixed) +{ + const char *start; + int i; + int len; + + start = original; + if (original[0] == ':') { + start = &original[1]; + } + + /* + here would be stuff to check where the file is, + including the game root and the user local dir + */ + + fixed[MAX_PATH-1] = 0; + + strncpy(fixed, start, MAX_PATH); + + /* check to see if strncpy overwrote the terminator */ + if (fixed[MAX_PATH-1] != 0) { + fixed[MAX_PATH-1] = 0; + + fprintf(stderr, "ERROR: file truncation error: %s -> %s\n", + original, fixed); + } + + len = strlen(fixed); + for (i = 0; i < len; i++) { + if (fixed[i] == ':') { + fixed[i] = '/'; + } + } +} + +/* +Convenient Filename Hacks +*/ + +FILE *cfh_fopen(const char *filename, const char *mode) +{ + char filename1[MAX_PATH]; + + fix_filename(filename, filename1); + + return fopen(filename1, mode); +} + int Files::OpenFile(Str255 Name) { - sFile = open((char *)Name, O_RDONLY | O_BINARY); + char filename1[MAX_PATH]; + + fix_filename((char *)Name, filename1); + + sFile = open(filename1, O_RDONLY | O_BINARY); return sFile; } @@ -74,15 +131,7 @@ void alutLoadWAVFile(char *filename, ALenum *format, void **wave, ALsizei format1, size1, bits1, freq1; int i, len; - strncpy(filename1, filename, sizeof(filename1)); - filename1[sizeof(filename1)-1] = 0; - - len = strlen(filename1); - for (i = 0; i < len; i++) { - if (filename1[i] == ':') { - filename1[i] = '/'; - } - } + fix_filename(filename, filename1); alutLoadWAV(filename1, wave, &format1, &size1, &bits1, &freq1); -- cgit v1.2.3