In perl_clone_using(), turn off AvREAL() on param->stashes.
[p5sagit/p5-mst-13.2.git] / vms / vms.c
index 7d208ba..60f01e3 100644 (file)
--- a/vms/vms.c
+++ b/vms/vms.c
@@ -219,6 +219,17 @@ return 0;
 #  define RTL_USES_UTC 1
 #endif
 
+#if !defined(__VAX) && __CRTL_VER >= 80200000
+#ifdef lstat
+#undef lstat
+#endif
+#else
+#ifdef lstat
+#undef lstat
+#endif
+#define lstat(_x, _y) stat(_x, _y)
+#endif
+
 /* Routine to create a decterm for use with the Perl debugger */
 /* No headers, this information was found in the Programming Concepts Manual */
 
@@ -1047,7 +1058,7 @@ Perl_vmstrnenv(const char *lnm, char *eqv, unsigned long int idx,
 #if defined(PERL_IMPLICIT_CONTEXT)
             if (aTHX == NULL) {
                 fprintf(stderr,
-                    "%%PERL-W-VMS_INIT Can't read CRTL environ\n");
+                    "Can't read CRTL environ\n");
             } else
 #endif
                 Perl_warn(aTHX_ "Can't read CRTL environ\n");
@@ -1087,7 +1098,7 @@ Perl_vmstrnenv(const char *lnm, char *eqv, unsigned long int idx,
 #if defined(PERL_IMPLICIT_CONTEXT)
               if (aTHX == NULL) {
                   fprintf(stderr,
-                     "%Perl-VMS-Init, Value of CLI symbol \"%s\" too long",lnm);
+                     "Value of CLI symbol \"%s\" too long",lnm);
               } else
 #endif
                if (ckWARN(WARN_MISC)) {
@@ -2874,7 +2885,11 @@ int test_unix_status;
 
 
 /* default piping mailbox size */
-#define PERL_BUFSIZ        512
+#ifdef __VAX
+#  define PERL_BUFSIZ        512
+#else
+#  define PERL_BUFSIZ        8192
+#endif
 
 
 static void
@@ -3062,7 +3077,10 @@ pipe_exit_routine()
 #if defined(USE_ITHREADS)
              && my_perl
 #endif
-             && PL_perlio_fd_refcnt) 
+#ifdef USE_PERLIO
+             && PL_perlio_fd_refcnt 
+#endif
+              )
                PerlIO_flush(info->fp);
            else 
                fflush((FILE *)info->fp);
@@ -4670,7 +4688,10 @@ static I32 my_pclose_pinfo(pTHX_ pInfo info) {
 #if defined(USE_ITHREADS)
           && my_perl
 #endif
-          && PL_perlio_fd_refcnt) 
+#ifdef USE_PERLIO
+          && PL_perlio_fd_refcnt 
+#endif
+           )
             PerlIO_flush(info->fp);
         else 
             fflush((FILE *)info->fp);
@@ -4697,7 +4718,10 @@ static I32 my_pclose_pinfo(pTHX_ pInfo info) {
 #if defined(USE_ITHREADS)
          && my_perl
 #endif
-         && PL_perlio_fd_refcnt) 
+#ifdef USE_PERLIO
+         && PL_perlio_fd_refcnt
+#endif
+        )
         PerlIO_close(info->fp);
      else 
         fclose((FILE *)info->fp);
@@ -5614,6 +5638,8 @@ int_rmsexpand
           if ((opts & PERL_RMSEXPAND_M_VMS) == 0)
 #if !defined(__VAX) && defined(NAML$C_MAXRSS)
               opts |= PERL_RMSEXPAND_M_LONG;
+#else
+              NOOP;
 #endif
           else
               isunix = 0;
@@ -5739,6 +5765,7 @@ int_expanded:
    /* Is a long or a short name expected */
   /*------------------------------------*/
   spec_buf = NULL;
+#if !defined(__VAX) && defined(NAML$C_MAXRSS)
   if ((opts & PERL_RMSEXPAND_M_LONG) != 0) {
     if (rms_nam_rsll(mynam)) {
        spec_buf = outbufl;
@@ -5750,6 +5777,7 @@ int_expanded:
     }
   }
   else {
+#endif
     if (rms_nam_rsl(mynam)) {
        spec_buf = outbuf;
        speclen = rms_nam_rsl(mynam);
@@ -5758,7 +5786,9 @@ int_expanded:
        spec_buf = esa; /* Not esal */
        speclen = rms_nam_esl(mynam);
     }
+#if !defined(__VAX) && defined(NAML$C_MAXRSS)
   }
+#endif
   spec_buf[speclen] = '\0';
 
   /* Trim off null fields added by $PARSE
@@ -6433,13 +6463,17 @@ int_fileify_dirspec(const char *dir, char *buf, int *utf8_fl)
       }
 
       /* Make sure we are using the right buffer */
+#if !defined(__VAX) && defined(NAML$C_MAXRSS)
       if (esal != NULL) {
        my_esa = esal;
        my_esa_len = rms_nam_esll(dirnam);
       } else {
+#endif
        my_esa = esa;
         my_esa_len = rms_nam_esl(dirnam);
+#if !defined(__VAX) && defined(NAML$C_MAXRSS)
       }
+#endif
       my_esa[my_esa_len] = '\0';
       if (!rms_is_nam_fnb(dirnam, (NAM$M_EXP_DEV | NAM$M_EXP_DIR))) {
         cp1 = strchr(my_esa,']');
@@ -7325,7 +7359,7 @@ static char *int_tounixspec(const char *spec, char *rslt, int * utf8_fl)
     }
     if (*cp2 == ':') {
       *(cp1++) = '/';
-      if (*(cp2+1) == '[') cp2++;
+      if (*(cp2+1) == '[' || *(cp2+1) == '<') cp2++;
     }
     else if (*cp2 == ']' || *cp2 == '>') {
       if (*(cp1-1) != '/') *(cp1++) = '/'; /* Don't double after ellipsis */
@@ -8210,7 +8244,7 @@ int sts, v_len, r_len, d_len, n_len, e_len, vs_len;
         * special device files.
          */
 
-       if ((add_6zero == 0) && (*nextslash == '/') &&
+       if (!islnm && (add_6zero == 0) && (*nextslash == '/') &&
            (&nextslash[1] == unixend)) {
          /* No real directory present */
          add_6zero = 1;
@@ -8470,7 +8504,7 @@ int sts, v_len, r_len, d_len, n_len, e_len, vs_len;
     vmsptr2 = vmsptr - 1;
     if ((vmslen > 1) &&
        (*vmsptr2 != ']') && (*vmsptr2 != '*') && (*vmsptr2 != '%') &&
-       (*vmsptr2 != ')') && (*lastdot != '.')) {
+       (*vmsptr2 != ')') && (*lastdot != '.') && (*vmsptr2 != ':')) {
        *vmsptr++ = '.';
         vmslen++;
     }
@@ -8656,7 +8690,7 @@ static char *int_tovmsspec
       }
   }
 
-/* If POSIX mode active, handle the conversion */
+/* If EFS charset mode active, handle the conversion */
 #if __CRTL_VER >= 80200000 && !defined(__VAX)
   if (decc_efs_charset) {
     posix_to_vmsspec_hardway(rslt, rslt_len, path, dir_flag, utf8_flag);
@@ -9397,7 +9431,7 @@ mp_getredirection(pTHX_ int *ac, char ***av)
        /* Input from a pipe, reopen it in binary mode to disable       */
        /* carriage control processing.                                 */
 
-       fgetname(stdin, mbxname);
+       fgetname(stdin, mbxname, 1);
        mbxnam.dsc$a_pointer = mbxname;
        mbxnam.dsc$w_length = strlen(mbxnam.dsc$a_pointer);     
        lib$getdvi(&dvi_item, 0, &mbxnam, &bufsize, 0, 0);
@@ -9775,6 +9809,7 @@ vms_image_init(int *argcp, char ***argvp)
     Perl_csighandler_init();
 #endif
 
+#if __CRTL_VER >= 70300000 && !defined(__VAX)
     /* This was moved from the pre-image init handler because on threaded */
     /* Perl it was always returning 0 for the default value. */
     status = simple_trnlnm("SYS$POSIX_ROOT", eqv, LNM$C_NAMLENGTH);
@@ -9804,7 +9839,7 @@ vms_image_init(int *argcp, char ***argvp)
            }
        }
     }
-
+#endif
 
   _ckvmssts_noperl(sys$getjpiw(0,NULL,NULL,jpilist,iosb,NULL,NULL));
   _ckvmssts_noperl(iosb[0]);
@@ -10451,18 +10486,14 @@ Perl_readdir(pTHX_ DIR *dd)
         /* In Unix report mode, remove the ".dir;1" from the name */
         /* if it is a real directory. */
         if (decc_filename_unix_report || decc_efs_charset) {
-            if ((e_len == 4) && (vs_len == 2) && (vs_spec[1] == '1')) {
-                if ((toupper(e_spec[1]) == 'D') &&
-                    (toupper(e_spec[2]) == 'I') &&
-                    (toupper(e_spec[3]) == 'R')) {
-                    Stat_t statbuf;
-                    int ret_sts;
-
-                    ret_sts = stat(buff, &statbuf.crtl_stat);
-                    if ((ret_sts == 0) && S_ISDIR(statbuf.st_mode)) {
-                        e_len = 0;
-                        e_spec[0] = 0;
-                    }
+            if (is_dir_ext(e_spec, e_len, vs_spec, vs_len)) {
+                Stat_t statbuf;
+                int ret_sts;
+
+                ret_sts = flex_lstat(buff, &statbuf);
+                if ((ret_sts == 0) && S_ISDIR(statbuf.st_mode)) {
+                    e_len = 0;
+                    e_spec[0] = 0;
                 }
             }
         }
@@ -11271,7 +11302,8 @@ int my_fclose(FILE *fp) {
 int
 my_fwrite(const void *src, size_t itmsz, size_t nitm, FILE *dest)
 {
-  register char *cp, *end, *cpd, *data;
+  register char *cp, *end, *cpd;
+  char *data;
   register unsigned int fd = fileno(dest);
   register unsigned int fdoff = fd / sizeof(unsigned int);
   int retval;
@@ -11328,6 +11360,34 @@ Perl_my_flush(pTHX_ FILE *fp)
 }
 /*}}}*/
 
+/* fgetname() is not returning the correct file specifications when
+ * decc_filename_unix_report mode is active.  So we have to have it
+ * aways return filenames in VMS mode and convert it ourselves.
+ */
+
+/*{{{ char * my_fgetname(FILE *fp, buf)*/
+char *
+Perl_my_fgetname(FILE *fp, char * buf) {
+    char * retname;
+    char * vms_name;
+
+    retname = fgetname(fp, buf, 1);
+
+    /* If we are in VMS mode, then we are done */
+    if (!decc_filename_unix_report || (retname == NULL)) {
+       return retname;
+    }
+
+    /* Convert this to Unix format */
+    vms_name = PerlMem_malloc(VMS_MAXRSS + 1);
+    strcpy(vms_name, retname);
+    retname = int_tounixspec(vms_name, buf, NULL);
+    PerlMem_free(vms_name);
+
+    return retname;
+}
+/*}}}*/
+
 /*
  * Here are replacements for the following Unix routines in the VMS environment:
  *      getpwuid    Get information for a particular UIC or UID
@@ -12754,17 +12814,6 @@ Perl_flex_fstat(pTHX_ int fd, Stat_t *statbufp)
 }  /* end of flex_fstat() */
 /*}}}*/
 
-#if !defined(__VAX) && __CRTL_VER >= 80200000
-#ifdef lstat
-#undef lstat
-#endif
-#else
-#ifdef lstat
-#undef lstat
-#endif
-#define lstat(_x, _y) stat(_x, _y)
-#endif
-
 static int
 Perl_flex_stat_int(pTHX_ const char *fspec, Stat_t *statbufp, int lstat_flag)
 {
@@ -13535,7 +13584,7 @@ rmscopy_fromperl(pTHX_ CV *cv)
   if (SvTYPE(mysv) == SVt_PVGV) {
     if (!(io = GvIOp(mysv)) || !PerlIO_getname(IoIFP(io),inspec)) {
       set_errno(EINVAL); set_vaxc_errno(LIB$_INVARG);
-      ST(0) = &PL_sv_no;
+      ST(0) = sv_2mortal(newSViv(0));
       Safefree(inspec);
       XSRETURN(1);
     }
@@ -13544,7 +13593,7 @@ rmscopy_fromperl(pTHX_ CV *cv)
   else {
     if (mysv != ST(0) || !(inp = SvPV(mysv,n_a)) || !*inp) {
       set_errno(EINVAL); set_vaxc_errno(LIB$_INVARG);
-      ST(0) = &PL_sv_no;
+      ST(0) = sv_2mortal(newSViv(0));
       Safefree(inspec);
       XSRETURN(1);
     }
@@ -13554,7 +13603,7 @@ rmscopy_fromperl(pTHX_ CV *cv)
   if (SvTYPE(mysv) == SVt_PVGV) {
     if (!(io = GvIOp(mysv)) || !PerlIO_getname(IoIFP(io),outspec)) {
       set_errno(EINVAL); set_vaxc_errno(LIB$_INVARG);
-      ST(0) = &PL_sv_no;
+      ST(0) = sv_2mortal(newSViv(0));
       Safefree(inspec);
       Safefree(outspec);
       XSRETURN(1);
@@ -13564,7 +13613,7 @@ rmscopy_fromperl(pTHX_ CV *cv)
   else {
     if (mysv != ST(1) || !(outp = SvPV(mysv,n_a)) || !*outp) {
       set_errno(EINVAL); set_vaxc_errno(LIB$_INVARG);
-      ST(0) = &PL_sv_no;
+      ST(0) = sv_2mortal(newSViv(0));
       Safefree(inspec);
       Safefree(outspec);
       XSRETURN(1);
@@ -13572,7 +13621,7 @@ rmscopy_fromperl(pTHX_ CV *cv)
   }
   date_flag = (items == 3) ? SvIV(ST(2)) : 0;
 
-  ST(0) = boolSV(rmscopy(inp,outp,date_flag));
+  ST(0) = sv_2mortal(newSViv(rmscopy(inp,outp,date_flag)));
   Safefree(inspec);
   Safefree(outspec);
   XSRETURN(1);
@@ -14331,6 +14380,20 @@ mp_do_vms_realpath(pTHX_ const char *filespec, char *outbuf,
                    int file_len = v_len + r_len + d_len + n_len + e_len;
                    vms_spec[file_len] = 0;
 
+                   /* Trim off the .DIR if this is a directory */
+                   if (is_dir_ext(e_spec, e_len, vs_spec, vs_len)) {
+                        if (S_ISDIR(my_mode)) {
+                            e_len = 0;
+                            e_spec[0] = 0;
+                        }
+                   }
+
+                   /* Drop NULL extensions on UNIX file specification */
+                   if ((e_len == 1) && decc_readdir_dropdotnotype) {
+                       e_len = 0;
+                       e_spec[0] = '\0';
+                   }
+
                    /* The result is expected to be in UNIX format */
                    rslt = int_tounixspec(vms_spec, outbuf, utf8_fl);