From f682912184de5813bfae23d1035d2bb60df790c1 Mon Sep 17 00:00:00 2001 From: jgarcia Date: Sat, 24 Mar 2007 10:47:51 +0000 Subject: [PATCH] Replace MAXPATHNAME with another field in cl_core --- src/c/main.d | 19 ++++++++++++++++++- src/c/pathname.d | 13 ++----------- src/c/unixfsys.d | 18 +++++++----------- src/h/external.h | 1 + 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/c/main.d b/src/c/main.d index 39cd584d2..55d2175e4 100644 --- a/src/c/main.d +++ b/src/c/main.d @@ -17,8 +17,19 @@ /******************************** IMPORTS *****************************/ #include -#include #include +#ifdef _MSC_VER +#define MAXPATHLEN 512 +#endif +#ifndef MAXPATHLEN +# ifdef PATH_MAX +# define MAXPATHLEN PATH_MAX +# else +# define NO_PATH_MAX +# include +# endif +#endif +#include #include 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; diff --git a/src/c/pathname.d b/src/c/pathname.d index 62d6fc3f6..a5dfea64f 100644 --- a/src/c/pathname.d +++ b/src/c/pathname.d @@ -24,16 +24,6 @@ #include #include #include -#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) { diff --git a/src/c/unixfsys.d b/src/c/unixfsys.d index 821d60212..219fd5e1a 100644 --- a/src/c/unixfsys.d +++ b/src/c/unixfsys.d @@ -43,18 +43,10 @@ #if defined(_MSC_VER) || defined(mingw32) # include # undef ERROR -# define MAXPATHLEN 512 #endif #ifndef HAVE_MKSTEMP # include #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); diff --git a/src/h/external.h b/src/h/external.h index 4ac4b6f8a..bda4a2dbc 100644 --- a/src/h/external.h +++ b/src/h/external.h @@ -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)