In message <[EMAIL PROTECTED]> 
in the vmsperl web archive at:

 http://www.xray.mpe.mpg.de/mailing-lists/vmsperl/2000-04/msg00127.html

Charles Lane wrote:

> I'm using DECC 5.5-003 on an Alpha and also have the "trailing
> slash" problem.  So rather than version/architecture testing, I suggest
> we just strip 'em all and not worry about it further.
> 
> Patch follows:

I encountered trouble with GNU patch 2.5 and a freshly 
untarred perl 5.6.0 kit:

 % patch -p0 < chdir_lane.txt
 patching file `iperlsys.h'
 Hunk #1 FAILED at 551.
 1 out of 1 hunk FAILED -- saving rejects to iperlsys.h.rej
 patching file `vms/vms.c'
 Hunk #1 succeeded at 911 with fuzz 2 (offset -4 lines).
 patching file `vms/vmsish.h'
 Hunk #1 FAILED at 109.
 Hunk #3 FAILED at 640.
 2 out of 3 hunks FAILED -- saving rejects to vms/vmsish.h.rej
 Exit 1

Nevertheless I think that I managed to recover everything then 
test on a VAX with the bad C RTL chdir() and there I see that
this patch does indeed fix the problem that a previous 
perl version (namely 5.005_02) had:

 % perl -e "chdir('/221006$DIA6/PERL-5_6_0/lib/');print $],`sho def`"
 5.00502  221006$DIA6:[PERL-5_6_0]
 % @perl_setup
 %DCL-I-SUPERSEDE, previous value of PERL_ROOT has been superseded
 %DCL-I-SUPERSEDE, previous value of PERLSHR has been superseded
 % perl -e "chdir('/221006$DIA6/PERL-5_6_0/lib/');print $],`sho def`"
 5.006  221006$DIA6:[PERL-5_6_0.LIB]

(where the latter result is correct).

The following re-work of Charles Lanes' original applied well with:

 % patch -p1 < chdir_lane.patch
 patching file `iperlsys.h'
 patching file `vms/vms.c'
 patching file `vms/vmsish.h'

Here is Charles Lanes' handiwork in a simple recast, please give credit to
Charles Lane for this work:

diff -ru perl-5.6.0.orig/iperlsys.h perl-5.6.0/iperlsys.h
--- perl-5.6.0.orig/iperlsys.h  Sun Mar  5 22:32:03 2000
+++ perl-5.6.0/iperlsys.h       Fri May  5 17:40:07 2000
@@ -551,7 +551,7 @@
 
 #define PerlDir_mkdir(name, mode)      Mkdir((name), (mode))
 #ifdef VMS
-#  define PerlDir_chdir(n)             chdir(((n) && *(n)) ? (n) : "SYS$LOGIN")
+#  define PerlDir_chdir(n)             Chdir(((n) && *(n)) ? (n) : "SYS$LOGIN")
 #else 
 #  define PerlDir_chdir(name)          chdir((name))
 #endif
diff -ru perl-5.6.0.orig/vms/vms.c perl-5.6.0/vms/vms.c
--- perl-5.6.0.orig/vms/vms.c   Tue Mar 14 13:20:15 2000
+++ perl-5.6.0/vms/vms.c        Fri May  5 17:42:45 2000
@@ -911,6 +911,30 @@
 }  /* end of my_mkdir */
 /*}}}*/
 
+/*{{{int my_chdir(char *)*/
+int
+my_chdir(char *dir)
+{
+  STRLEN dirlen = strlen(dir);
+  dTHX;
+
+  /* zero length string sometimes gives ACCVIO */
+  if (dirlen == 0) return -1;
+
+  /* some versions of CRTL chdir() doesn't tolerate trailing /, since
+   * that implies
+   * null file name/type.  However, it's commonplace under Unix,
+   * so we'll allow it for a gain in portability.
+   */
+  if (dir[dirlen-1] == '/') {
+    char *newdir = savepvn(dir,dirlen-1);
+    int ret = chdir(newdir);
+    Safefree(newdir);
+    return ret;
+  }
+  else return chdir(dir);
+}  /* end of my_chdir */
+/*}}}*/
 
 static void
 create_mbx(unsigned short int *chan, struct dsc$descriptor_s *namdsc)
diff -ru perl-5.6.0.orig/vms/vmsish.h perl-5.6.0/vms/vmsish.h
--- perl-5.6.0.orig/vms/vmsish.h        Sat Mar 18 21:45:33 2000
+++ perl-5.6.0/vms/vmsish.h     Fri May  5 17:46:09 2000
@@ -109,6 +109,7 @@
 #define do_rmdir               Perl_do_rmdir
 #define kill_file              Perl_kill_file
 #define my_mkdir               Perl_my_mkdir
+#define my_chdir               Perl_my_chdir
 #define my_utime               Perl_my_utime
 #define rmsexpand      Perl_rmsexpand
 #define rmsexpand_ts   Perl_rmsexpand_ts
@@ -447,8 +448,9 @@
 /* Ditto for sys$hash_passwrod() . . . */
 #define crypt  my_crypt
 
-/* Tweak arg to mkdir first, so we can tolerate trailing /. */
+/* Tweak arg to mkdir & chdir first, so we can tolerate trailing /. */
 #define Mkdir(dir,mode) my_mkdir((dir),(mode))
+#define Chdir(dir) my_chdir((dir))
 
 /* Use our own stat() clones, which handle Unix-style directory names */
 #define Stat(name,bufptr) flex_stat(name,bufptr)
@@ -638,6 +640,7 @@
 int    do_rmdir (char *);
 int    kill_file (char *);
 int    my_mkdir (char *, Mode_t);
+int    my_chdir (char *);
 int    my_utime (char *, struct utimbuf *);
 char * rmsexpand (char *, char *, char *, unsigned);
 char * rmsexpand_ts (char *, char *, char *, unsigned);
End of Patch.

Peter Prymmer

Reply via email to