use PATH_MAX for hog pathname, ensure correct translation of path separators
This commit is contained in:
parent
fb066ff53e
commit
5a091ee718
|
@ -1,3 +1,8 @@
|
|||
2004-12-03 Bradley Bell <btb@icculus.org>
|
||||
|
||||
* include/cfile.h, include/physfsx.h: use PATH_MAX for hog
|
||||
pathname, ensure correct translation of path separators
|
||||
|
||||
2004-12-03 Chris Taylor <c.taylor@student.curtin.edu.au>
|
||||
|
||||
* misc/strutil.c: fix stricmp and strnicmp
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id: cfile.h,v 1.14 2004-12-02 09:48:57 btb Exp $ */
|
||||
/* $Id: cfile.h,v 1.15 2004-12-04 04:07:16 btb Exp $ */
|
||||
/*
|
||||
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
|
||||
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
|
||||
|
@ -64,7 +64,7 @@ static inline PHYSFS_file *cfopen(char *filename, char *mode)
|
|||
//Specify the name of the hogfile. Returns 1 if hogfile found & had files
|
||||
static inline int cfile_init(char *hogname)
|
||||
{
|
||||
char pathname[1024];
|
||||
char pathname[PATH_MAX];
|
||||
|
||||
if (!PHYSFSX_getRealPath(hogname, pathname))
|
||||
return 0;
|
||||
|
@ -74,7 +74,7 @@ static inline int cfile_init(char *hogname)
|
|||
|
||||
static inline int cfile_close(char *hogname)
|
||||
{
|
||||
char pathname[1024];
|
||||
char pathname[PATH_MAX];
|
||||
|
||||
if (!PHYSFSX_getRealPath(hogname, pathname))
|
||||
return 0;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id: physfsx.h,v 1.5 2004-12-03 07:29:32 btb Exp $ */
|
||||
/* $Id: physfsx.h,v 1.6 2004-12-04 04:07:16 btb Exp $ */
|
||||
|
||||
/*
|
||||
*
|
||||
|
@ -76,17 +76,42 @@ static inline int PHYSFSX_putc(PHYSFS_file *file, int c)
|
|||
return (int)c;
|
||||
}
|
||||
|
||||
static inline int PHYSFSX_getRealPath(char *stdPath, char *realPath)
|
||||
static inline int PHYSFSX_getRealPath(const char *stdPath, char *realPath)
|
||||
{
|
||||
const char *realDir = PHYSFS_getRealDir(stdPath);
|
||||
char sep = *PHYSFS_getDirSeparator();
|
||||
const char *sep = PHYSFS_getDirSeparator();
|
||||
char *p;
|
||||
|
||||
if (!realDir)
|
||||
return 0;
|
||||
|
||||
Assert(strlen(realDir) + 1 + strlen(stdPath) < PATH_MAX);
|
||||
|
||||
sprintf(realPath, "%s%c%s", realDir, sep, stdPath);
|
||||
strncpy(realPath, realDir, PATH_MAX - 1);
|
||||
if (strlen(realPath) >= strlen(sep))
|
||||
{
|
||||
p = realPath + strlen(realPath) - strlen(sep);
|
||||
if (strcmp(p, sep)) // no sep at end of realPath
|
||||
strncat(realPath, sep, PATH_MAX - 1 - strlen(realPath));
|
||||
}
|
||||
|
||||
if (strlen(stdPath) >= 1)
|
||||
if (*stdPath == '/')
|
||||
stdPath++;
|
||||
|
||||
while (*stdPath)
|
||||
{
|
||||
if (*stdPath == '/')
|
||||
strncat(realPath, sep, PATH_MAX - 1 - strlen(realPath));
|
||||
else
|
||||
{
|
||||
if (strlen(realPath) < PATH_MAX - 2)
|
||||
{
|
||||
p = realPath + strlen(realPath);
|
||||
p[0] = *stdPath;
|
||||
p[1] = '\0';
|
||||
}
|
||||
}
|
||||
stdPath++;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue