place large filename buffers in data, not stack, for gc effectiveness - gcl.git - GNU Common Lisp

index : gcl.git
GNU Common Lisp
summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamm Maguire <camm@debian.org>2014年10月03日 11:56:45 -0400
committerCamm Maguire <camm@debian.org>2014年10月03日 11:56:45 -0400
commit21345fcb0473695290c3d9058ffb0eadeeb77048 (patch)
tree198c9a1722a8f690bbd4ba97a59a6fb323875585
parent97e656fd1cc71a5e60b384b8fa76fb81961b4544 (diff)
place large filename buffers in data, not stack, for gc effectivenessdata_filenames
Diffstat
-rwxr-xr-xgcl/h/notcomp.h 5
-rw-r--r--gcl/o/alloc.c 23
-rwxr-xr-xgcl/o/fasldlsym.c 39
-rwxr-xr-xgcl/o/file.d 78
-rw-r--r--gcl/o/mingfile.c 15
-rwxr-xr-xgcl/o/pathname.d 12
-rw-r--r--gcl/o/sfaslcoff.c 3
-rw-r--r--gcl/o/sfaslmacosx.c 30
-rwxr-xr-xgcl/o/unixfsys.c 221
9 files changed, 176 insertions, 250 deletions
diff --git a/gcl/h/notcomp.h b/gcl/h/notcomp.h
index 926a6fde7..e4a024afb 100755
--- a/gcl/h/notcomp.h
+++ b/gcl/h/notcomp.h
@@ -367,3 +367,8 @@ extern bool writable_malloc;
#define psystem(x) prof_block(system(x))
#define pfork() prof_block(fork())
+/* #include <sys/param.h> */
+#define MAXPATHLEN 4096
+typedef char Filename[MAXPATHLEN];
+
+Filename FN1,FN2,FN3,FN4;
diff --git a/gcl/o/alloc.c b/gcl/o/alloc.c
index 996718f8a..b51f29ad7 100644
--- a/gcl/o/alloc.c
+++ b/gcl/o/alloc.c
@@ -1389,18 +1389,16 @@ gprof_cleanup(void) {
if (gprof_on) {
- char b[PATH_MAX],b1[PATH_MAX];
-
- if (!getcwd(b,sizeof(b)))
+ if (!getcwd(FN1,sizeof(FN1)))
FEerror("Cannot get working directory", 0);
if (chdir(P_tmpdir))
FEerror("Cannot change directory to tmpdir", 0);
_mcleanup();
- if (snprintf(b1,sizeof(b1),"gmon.out.%u",getpid())<=0)
+ if (snprintf(FN2,sizeof(FN2),"gmon.out.%u",getpid())<=0)
FEerror("Cannot write temporary gmon filename", 0);
- if (rename("gmon.out",b1))
+ if (rename("gmon.out",FN2))
FEerror("Cannot rename gmon.out",0);
- if (chdir(b))
+ if (chdir(FN1))
FEerror("Cannot restore working directory", 0);
gprof_on=0;
@@ -1454,28 +1452,27 @@ DEFUN_NEW("GPROF-QUIT",object,fSgprof_quit,SI
,0,0,NONE,OO,OO,OO,OO,(void),"")
{
extern void _mcleanup(void);
- char b[PATH_MAX],b1[PATH_MAX];
FILE *pp;
unsigned n;
if (!gprof_on)
return Cnil;
- if (!getcwd(b,sizeof(b)))
+ if (!getcwd(FN1,sizeof(FN1)))
FEerror("Cannot get working directory", 0);
if (chdir(P_tmpdir))
FEerror("Cannot change directory to tmpdir", 0);
_mcleanup();
- if (snprintf(b1,sizeof(b1),"gprof %s",kcl_self)<=0)
+ if (snprintf(FN2,sizeof(FN2),"gprof %s",kcl_self)<=0)
FEerror("Cannot write gprof command line", 0);
- if (!(pp=popen(b1,"r")))
+ if (!(pp=popen(FN2,"r")))
FEerror("Cannot open gprof pipe", 0);
- while ((n=fread(b1,1,sizeof(b1),pp)))
- if (!fwrite(b1,1,n,stdout))
+ while ((n=fread(FN2,1,sizeof(FN2),pp)))
+ if (!fwrite(FN2,1,n,stdout))
FEerror("Cannot write gprof output",0);
if (pclose(pp)<0)
FEerror("Cannot close gprof pipe", 0);
- if (chdir(b))
+ if (chdir(FN1))
FEerror("Cannot restore working directory", 0);
gprof_on=0;
diff --git a/gcl/o/fasldlsym.c b/gcl/o/fasldlsym.c
index a4a345489..5c4857e7e 100755
--- a/gcl/o/fasldlsym.c
+++ b/gcl/o/fasldlsym.c
@@ -55,47 +55,46 @@ fasload(object faslfile) {
void *dlp ;
int (*fptr)();
- char buf[MAXPATHLEN],b[MAXPATHLEN],filename[MAXPATHLEN];
static int count;
object memory,data,faslstream;
struct name_list *nl;
object x;
- bzero(buf,sizeof(buf)); /*GC partial stack hole closing*/
- bzero(b,sizeof(b));
- bzero(filename,sizeof(filename));
+ bzero(FN1,sizeof(FN1)); /*GC partial stack hole closing*/
+ bzero(FN2,sizeof(FN2));
+ bzero(FN3,sizeof(FN3));
/* this is just to allow reloading in the same file twice.
*/
- coerce_to_filename(truename(faslfile), filename);
+ coerce_to_filename(truename(faslfile), FN3);
if (!count)
count=time(0);
- massert(snprintf(buf,sizeof(buf),"/tmp/ufas%dxXXXXXX",count++)>0);
- massert(mkstemp(buf)>=0);
+ massert(snprintf(FN1,sizeof(FN1),"/tmp/ufas%dxXXXXXX",count++)>0);
+ massert(mkstemp(FN1)>=0);
- massert((nl=(void *) malloc(strlen(buf)+1+sizeof(nl))));
+ massert((nl=(void *) malloc(strlen(FN1)+1+sizeof(nl))));
massert(loaded_files || !atexit(unlink_loaded_files));
nl->next = loaded_files;
loaded_files = nl;
- strcpy(nl->name,buf);
+ strcpy(nl->name,FN1);
faslstream = open_stream(faslfile, smm_input, Cnil, sKerror);
- massert(snprintf(b,sizeof(b),"cc -shared %s -o %s",filename,buf)>0);
- massert(!psystem(b));
+ massert(snprintf(FN2,sizeof(FN2),"cc -shared %s -o %s",FN3,FN1)>0);
+ massert(!psystem(FN2));
- if (!(dlp = dlopen(buf,RTLD_NOW))) {
+ if (!(dlp = dlopen(FN1,RTLD_NOW))) {
fputs(dlerror(),stderr);
- FEerror("Cannot open for dynamic link ~a",1,make_simple_string(filename));
+ FEerror("Cannot open for dynamic link ~a",1,make_simple_string(FN3));
}
- x=find_init_name1(buf,0);
- massert(x->st.st_fillp+1<sizeof(b));
- memcpy(b,x->st.st_self,x->st.st_fillp);
- b[x->st.st_fillp]=0;
- if (!(fptr=dlsym(dlp,b))) {
+ x=find_init_name1(FN1,0);
+ massert(x->st.st_fillp+1<sizeof(FN2));
+ memcpy(FN2,x->st.st_self,x->st.st_fillp);
+ FN2[x->st.st_fillp]=0;
+ if (!(fptr=dlsym(dlp,FN2))) {
fputs(dlerror(),stderr);
- FEerror("Cannot lookup ~a in ~a",2,make_simple_string(b),make_simple_string(filename));
+ FEerror("Cannot lookup ~a in ~a",2,make_simple_string(FN2),make_simple_string(FN3));
}
SEEK_TO_END_OFILE(faslstream->sm.sm_fp);
@@ -111,7 +110,7 @@ fasload(object faslfile) {
call_init(0,memory,data,fptr);
- unlink(buf);
+ unlink(FN1);
close_stream(faslstream);
return memory->cfd.cfd_size;
diff --git a/gcl/o/file.d b/gcl/o/file.d
index c3b4fcf58..94e9daf45 100755
--- a/gcl/o/file.d
+++ b/gcl/o/file.d
@@ -348,26 +348,15 @@ object if_exists, if_does_not_exist;
{
object x;
FILE *fp=NULL;
- char fname[PATH_MAX];
object unzipped = 0;
vs_mark;
-/*
- if (type_of(fn) != t_string)
- FEwrong_type_argument(sLstring, fn);
-*/
- /* if (fn->st.st_fillp > BUFSIZ - 1) */
- /* too_long_file_name(fn); */
- /* for (i = 0; i < fn->st.st_fillp; i++) */
- /* fname[i] = fn->st.st_self[i]; */
-
- /* fname[i] = '0円'; */
- coerce_to_filename(fn,fname);
+ coerce_to_filename(fn,FN1);
if (smm == smm_input || smm == smm_probe) {
- if(fname[0]=='|')
- fp = popen(fname+1,"r");
+ if(FN1[0]=='|')
+ fp = popen(FN1+1,"r");
else
- fp = fopen_not_dir(fname, "r");
+ fp = fopen_not_dir(FN1, "r");
AGAIN:
if (fp == NULL) {
@@ -375,7 +364,7 @@ object if_exists, if_does_not_exist;
{
static struct string st;
char buf[256];
- if (snprintf(buf,sizeof(buf),"%s.gz",fname)<=0)
+ if (snprintf(buf,sizeof(buf),"%s.gz",FN1)<=0)
FEerror("Cannot write .gz filename",0);
st.st_self=buf;
st.st_dim=st.st_fillp=strlen(buf);
@@ -385,7 +374,7 @@ object if_exists, if_does_not_exist;
int n;
if (!(fp=tmpfile()))
FEerror("Cannot create temporary file",0);
- if (snprintf(buf,sizeof(buf),"zcat %s.gz",fname)<=0)
+ if (snprintf(buf,sizeof(buf),"zcat %s.gz",FN1)<=0)
FEerror("Cannot write zcat pipe name",0);
if (!(pp=popen(buf,"r")))
FEerror("Cannot open zcat pipe",0);
@@ -400,41 +389,14 @@ object if_exists, if_does_not_exist;
}
}
-/* fp = fopen_not_dir(buf,"r"); */
-/* if (fp) */
-/* { */
-/* #ifdef NO_MKSTEMP */
-/* char *tmp; */
-/* #else */
-/* char tmp[200]; */
-/* #endif */
-/* char command [500]; */
-/* fclose(fp); */
-/* #ifdef NO_MKSTEMP */
-/* tmp = tmpnam(0); */
-/* #else */
-/* snprintf(tmp,sizeof(tmp),"uzipXXXXXX"); */
- /* mkstemp(tmp); */ /* fixme: catch errors */
-/* #endif */
-/* unzipped = make_simple_string(tmp); */
-/* sprintf(command,"gzip -dc %s > %s",buf,tmp); */
-/* fp = 0; */
-/* if (0 == system(command)) */
-/* { */
-/* fp = fopen_not_dir(tmp,"r"); */
-/* if (fp) */
-/* goto AGAIN; */
-/* /\* should not get here *\/ */
-/* else { unlink(tmp);}} */
-/* }} */
if (if_does_not_exist == sKerror)
cannot_open(fn);
else if (if_does_not_exist == sKcreate) {
- fp = fopen_not_dir(fname, "w");
+ fp = fopen_not_dir(FN1, "w");
if (fp == NULL)
cannot_create(fn);
fclose(fp);
- fp = fopen_not_dir(fname, "r");
+ fp = fopen_not_dir(FN1, "r");
if (fp == NULL)
cannot_open(fn);
} else if (if_does_not_exist == Cnil)
@@ -446,36 +408,36 @@ object if_exists, if_does_not_exist;
} else if (smm == smm_output || smm == smm_io) {
if (if_exists == sKnew_version && if_does_not_exist == sKcreate)
goto CREATE;
- fp = fopen_not_dir(fname, "r");
+ fp = fopen_not_dir(FN1, "r");
if (fp != NULL) {
fclose(fp);
if (if_exists == sKerror)
FEerror("The file ~A already exists.", 1, fn);
else if (if_exists == sKrename) {
if (smm == smm_output)
- fp = backup_fopen(fname, "w");
+ fp = backup_fopen(FN1, "w");
else
- fp = backup_fopen(fname, "w+");
+ fp = backup_fopen(FN1, "w+");
if (fp == NULL)
cannot_create(fn);
} else if (if_exists == sKrename_and_delete ||
if_exists == sKnew_version ||
if_exists == sKsupersede) {
if (smm == smm_output)
- fp = fopen_not_dir(fname, "w");
+ fp = fopen_not_dir(FN1, "w");
else
- fp = fopen_not_dir(fname, "w+");
+ fp = fopen_not_dir(FN1, "w+");
if (fp == NULL)
cannot_create(fn);
} else if (if_exists == sKoverwrite) {
- fp = fopen_not_dir(fname, "r+");
+ fp = fopen_not_dir(FN1, "r+");
if (fp == NULL)
cannot_open(fn);
} else if (if_exists == sKappend) {
if (smm == smm_output)
- fp = fopen_not_dir(fname, "a");
+ fp = fopen_not_dir(FN1, "a");
else
- fp = fopen_not_dir(fname, "a+");
+ fp = fopen_not_dir(FN1, "a+");
if (fp == NULL)
FEerror("Cannot append to the file ~A.",1,fn);
} else if (if_exists == Cnil)
@@ -490,13 +452,13 @@ object if_exists, if_does_not_exist;
CREATE:
if (smm == smm_output)
{
- if(fname[0]=='|')
- fp = popen(fname+1,"w");
+ if(FN1[0]=='|')
+ fp = popen(FN1+1,"w");
else
- fp = fopen_not_dir(fname, "w");
+ fp = fopen_not_dir(FN1, "w");
}
else
- fp = fopen_not_dir(fname, "w+");
+ fp = fopen_not_dir(FN1, "w+");
if (fp == NULL)
cannot_create(fn);
} else if (if_does_not_exist == Cnil)
diff --git a/gcl/o/mingfile.c b/gcl/o/mingfile.c
index 26a67f98c..82d7389d6 100644
--- a/gcl/o/mingfile.c
+++ b/gcl/o/mingfile.c
@@ -6,7 +6,6 @@ extern object truename(object);
extern object make_pathname();
void Ldirectory ( void )
{
- char filename[MAXPATHLEN];
object *top=vs_top;
object path;
check_arg(1);
@@ -14,19 +13,19 @@ void Ldirectory ( void )
path = vs_base[0] = coerce_to_pathname(vs_base[0]);
if (vs_base[0]->pn.pn_name==Cnil && vs_base[0]->pn.pn_type==Cnil) {
- coerce_to_filename(vs_base[0], filename);
- strcat(filename, "*.*");
+ coerce_to_filename(vs_base[0], FN1);
+ strcat(FN1, "*.*");
} else if (vs_base[0]->pn.pn_name==Cnil) {
vs_base[0]->pn.pn_name = sKwild;
- coerce_to_filename(vs_base[0], filename);
+ coerce_to_filename(vs_base[0], FN1);
vs_base[0]->pn.pn_name = Cnil;
} else if (vs_base[0]->pn.pn_type==Cnil) {
- coerce_to_filename(vs_base[0], filename);
- strcat(filename, ".*");
+ coerce_to_filename(vs_base[0], FN1);
+ strcat(FN1, ".*");
} else
- coerce_to_filename(vs_base[0], filename);
+ coerce_to_filename(vs_base[0], FN1);
{ WIN32_FIND_DATA data;
- HANDLE dirHandle = FindFirstFile(filename,&data);
+ HANDLE dirHandle = FindFirstFile(FN1,&data);
if (dirHandle== INVALID_HANDLE_VALUE) {
vs_base[0]=Cnil; return;
diff --git a/gcl/o/pathname.d b/gcl/o/pathname.d
index c508bab20..131345efd 100755
--- a/gcl/o/pathname.d
+++ b/gcl/o/pathname.d
@@ -399,13 +399,11 @@ M:
N:
token->st.st_fillp = i;
#ifdef FIX_FILENAME
- {char buf[MAXPATHLEN];
- if (i > MAXPATHLEN-1) i =MAXPATHLEN-1;
- memcpy(buf,token->st.st_self,i);
- buf[i]=0;
- FIX_FILENAME(x,buf);
- return (make_simple_string(buf));
- }
+ if (i > sizeof(FN1)-1) i =sizeof(FN1)-1;
+ memcpy(FN1,token->st.st_self,i);
+ FN1[i]=0;
+ FIX_FILENAME(x,FN1);
+ return (make_simple_string(FN1));
#endif
return(copy_simple_string(token));
}
diff --git a/gcl/o/sfaslcoff.c b/gcl/o/sfaslcoff.c
index 9cbbcb0f6..173368baf 100644
--- a/gcl/o/sfaslcoff.c
+++ b/gcl/o/sfaslcoff.c
@@ -393,12 +393,11 @@ fasload(object faslfile) {
struct reloc *rel,*rele;
object memory, data;
FILE *fp;
- char filename[MAXPATHLEN],*st1,*ste;
+ char *st1,*ste;
int i;
ul init_address=0;
void *st,*est;
- coerce_to_filename(faslfile, filename);
faslfile = open_stream(faslfile, smm_input, Cnil, sKerror);
fp = faslfile->sm.sm_fp;
diff --git a/gcl/o/sfaslmacosx.c b/gcl/o/sfaslmacosx.c
index 716deda53..c09688571 100644
--- a/gcl/o/sfaslmacosx.c
+++ b/gcl/o/sfaslmacosx.c
@@ -67,7 +67,6 @@ get_init_sym(NSModule module,object ff) {
static object inf;
static struct string st;
object x;
- char ib[MAXPATHLEN+1];
NSSymbol v;
if (!inf) {
@@ -94,14 +93,14 @@ get_init_sym(NSModule module,object ff) {
x=ifuncall1(inf,(object)&st);
if (x->d.t!=t_string)
sfasl_error("INIT-NAME error\n");
- assert(snprintf(ib,sizeof(ib),"_init_%-.*s",x->st.st_dim,x->st.st_self)>0);
+ assert(snprintf(FN1,sizeof(FN1),"_init_%-.*s",x->st.st_dim,x->st.st_self)>0);
- if (!(v=NSLookupSymbolInModule(module, ib))) {
+ if (!(v=NSLookupSymbolInModule(module, FN1))) {
x=ifuncall2(inf,(object)&st,Ct);
if (x->d.t!=t_string)
sfasl_error("INIT-NAME error\n");
- assert(snprintf(ib,sizeof(ib),"_init_%-.*s",x->st.st_dim,x->st.st_self)>0);
- if (!(v=NSLookupSymbolInModule(module, ib)))
+ assert(snprintf(FN1,sizeof(FN1),"_init_%-.*s",x->st.st_dim,x->st.st_self)>0);
+ if (!(v=NSLookupSymbolInModule(module, FN1)))
sfasl_error("Cannot lookup init-name\n");
}
@@ -191,17 +190,12 @@ int fasload (object faslfile)
int (*fptr) ();
- char filename [MAXPATHLEN];
- char tmpfile [MAXPATHLEN];
-
char cmd [256];
static int count = 0;
static char ldfmt [] = "gcc -bind_at_load -bundle -bundle_loader %s -o %s %s";
- char fmt [MAXPATHLEN];
-
extern int seek_to_end_ofile (FILE *);
if (count == 0) {
@@ -210,12 +204,12 @@ int fasload (object faslfile)
count = time (0);
}
- coerce_to_filename (truename (faslfile), filename);
+ coerce_to_filename (truename (faslfile), FN1);
- snprintf (tmpfile, sizeof (tmpfile), "/tmp/ufas%dx.so", count++);
+ snprintf (FN2, sizeof (FN2), "/tmp/ufas%dx.so", count++);
- mkstemp (tmpfile);
- symlink (filename, tmpfile);
+ mkstemp (FN2);
+ symlink (FN1, FN2);
faslstream = open_stream (faslfile, smm_input, Cnil, sKerror);
@@ -224,15 +218,15 @@ int fasload (object faslfile)
loaded (if the bundle makes reference to this shared library). To avoid this, we
would need all external bundle calls to be indirected through the loader image stubs. */
- coerce_to_filename (symbol_value (sSAmacosx_ldcmdA), fmt);
+ coerce_to_filename (symbol_value (sSAmacosx_ldcmdA), FN3);
- snprintf (cmd, sizeof(cmd), fmt, kcl_self, tmpfile, filename);
+ snprintf (cmd, sizeof(cmd), FN3, kcl_self, FN2, FN1);
if (system (cmd) != 0) {
sfasl_error ("cannot execute command `%s'\n", cmd);
}
- fptr = prepare_bundle (faslfile, tmpfile);
+ fptr = prepare_bundle (faslfile, FN2);
if (seek_to_end_ofile (faslstream->sm.sm_fp) != 1) {
sfasl_error ("error seeking to end of object file");
@@ -252,7 +246,7 @@ int fasload (object faslfile)
call_init (0, memory, data, fptr);
- unlink (tmpfile);
+ unlink (FN2);
return memory->cfd.cfd_size;
}
diff --git a/gcl/o/unixfsys.c b/gcl/o/unixfsys.c
index ea2f9dd96..703db992e 100755
--- a/gcl/o/unixfsys.c
+++ b/gcl/o/unixfsys.c
@@ -145,11 +145,6 @@ DEV_FOUND:
#endif /* not HAVE_GETCWD */
#endif
-#ifndef MAXPATHLEN
-#define MAXPATHLEN 512
-#endif
-
-
#ifdef HAVE_GETCWD
char *
getwd(char *buffer) {
@@ -228,13 +223,10 @@ object
truename(object pathname)
{
register char *p, *q;
- char filename[MAXPATHLEN];
- char truefilename[MAXPATHLEN];
- char current_directory[MAXPATHLEN];
- char directory[MAXPATHLEN];
+
#ifdef __MINGW32__
DWORD current_directory_length =
- GetCurrentDirectory ( MAXPATHLEN, current_directory );
+ GetCurrentDirectory ( MAXPATHLEN, FN3 );
if ( MAXPATHLEN < current_directory_length ) {
FEerror ( "truename got a current directory name larger than MAXPATHLEN", 1, "" );
}
@@ -242,10 +234,10 @@ truename(object pathname)
FEerror ( "truename could not determine the current directory.", 1, "" );
}
#else
- massert(current_directory==getcwd(current_directory,sizeof(current_directory)));
+ massert(FN3==getcwd(FN3,sizeof(FN3)));
#endif
- coerce_to_filename(pathname, filename);
+ coerce_to_filename(pathname, FN1);
#ifdef S_IFLNK
{
@@ -253,27 +245,25 @@ truename(object pathname)
struct stat filestatus;
int islinkcount=8;
- if (lstat(filename, &filestatus) >= 0)
+ if (lstat(FN1, &filestatus) >= 0)
while (((filestatus.st_mode&S_IFMT) == S_IFLNK) && (--islinkcount>0)) {
- char newname[MAXPATHLEN];
- int newlen;
+ int newlen=readlink(FN1,FN4,sizeof(FN4));;
- newlen=readlink(filename,newname,MAXPATHLEN-1);
if (newlen < 0)
return((FEerror("Symlink broken at ~S.",1,pathname),Cnil));
- for (p = filename, q = 0; *p != '0円'; p++)
+ for (p = FN1, q = 0; *p != '0円'; p++)
if (*p == '/') q = p;
- if (q == 0 || *newname == '/')
- q = filename;
+ if (q == 0 || *FN4 == '/')
+ q = FN1;
else
q++;
- memcpy(q,newname,newlen);
+ memcpy(q,FN4,newlen);
q[newlen]=0;
- if (lstat(filename, &filestatus) < 0)
+ if (lstat(FN1, &filestatus) < 0)
islinkcount=0; /* It would be ANSI to do the following :
return(file_error("Symlink broken at ~S.",pathname));
but this would break DIRECTORY if a file points to nowhere */
@@ -281,31 +271,31 @@ truename(object pathname)
}
#endif
- for (p = filename, q = 0; *p != '0円'; p++)
+ for (p = FN1, q = 0; *p != '0円'; p++)
if (*p == '/')
q = p;
- if (q == filename) {
+ if (q == FN1) {
q++;
p = "/";
} else if (q == 0) {
- q = filename;
- p = current_directory;
+ q = FN1;
+ p = FN3;
} else
#ifdef __MINGW32__
- if ( ( q > filename ) && ( q[-1] == ':' ) ) {
+ if ( ( q > FN1 ) && ( q[-1] == ':' ) ) {
int current = (q++, q[0]);
q[0]=0;
- if (chdir(filename) < 0)
+ if (chdir(FN1) < 0)
FEerror("Cannot get the truename of ~S.", 1, pathname);
current_directory_length =
- GetCurrentDirectory ( MAXPATHLEN, directory );
+ GetCurrentDirectory ( MAXPATHLEN, FN4 );
if ( MAXPATHLEN < current_directory_length ) {
FEerror ( "truename got a current directory name larger than MAXPATHLEN", 1, "" );
}
if ( 0 == current_directory_length ) {
FEerror ( "truename could not determine the current directory.", 1, "" );
}
- p = directory;
+ p = FN4;
if ( p[1]==':' && ( p[2]=='\\' || p[2]=='/' ) && p[3]==0 ) p[2]=0;
q[0]=current;
}
@@ -313,41 +303,41 @@ truename(object pathname)
#endif
{
*q++ = '0円';
- if (chdir(filename) < 0)
+ if (chdir(FN1) < 0)
FEerror("Cannot get the truename of ~S.", 1, pathname);
#ifdef __MINGW32__
- current_directory_length = GetCurrentDirectory ( MAXPATHLEN, directory );
+ current_directory_length = GetCurrentDirectory ( MAXPATHLEN, FN4 );
if ( MAXPATHLEN < current_directory_length ) {
FEerror ( "truename got a current directory name larger than MAXPATHLEN", 1, "" );
}
if ( 0 == current_directory_length ) {
FEerror ( "truename could not determine the current directory.", 1, "" );
}
- p = directory;
+ p = FN4;
#else
- p = getcwd(directory,sizeof(directory));
+ p = getcwd(FN4,sizeof(FN4));
#endif
}
if (p[0] == '/' && p[1] == '0円') {
if (strcmp(q, "..") == 0)
- strcpy(truefilename, "/.");
+ strcpy(FN2, "/.");
else
- sprintf(truefilename, "/%s", q);
+ sprintf(FN2, "/%s", q);
} else if (strcmp(q, ".") == 0)
- strcpy(truefilename, p);
+ strcpy(FN2, p);
else if (strcmp(q, "..") == 0) {
for (q = p + strlen(p); *--q != '/';) ;
if (p == q)
- strcpy(truefilename, "/.");
+ strcpy(FN2, "/.");
else {
*q = '0円';
- strcpy(truefilename, p);
+ strcpy(FN2, p);
*q = '/';
}
} else
- sprintf(truefilename, "%s/%s", p, q);
- massert(!chdir(current_directory));
- vs_push(make_simple_string(truefilename));
+ sprintf(FN2, "%s/%s", p, q);
+ massert(!chdir(FN3));
+ vs_push(make_simple_string(FN2));
pathname = coerce_to_pathname(vs_head);
vs_popp;
return(pathname);
@@ -357,27 +347,26 @@ object sSAallow_gzipped_fileA;
bool
file_exists(object file)
{
- char filename[MAXPATHLEN];
struct stat filestatus;
- coerce_to_filename(file, filename);
+ coerce_to_filename(file, FN1);
#ifdef __MINGW32__
{
char *p;
- for (p = filename; *p != '0円'; p++);
- if ( (p > filename) &&
+ for (p = FN1; *p != '0円'; p++);
+ if ( (p > FN1) &&
( ( *(p-1) == '/' ) || ( *(p-1) == '\\' ) ) ) {
*(p-1) = '0円';
}
}
#endif
- if (stat(filename, &filestatus) >= 0 && !S_ISDIR(filestatus.st_mode))
+ if (stat(FN1, &filestatus) >= 0 && !S_ISDIR(filestatus.st_mode))
{
#ifdef AIX
/* if /tmp/foo is not a directory /tmp/foo/ should not exist */
- if (filename[strlen(filename)-1] == '/' &&
+ if (FN1[strlen(FN1)-1] == '/' &&
!( filestatus.st_mode & S_IFDIR))
return(FALSE);
#endif
@@ -386,8 +375,8 @@ file_exists(object file)
}
else
if (sSAallow_gzipped_fileA->s.s_dbind != sLnil
- && (strcat(filename,".gz"),
- stat(filename, &filestatus) >= 0 && !S_ISDIR(filestatus.st_mode)))
+ && (strcat(FN1,".gz"),
+ stat(FN1, &filestatus) >= 0 && !S_ISDIR(filestatus.st_mode)))
return TRUE;
@@ -410,13 +399,13 @@ fopen_not_dir(char *filename,char * option) {
FILE *
backup_fopen(char *filename, char *option)
{
- char backupfilename[MAXPATHLEN];
- char command[MAXPATHLEN * 2];
+ char *command;
- strcat(strcpy(backupfilename, filename), ".BAK");
- sprintf(command, "mv %s %s", filename, backupfilename);
- msystem(command);
- return(fopen(filename, option));
+ strcat(strcpy(FN2, filename), ".BAK");
+ massert(command=alloca(6+strlen(filename)+strlen(FN2)));
+ sprintf(command, "mv %s %s", filename, FN2);
+ msystem(command);
+ return(fopen(filename, option));
}
int
@@ -438,23 +427,20 @@ LFD(Ltruename)(void)
LFD(Lrename_file)(void)
{
- char filename[MAXPATHLEN];
- char newfilename[MAXPATHLEN];
-
check_arg(2);
check_type_or_pathname_string_symbol_stream(&vs_base[0]);
check_type_or_Pathname_string_symbol(&vs_base[1]);
- coerce_to_filename(vs_base[0], filename);
+ coerce_to_filename(vs_base[0], FN1);
vs_base[0] = coerce_to_pathname(vs_base[0]);
vs_base[1] = coerce_to_pathname(vs_base[1]);
vs_base[1] = merge_pathnames(vs_base[1], vs_base[0], Cnil);
- coerce_to_filename(vs_base[1], newfilename);
+ coerce_to_filename(vs_base[1], FN2);
#ifdef HAVE_RENAME
- if (rename(filename, newfilename) < 0)
+ if (rename(FN1, FN2) < 0)
FEerror("Cannot rename the file ~S to ~S.",
2, vs_base[0], vs_base[1]);
#else
- sprintf(command, "mv %s %s", filename, newfilename);
+ sprintf(command, "mv %s %s", FN1, FN2);
msystem(command);
#endif
vs_push(vs_base[1]);
@@ -555,12 +541,10 @@ DEFUNO_NEW("DELETE-FILE",object,fLdelete_file,LISP
,1,1,NONE,OO,OO,OO,OO,void,Ldelete_file,(object path),"")
{
- char filename[MAXPATHLEN];
-
/* 1 args */
check_type_or_pathname_string_symbol_stream(&path);
- coerce_to_filename(path, filename);
- if (unlink(filename) < 0 && rmdir(filename) < 0)
+ coerce_to_filename(path, FN1);
+ if (unlink(FN1) < 0 && rmdir(FN1) < 0)
FEerror("Cannot delete the file ~S: ~s.", 2, path, make_simple_string(strerror(errno)));
path = Ct;
RETURN1(path);
@@ -585,13 +569,12 @@ LFD(Lprobe_file)(void)
LFD(Lfile_write_date)(void)
{
- char filename[MAXPATHLEN];
struct stat filestatus;
check_arg(1);
check_type_or_pathname_string_symbol_stream(&vs_base[0]);
- coerce_to_filename(vs_base[0], filename);
- if (stat(filename, &filestatus) < 0 || S_ISDIR(filestatus.st_mode))
+ coerce_to_filename(vs_base[0], FN1);
+ if (stat(FN1, &filestatus) < 0 || S_ISDIR(filestatus.st_mode))
{ vs_base[0] = Cnil; return;}
vs_base[0] = unix_time_to_universal_time(filestatus.st_mtime);
}
@@ -599,7 +582,6 @@ LFD(Lfile_write_date)(void)
LFD(Lfile_author)(void)
{
#if !defined(NO_PWD_H) && !defined(STATIC_LINKING)
- char filename[MAXPATHLEN];
struct stat filestatus;
struct passwd *pwent;
#ifndef __STDC__
@@ -608,8 +590,8 @@ LFD(Lfile_author)(void)
check_arg(1);
check_type_or_pathname_string_symbol_stream(&vs_base[0]);
- coerce_to_filename(vs_base[0], filename);
- if (stat(filename, &filestatus) < 0 || S_ISDIR(filestatus.st_mode))
+ coerce_to_filename(vs_base[0], FN1);
+ if (stat(FN1, &filestatus) < 0 || S_ISDIR(filestatus.st_mode))
{ vs_base[0] = Cnil; return;}
pwent = getpwuid(filestatus.st_uid);
vs_base[0] = make_simple_string(pwent->pw_name);
@@ -623,10 +605,8 @@ static void
FFN(Luser_homedir_pathname)(void)
{
- char filename[MAXPATHLEN];
-
- coerce_to_filename(make_simple_string("~/"),filename);
- vs_base[0]=coerce_to_pathname(make_simple_string(filename));
+ coerce_to_filename(make_simple_string("~/"),FN1);
+ vs_base[0]=coerce_to_pathname(make_simple_string(FN1));
vs_top = vs_base+1;
}
@@ -635,8 +615,7 @@ FFN(Luser_homedir_pathname)(void)
#ifdef BSD
LFD(Ldirectory)(void)
{
- char filename[MAXPATHLEN];
- char command[MAXPATHLEN * 2];
+ char *command;
FILE *fp;
register int i, c;
object *top = vs_top;
@@ -648,18 +627,19 @@ LFD(Ldirectory)(void)
check_type_or_pathname_string_symbol_stream(&vs_base[0]);
vs_base[0] = coerce_to_pathname(vs_base[0]);
if (vs_base[0]->pn.pn_name==Cnil && vs_base[0]->pn.pn_type==Cnil) {
- coerce_to_filename(vs_base[0], filename);
- strcat(filename, "*");
+ coerce_to_filename(vs_base[0], FN1);
+ strcat(FN1, "*");
} else if (vs_base[0]->pn.pn_name==Cnil) {
vs_base[0]->pn.pn_name = sKwild;
- coerce_to_filename(vs_base[0], filename);
+ coerce_to_filename(vs_base[0], FN1);
vs_base[0]->pn.pn_name = Cnil;
} else if (vs_base[0]->pn.pn_type==Cnil) {
- coerce_to_filename(vs_base[0], filename);
- strcat(filename, "*");
+ coerce_to_filename(vs_base[0], FN1);
+ strcat(FN1, "*");
} else
- coerce_to_filename(vs_base[0], filename);
- sprintf(command, "ls -d %s 2> /dev/null", filename);
+ coerce_to_filename(vs_base[0], FN1);
+ massert(command=alloca(21+strlen(FN1)));
+ sprintf(command, "ls -d %s 2> /dev/null", FN1);
fp = popen(command, "r");
setbuf(fp, iobuffer);
for (;;) {
@@ -669,9 +649,9 @@ LFD(Ldirectory)(void)
else if (c == '\n')
break;
else
- filename[i] = c;
- filename[i] = '0円';
- vs_push(make_simple_string(filename));
+ FN1[i] = c;
+ FN1[i] = '0円';
+ vs_push(make_simple_string(FN1));
vs_head = truename(vs_head);
}
L:
@@ -688,7 +668,6 @@ L:
LFD(Ldirectory)()
{
object name, type;
- char filename[MAXPATHLEN];
FILE *fp;
object *top = vs_top;
char iobuffer[BUFSIZ];
@@ -703,30 +682,30 @@ LFD(Ldirectory)()
vs_push(vs_base[0]->pn.pn_type);
vs_base[0]->pn.pn_name = Cnil;
vs_base[0]->pn.pn_type = Cnil;
- coerce_to_filename(vs_base[0], filename);
+ coerce_to_filename(vs_base[0], FN1);
type = vs_base[0]->pn.pn_type = vs_pop;
name = vs_base[0]->pn.pn_name = vs_pop;
- i = strlen(filename);
- if (i > 1 && filename[i-1] == '/')
- filename[i-1] = '0円';
+ i = strlen(FN1);
+ if (i > 1 && FN1[i-1] == '/')
+ FN1[i-1] = '0円';
if (i == 0)
- strcpy(filename, ".");
- fp = fopen(filename, "r");
+ strcpy(FN1, ".");
+ fp = fopen(FN1, "r");
if (fp == NULL) {
- vs_push(make_simple_string(filename));
+ vs_push(make_simple_string(FN1));
FEerror("Can't open the directory ~S.", 1, vs_head);
}
setbuf(fp, iobuffer);
fread(&dir, sizeof(struct direct), 1, fp);
fread(&dir, sizeof(struct direct), 1, fp);
- filename[DIRSIZ] = '0円';
+ FN1[DIRSIZ] = '0円';
for (;;) {
if (fread(&dir, sizeof(struct direct), 1, fp) <=0)
break;
if (dir.d_ino == 0)
continue;
- strncpy(filename, dir.d_name, DIRSIZ);
- vs_push(make_simple_string(filename));
+ strncpy(FN1, dir.d_name, DIRSIZ);
+ vs_push(make_simple_string(FN1));
vs_head = coerce_to_pathname(vs_head);
if ((name == Cnil || name == sKwild ||
equal(name, vs_head->pn.pn_name)) &&
@@ -753,7 +732,6 @@ LFD(Ldirectory)()
LFD(Ldirectory)()
{
object name, type;
- char filename[MAXPATHLEN];
FILE *fp;
object *top = vs_top;
char iobuffer[BUFSIZ];
@@ -768,30 +746,30 @@ LFD(Ldirectory)()
vs_push(vs_base[0]->pn.pn_type);
vs_base[0]->pn.pn_name = Cnil;
vs_base[0]->pn.pn_type = Cnil;
- coerce_to_filename(vs_base[0], filename);
+ coerce_to_filename(vs_base[0], FN1);
type = vs_base[0]->pn.pn_type = vs_pop;
name = vs_base[0]->pn.pn_name = vs_pop;
- i = strlen(filename);
- if (i > 1 && filename[i-1] == '/')
- filename[i-1] = '0円';
+ i = strlen(FN1);
+ if (i > 1 && FN1[i-1] == '/')
+ FN1[i-1] = '0円';
if (i == 0)
- strcpy(filename, ".");
- fp = fopen(filename, "r");
+ strcpy(FN1, ".");
+ fp = fopen(FN1, "r");
if (fp == NULL) {
- vs_push(make_simple_string(filename));
+ vs_push(make_simple_string(FN1));
FEerror("Can't open the directory ~S.", 1, vs_head);
}
setbuf(fp, iobuffer);
fread(&dir, sizeof(struct direct), 1, fp);
fread(&dir, sizeof(struct direct), 1, fp);
- filename[DIRSIZ] = '0円';
+ FN1[DIRSIZ] = '0円';
for (;;) {
if (fread(&dir, sizeof(struct direct), 1, fp) <=0)
break;
if (dir.d_ino == 0)
continue;
- strncpy(filename, dir.d_name, DIRSIZ);
- vs_push(make_simple_string(filename));
+ strncpy(FN1, dir.d_name, DIRSIZ);
+ vs_push(make_simple_string(FN1));
vs_head = coerce_to_pathname(vs_head);
if ((name == Cnil || name == sKwild ||
equal(name, vs_head->pn.pn_name)) &&
@@ -816,11 +794,10 @@ LFD(Ldirectory)()
DEFUN_NEW("OPENDIR",object,fSopendir,SI,1,1,NONE,IO,OO,OO,OO,(object x),"") {
DIR *d;
- char filename[MAXPATHLEN];
check_type_string(&x);
- memcpy(filename,x->st.st_self,x->st.st_fillp);
- filename[x->st.st_fillp]=0;
- d=opendir(filename);
+ memcpy(FN1,x->st.st_self,x->st.st_fillp);
+ FN1[x->st.st_fillp]=0;
+ d=opendir(FN1);
return (object)d;
}
@@ -864,17 +841,15 @@ DEFUN_NEW("CLOSEDIR",object,fSclosedir,SI,1,1,NONE,OI,OO,OO,OO,(fixnum x),"") {
DEFUN_NEW("MKDIR",object,fSmkdir,SI,1,1,NONE,OO,OO,OO,OO,(object x),"") {
- char filename[MAXPATHLEN];
-
check_type_string(&x);
- memcpy(filename,x->st.st_self,x->st.st_fillp);
- filename[x->st.st_fillp]=0;
+ memcpy(FN1,x->st.st_self,x->st.st_fillp);
+ FN1[x->st.st_fillp]=0;
#ifdef __MINGW32__
- if (mkdir(filename) < 0)
+ if (mkdir(FN1) < 0)
#else
- if (mkdir(filename,01777) < 0)
+ if (mkdir(FN1,01777) < 0)
#endif
FEerror("Cannot make the directory ~S.", 1, vs_base[0]);
@@ -888,13 +863,11 @@ DEFUN_NEW("MKDIR",object,fSmkdir,SI,1,1,NONE,OO,OO,OO,OO,(object x),"") {
static void
FFN(siLchdir)(void)
{
- char filename[MAXPATHLEN];
-
check_arg(1);
check_type_or_pathname_string_symbol_stream(&vs_base[0]);
- coerce_to_filename(vs_base[0], filename);
+ coerce_to_filename(vs_base[0], FN1);
- if (chdir(filename) < 0)
+ if (chdir(FN1) < 0)
FEerror("Can't change the current directory to ~S.",
1, vs_base[0]);
}
generated by cgit v1.2.3 (git 2.46.0) at 2025年12月16日 19:42:05 +0000

AltStyle によって変換されたページ (->オリジナル) /