1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-28 06:30:16 +00:00

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
This commit is contained in:
cuz 2006-08-22 20:27:59 +00:00
parent ae4167e595
commit 4846c27c77

View File

@ -33,7 +33,6 @@
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(_MSC_VER) #if defined(_MSC_VER)
@ -46,6 +45,7 @@
/* common */ /* common */
#include "searchpath.h" #include "searchpath.h"
#include "strbuf.h"
#include "xmalloc.h" #include "xmalloc.h"
@ -107,14 +107,9 @@ static char* Find (const char* Path, const char* File)
*/ */
{ {
const char* P; const char* P;
int Max; StrBuf PathName = AUTO_STRBUF_INITIALIZER;
char PathName [FILENAME_MAX];
/* Initialize variables */ /* Initialize variables */
Max = sizeof (PathName) - strlen (File) - 2;
if (Max < 0) {
return 0;
}
P = Path; P = Path;
/* Handle a NULL pointer as replacement for an empty string */ /* 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 */ /* Start the search */
while (*P) { while (*P) {
/* Clear the string buffer */
SB_Clear (&PathName);
/* Copy the next path element into the buffer */ /* Copy the next path element into the buffer */
int Count = 0; while (*P != '\0' && *P != ';') {
while (*P != '\0' && *P != ';' && Count < Max) { SB_AppendChar (&PathName, *P++);
PathName [Count++] = *P++;
} }
/* Add a path separator and the filename */ /* Add a path separator and the filename */
if (Count) { if (SB_NotEmpty (&PathName)) {
PathName [Count++] = '/'; SB_AppendChar (&PathName, '/');
} }
strcpy (PathName + Count, File); SB_AppendStr (&PathName, File);
SB_Terminate (&PathName);
/* Check if this file exists */ /* Check if this file exists */
if (access (PathName, 0) == 0) { if (access (SB_GetBuf (&PathName), 0) == 0) {
/* The file exists */ /* The file exists, return its name */
return xstrdup (PathName); char* Name = xstrdup (SB_GetBuf (&PathName));
DoneStrBuf (&PathName);
return Name;
} }
/* Skip a list separator if we have one */ /* Skip a list separator if we have one */
@ -149,6 +149,7 @@ static char* Find (const char* Path, const char* File)
} }
/* Not found */ /* Not found */
DoneStrBuf (&PathName);
return 0; return 0;
} }