From 5a091ee718bb49b9160cbfbb145bde2dc191eba0 Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Sat, 4 Dec 2004 04:07:16 +0000 Subject: [PATCH] use PATH_MAX for hog pathname, ensure correct translation of path separators --- ChangeLog | 5 +++++ include/cfile.h | 6 +++--- include/physfsx.h | 37 +++++++++++++++++++++++++++++++------ 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index b62733bf6..827d53eda 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-12-03 Bradley Bell + + * include/cfile.h, include/physfsx.h: use PATH_MAX for hog + pathname, ensure correct translation of path separators + 2004-12-03 Chris Taylor * misc/strutil.c: fix stricmp and strnicmp diff --git a/include/cfile.h b/include/cfile.h index 60aa7cc1c..d41c7ff32 100644 --- a/include/cfile.h +++ b/include/cfile.h @@ -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; diff --git a/include/physfsx.h b/include/physfsx.h index 25126fc6d..e3cd98d28 100644 --- a/include/physfsx.h +++ b/include/physfsx.h @@ -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; }