Replace MAXPATHNAME with another field in cl_core

This commit is contained in:
jgarcia 2007-03-24 10:47:51 +00:00
parent 7726d09262
commit f682912184
4 changed files with 28 additions and 23 deletions

View file

@ -17,8 +17,19 @@
/******************************** IMPORTS *****************************/
#include <ecl/ecl.h>
#include <stdlib.h>
#include <limits.h>
#ifdef _MSC_VER
#define MAXPATHLEN 512
#endif
#ifndef MAXPATHLEN
# ifdef PATH_MAX
# define MAXPATHLEN PATH_MAX
# else
# define NO_PATH_MAX
# include <unistd.h>
# endif
#endif
#include <stdlib.h>
#include <ecl/internal.h>
extern int GC_dont_gc;
@ -213,6 +224,12 @@ cl_boot(int argc, char **argv)
Ct->symbol.isform = FALSE;
cl_num_symbols_in_core=2;
#ifdef NO_PATH_MAX
cl_core.path_max = sysconf(_PC_PATH_MAX);
#else
cl_core.path_max = MAXPATHLEN;
#endif
cl_core.packages = Cnil;
cl_core.packages_to_be_created = OBJNULL;

View file

@ -24,16 +24,6 @@
#include <limits.h>
#include <string.h>
#include <ctype.h>
#ifdef _MSC_VER
#define MAXPATHLEN 512
#endif
#ifndef MAXPATHLEN
# ifdef PATH_MAX
# define MAXPATHLEN PATH_MAX
# else
# error "Either MAXPATHLEN or PATH_MAX should be defined"
# endif
#endif
typedef int (*delim_fn)(int);
@ -788,7 +778,8 @@ si_coerce_to_filename(cl_object pathname_orig)
FEerror("Pathname ~A does not have a physical namestring",
1, pathname_orig);
}
if (ecl_length(namestring) >= MAXPATHLEN - 16)
if (cl_core.path_max != -1 &&
ecl_length(namestring) >= cl_core.path_max - 16)
FEerror("Too long filename: ~S.", 1, namestring);
#ifdef ECL_UNICODE
if (type_of(namestring) == t_string) {

View file

@ -43,18 +43,10 @@
#if defined(_MSC_VER) || defined(mingw32)
# include <windows.h>
# undef ERROR
# define MAXPATHLEN 512
#endif
#ifndef HAVE_MKSTEMP
# include <fcntl.h>
#endif
#ifndef MAXPATHLEN
# ifdef PATH_MAX
# define MAXPATHLEN PATH_MAX
# else
# error "Either MAXPATHLEN or PATH_MAX should be defined"
# endif
#endif
#if defined(_MSC_VER) || defined(mingw32)
static void
@ -268,7 +260,10 @@ ERROR: FElibc_error("Can't change the current directory to ~S",
void *
ecl_backup_fopen(const char *filename, const char *option)
{
char backupfilename[MAXPATHLEN];
char *backupfilename = cl_alloc(strlen(filename) + 5);
if (backupfilename == NULL) {
FElibc_error("Cannot allocate memory for backup filename", 0);
}
strcat(strcpy(backupfilename, filename), ".BAK");
#ifdef _MSC_VER
@ -279,6 +274,7 @@ ecl_backup_fopen(const char *filename, const char *option)
if (rename(filename, backupfilename))
FElibc_error("Cannot rename the file ~S to ~S.", 2,
make_constant_base_string(filename), make_simple_base_string(backupfilename));
cl_dealloc(backupfilename, 0);
return fopen(filename, option);
}
@ -738,11 +734,11 @@ si_getcwd(void)
cl_object
si_get_library_pathname(void)
{
cl_object s = cl_alloc_adjustable_base_string(MAXPATHLEN);
cl_object s = cl_alloc_adjustable_base_string(cl_core.path_max);
char *buffer = (char*)s->base_string.self;
HMODULE hnd = GetModuleHandle( "ecl.dll" );
cl_index len, ep;
if ((len = GetModuleFileName(hnd, buffer, MAXPATHLEN-1)) == 0)
if ((len = GetModuleFileName(hnd, buffer, cl_core.path_max-1)) == 0)
FEerror("GetModuleFileName failed (last error = ~S)", 1, MAKE_FIXNUM(GetLastError()));
s->base_string.fillp = len;
return ecl_parse_namestring(s, 0, len, &ep, Cnil);

View file

@ -176,6 +176,7 @@ struct cl_core_struct {
cl_object bytes_consed;
cl_object gc_counter;
bool gc_stats;
int path_max;
};
#if defined(mingw32) || defined(_MSC_VER) || defined(cygwin)