From 4846c27c7724b4ded92da6e39ace3521ffd493fd Mon Sep 17 00:00:00 2001 From: cuz Date: Tue, 22 Aug 2006 20:27:59 +0000 Subject: [PATCH] Replace the fixed buffer in the Find() routine by a dynamically allocated string using a StrBuf. This works around problems with Watcom C where FILENAME_MAX was just 80. git-svn-id: svn://svn.cc65.org/cc65/trunk@3765 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/common/searchpath.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/common/searchpath.c b/src/common/searchpath.c index 7ae0a96ef..e4c4f7223 100644 --- a/src/common/searchpath.c +++ b/src/common/searchpath.c @@ -33,7 +33,6 @@ -#include #include #include #if defined(_MSC_VER) @@ -46,6 +45,7 @@ /* common */ #include "searchpath.h" +#include "strbuf.h" #include "xmalloc.h" @@ -107,14 +107,9 @@ static char* Find (const char* Path, const char* File) */ { const char* P; - int Max; - char PathName [FILENAME_MAX]; + StrBuf PathName = AUTO_STRBUF_INITIALIZER; /* Initialize variables */ - Max = sizeof (PathName) - strlen (File) - 2; - if (Max < 0) { - return 0; - } P = Path; /* Handle a NULL pointer as replacement for an empty string */ @@ -124,22 +119,27 @@ static char* Find (const char* Path, const char* File) /* Start the search */ while (*P) { + /* Clear the string buffer */ + SB_Clear (&PathName); + /* Copy the next path element into the buffer */ - int Count = 0; - while (*P != '\0' && *P != ';' && Count < Max) { - PathName [Count++] = *P++; + while (*P != '\0' && *P != ';') { + SB_AppendChar (&PathName, *P++); } /* Add a path separator and the filename */ - if (Count) { - PathName [Count++] = '/'; + if (SB_NotEmpty (&PathName)) { + SB_AppendChar (&PathName, '/'); } - strcpy (PathName + Count, File); + SB_AppendStr (&PathName, File); + SB_Terminate (&PathName); /* Check if this file exists */ - if (access (PathName, 0) == 0) { - /* The file exists */ - return xstrdup (PathName); + if (access (SB_GetBuf (&PathName), 0) == 0) { + /* The file exists, return its name */ + char* Name = xstrdup (SB_GetBuf (&PathName)); + DoneStrBuf (&PathName); + return Name; } /* Skip a list separator if we have one */ @@ -149,6 +149,7 @@ static char* Find (const char* Path, const char* File) } /* Not found */ + DoneStrBuf (&PathName); return 0; } -- 2.39.5