Make __PHYSFS_platformDirSeparator into a single char.
This multichar thing was always stupid. Pull it out of revision control if you ever need it.
This commit is contained in:
parent
aaf8868c8d
commit
03dbc3f758
|
@ -14,10 +14,10 @@
|
||||||
static void *DIR_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
|
static void *DIR_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
|
||||||
{
|
{
|
||||||
PHYSFS_Stat statbuf;
|
PHYSFS_Stat statbuf;
|
||||||
const char *dirsep = PHYSFS_getDirSeparator();
|
const char dirsep = __PHYSFS_platformDirSeparator;
|
||||||
char *retval = NULL;
|
char *retval = NULL;
|
||||||
const size_t namelen = strlen(name);
|
const size_t namelen = strlen(name);
|
||||||
const size_t seplen = strlen(dirsep);
|
const size_t seplen = 1;
|
||||||
int exists = 0;
|
int exists = 0;
|
||||||
|
|
||||||
assert(io == NULL); /* shouldn't create an Io for these. */
|
assert(io == NULL); /* shouldn't create an Io for these. */
|
||||||
|
@ -28,11 +28,14 @@ static void *DIR_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
|
||||||
retval = allocator.Malloc(namelen + seplen + 1);
|
retval = allocator.Malloc(namelen + seplen + 1);
|
||||||
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
|
|
||||||
/* make sure there's a dir separator at the end of the string */
|
|
||||||
/* !!! FIXME: is there really any place where (seplen != 1)? */
|
|
||||||
strcpy(retval, name);
|
strcpy(retval, name);
|
||||||
if (strcmp((name + namelen) - seplen, dirsep) != 0)
|
|
||||||
strcat(retval, dirsep);
|
/* make sure there's a dir separator at the end of the string */
|
||||||
|
if (retval[namelen - 1] != dirsep)
|
||||||
|
{
|
||||||
|
retval[namelen] = dirsep;
|
||||||
|
retval[namelen + 1] = '\0';
|
||||||
|
} /* if */
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
} /* DIR_openArchive */
|
} /* DIR_openArchive */
|
||||||
|
|
52
src/physfs.c
52
src/physfs.c
|
@ -1052,17 +1052,16 @@ static char *calculateUserDir(void)
|
||||||
char *retval = __PHYSFS_platformGetUserDir();
|
char *retval = __PHYSFS_platformGetUserDir();
|
||||||
if (retval == NULL)
|
if (retval == NULL)
|
||||||
{
|
{
|
||||||
const char *dirsep = PHYSFS_getDirSeparator();
|
const char dirsep = __PHYSFS_platformDirSeparator;
|
||||||
const char *uname = __PHYSFS_platformGetUserName();
|
const char *uname = __PHYSFS_platformGetUserName();
|
||||||
const char *str = (uname != NULL) ? uname : "default";
|
const char *str = (uname != NULL) ? uname : "default";
|
||||||
|
const size_t len = strlen(baseDir) + strlen(str) + 7;
|
||||||
|
|
||||||
retval = (char *) allocator.Malloc(strlen(baseDir) + strlen(str) +
|
retval = (char *) allocator.Malloc(len);
|
||||||
strlen(dirsep) + 6);
|
|
||||||
|
|
||||||
if (retval == NULL)
|
if (retval == NULL)
|
||||||
__PHYSFS_setError(ERR_OUT_OF_MEMORY);
|
__PHYSFS_setError(ERR_OUT_OF_MEMORY);
|
||||||
else
|
else
|
||||||
sprintf(retval, "%susers%s%s", baseDir, dirsep, str);
|
sprintf(retval, "%susers%c%s", baseDir, dirsep, str);
|
||||||
|
|
||||||
allocator.Free((void *) uname);
|
allocator.Free((void *) uname);
|
||||||
} /* else */
|
} /* else */
|
||||||
|
@ -1070,23 +1069,29 @@ static char *calculateUserDir(void)
|
||||||
return retval;
|
return retval;
|
||||||
} /* calculateUserDir */
|
} /* calculateUserDir */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* !!! FIXME: remove this and require userdir and basedir to have dirsep
|
||||||
|
* !!! FIXME: appended in the platform layer
|
||||||
|
*/
|
||||||
static int appendDirSep(char **dir)
|
static int appendDirSep(char **dir)
|
||||||
{
|
{
|
||||||
const char *dirsep = PHYSFS_getDirSeparator();
|
const char dirsep = __PHYSFS_platformDirSeparator;
|
||||||
char *ptr;
|
char *ptr = *dir;
|
||||||
|
const size_t len = strlen(ptr);
|
||||||
|
|
||||||
if (strcmp((*dir + strlen(*dir)) - strlen(dirsep), dirsep) == 0)
|
if (ptr[len - 1] == dirsep)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
ptr = (char *) allocator.Realloc(*dir, strlen(*dir) + strlen(dirsep) + 1);
|
ptr = (char *) allocator.Realloc(ptr, len + 2);
|
||||||
if (!ptr)
|
if (!ptr)
|
||||||
{
|
{
|
||||||
allocator.Free(*dir);
|
allocator.Free(*dir);
|
||||||
return 0;
|
return 0;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
strcat(ptr, dirsep);
|
ptr[len] = dirsep;
|
||||||
|
ptr[len+1] = '\0';
|
||||||
|
|
||||||
*dir = ptr;
|
*dir = ptr;
|
||||||
return 1;
|
return 1;
|
||||||
} /* appendDirSep */
|
} /* appendDirSep */
|
||||||
|
@ -1094,8 +1099,8 @@ static int appendDirSep(char **dir)
|
||||||
|
|
||||||
static char *calculateBaseDir(const char *argv0)
|
static char *calculateBaseDir(const char *argv0)
|
||||||
{
|
{
|
||||||
|
const char dirsep = __PHYSFS_platformDirSeparator;
|
||||||
char *retval = NULL;
|
char *retval = NULL;
|
||||||
const char *dirsep = NULL;
|
|
||||||
char *ptr = NULL;
|
char *ptr = NULL;
|
||||||
|
|
||||||
/* Give the platform layer first shot at this. */
|
/* Give the platform layer first shot at this. */
|
||||||
|
@ -1106,26 +1111,10 @@ static char *calculateBaseDir(const char *argv0)
|
||||||
/* We need argv0 to go on. */
|
/* We need argv0 to go on. */
|
||||||
BAIL_IF_MACRO(argv0 == NULL, ERR_ARGV0_IS_NULL, NULL);
|
BAIL_IF_MACRO(argv0 == NULL, ERR_ARGV0_IS_NULL, NULL);
|
||||||
|
|
||||||
dirsep = PHYSFS_getDirSeparator();
|
ptr = strrchr(argv0, dirsep);
|
||||||
if (strlen(dirsep) == 1) /* fast path. */
|
|
||||||
ptr = strrchr(argv0, *dirsep);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ptr = strstr(argv0, dirsep);
|
|
||||||
if (ptr != NULL)
|
|
||||||
{
|
|
||||||
char *p = ptr;
|
|
||||||
while (p != NULL)
|
|
||||||
{
|
|
||||||
ptr = p;
|
|
||||||
p = strstr(p + 1, dirsep);
|
|
||||||
} /* while */
|
|
||||||
} /* if */
|
|
||||||
} /* else */
|
|
||||||
|
|
||||||
if (ptr != NULL)
|
if (ptr != NULL)
|
||||||
{
|
{
|
||||||
size_t size = (size_t) (ptr - argv0);
|
const size_t size = (size_t) (ptr - argv0);
|
||||||
retval = (char *) allocator.Malloc(size + 1);
|
retval = (char *) allocator.Malloc(size + 1);
|
||||||
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
memcpy(retval, argv0, size);
|
memcpy(retval, argv0, size);
|
||||||
|
@ -1310,7 +1299,8 @@ void PHYSFS_freeList(void *list)
|
||||||
|
|
||||||
const char *PHYSFS_getDirSeparator(void)
|
const char *PHYSFS_getDirSeparator(void)
|
||||||
{
|
{
|
||||||
return __PHYSFS_platformDirSeparator;
|
static char retval[2] = { __PHYSFS_platformDirSeparator, '\0' };
|
||||||
|
return retval;
|
||||||
} /* PHYSFS_getDirSeparator */
|
} /* PHYSFS_getDirSeparator */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1031,11 +1031,15 @@ int UNPK_stat(dvoid *opaque, const char *fn, int *exists, PHYSFS_Stat *stat);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The dir separator; "/" on unix, "\\" on win32, ":" on MacOS, etc...
|
* The dir separator; '/' on unix, '\\' on win32, ":" on MacOS, etc...
|
||||||
* Obviously, this isn't a function, but it IS a null-terminated string.
|
* Obviously, this isn't a function. If you need more than one char for this,
|
||||||
|
* you'll need to pull some old pieces of PhysicsFS out of revision control.
|
||||||
*/
|
*/
|
||||||
extern const char *__PHYSFS_platformDirSeparator;
|
#if (((defined _WIN32) || (defined _WIN64)) && (!defined __CYGWIN__))
|
||||||
|
#define __PHYSFS_platformDirSeparator '\\'
|
||||||
|
#else
|
||||||
|
#define __PHYSFS_platformDirSeparator '/'
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the platform. This is called when PHYSFS_init() is called from
|
* Initialize the platform. This is called when PHYSFS_init() is called from
|
||||||
|
|
|
@ -30,10 +30,6 @@
|
||||||
|
|
||||||
#include "physfs_internal.h"
|
#include "physfs_internal.h"
|
||||||
|
|
||||||
|
|
||||||
const char *__PHYSFS_platformDirSeparator = "/";
|
|
||||||
|
|
||||||
|
|
||||||
char *__PHYSFS_platformCopyEnvironmentVariable(const char *varname)
|
char *__PHYSFS_platformCopyEnvironmentVariable(const char *varname)
|
||||||
{
|
{
|
||||||
const char *envr = getenv(varname);
|
const char *envr = getenv(varname);
|
||||||
|
|
|
@ -93,7 +93,6 @@ typedef struct
|
||||||
} WinApiFile;
|
} WinApiFile;
|
||||||
|
|
||||||
|
|
||||||
const char *__PHYSFS_platformDirSeparator = "\\";
|
|
||||||
static char *userDir = NULL;
|
static char *userDir = NULL;
|
||||||
static HANDLE libUserEnv = NULL;
|
static HANDLE libUserEnv = NULL;
|
||||||
static HANDLE detectCDThreadHandle = NULL;
|
static HANDLE detectCDThreadHandle = NULL;
|
||||||
|
|
Loading…
Reference in New Issue