1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-20 05:29:39 +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 <string.h>
#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;
}