From: Nobuyoshi Nakada Date: 2008-04-24T13:26:27+09:00 Subject: Re: RFC: #19733 - dln_find_1 prioritizes posix naming conventions over Operating System naming conventions. Hi, At Thu, 24 Apr 2008 13:17:03 +0900, Nobuyoshi Nakada wrote in [ruby-core:16548]: > > Basically, this ticket [1] exposes a problem that annoys and add > > cross-platform inoperativeness to Ruby. It start with the assumption > > that an extensionless file have priority over a true windows > > executable (.exe, com, bat, cmd) and try to use it instead when issue > > system or any way that calls back into the OS. > > Do you consider files sans extensions shouldn't be returned? And, rather I want to remove static fbuf in dln.c. Index: dln.h =================================================================== --- dln.h (revision 16174) +++ dln.h (working copy) @@ -31,4 +31,6 @@ char *dln_find_exe(const char*,const char*); char *dln_find_file(const char*,const char*); +char *dln_find2_exe(const char*,const char*,char*,int); +char *dln_find2_file(const char*,const char*,char*,int); #ifdef USE_DLN_A_OUT Index: dln.c =================================================================== --- dln.c (revision 16174) +++ dln.c (working copy) @@ -1569,8 +1569,8 @@ dln_load(const char *file) } -static char *dln_find_1(const char *fname, const char *path, int exe_flag); +static char *dln_find_1(const char *fname, const char *path, char *buf, int size, int exe_flag); char * -dln_find_exe(const char *fname, const char *path) +dln_find_exe2(const char *fname, const char *path, char *buf, int size) { if (!path) { @@ -1585,16 +1585,16 @@ dln_find_exe(const char *fname, const ch #endif } - return dln_find_1(fname, path, 1); + return dln_find_1(fname, path, buf, size, 1); } char * -dln_find_file(const char *fname, const char *path) +dln_find_file2(const char *fname, const char *path, char *buf, int size) { #ifndef __MACOS__ if (!path) path = "."; - return dln_find_1(fname, path, 0); + return dln_find_1(fname, path, buf, size, 0); #else if (!path) path = "."; - return _macruby_path_conv_posix_to_macos(dln_find_1(fname, path, 0)); + return _macruby_path_conv_posix_to_macos(dln_find_1(fname, path, buf, size, 0)); #endif } @@ -1602,6 +1602,19 @@ dln_find_file(const char *fname, const c static char fbuf[MAXPATHLEN]; +char * +dln_find_exe(const char *fname, const char *path) +{ + return dln_find_exe2(fname, path, fbuf, sizeof(fbuf)); +} + +char * +dln_find_file(const char *fname, const char *path) +{ + return dln_find_file2(fname, path, fbuf, sizeof(fbuf)); +} + static char * -dln_find_1(const char *fname, const char *path, int exe_flag /* non 0 if looking for executable. */) +dln_find_1(const char *fname, const char *path, char *fbuf, int size, + int exe_flag /* non 0 if looking for executable. */) { register const char *dp; @@ -1643,5 +1656,5 @@ dln_find_1(const char *fname, const char l = ep - dp; bp = fbuf; - fspace = sizeof fbuf - 2; + fspace = size - 2; if (l > 0) { /* Index: file.c =================================================================== --- file.c (revision 16174) +++ file.c (working copy) @@ -4335,9 +4381,10 @@ rb_find_file_ext(VALUE *filep, const cha for (i=0;i()~&|\\$;'`\"\n",*s)) { - char *shell = dln_find_exe("sh", 0); + char *shell = dln_find_exe2("sh", 0, fbuf, sizeof(fbuf)); before_exec(); status = shell?spawnl(P_WAIT,shell,"sh","-c",str,(char*)NULL):system(str); @@ -949,6 +984,7 @@ process_options(VALUE arg) NODE *tree = 0; VALUE parser; rb_encoding *enc; const char *s; + char fbuf[MAXPATHLEN]; int i = proc_options(argc, argv, opt); @@ -1031,8 +1067,8 @@ process_options(VALUE arg) opt->script = 0; if (path) { - opt->script = dln_find_file(argv[0], path); + opt->script = dln_find_file2(argv[0], path, fbuf, sizeof(fbuf)); } if (!opt->script) { - opt->script = dln_find_file(argv[0], getenv(PATH_ENV)); + opt->script = dln_find_file(argv[0], getenv(PATH_ENV), fbuf, sizeof(fbuf)); } if (!opt->script) -- Nobu Nakada