X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=doio.c;h=41f026fc9c1a6263725c28f01d8134a1a8dad0f5;hb=2afa90c7c9ac9df151aa202b4ababf02e63d1d9f;hp=495599cf67e3547c2e636305edb83fbd640b24d1;hpb=fafc274c285207343d70f4a0d51c29a2f492863a;p=p5sagit%2Fp5-mst-13.2.git diff --git a/doio.c b/doio.c index 495599c..41f026f 100644 --- a/doio.c +++ b/doio.c @@ -65,8 +65,8 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, { dVAR; register IO * const io = GvIOn(gv); - PerlIO *saveifp = Nullfp; - PerlIO *saveofp = Nullfp; + PerlIO *saveifp = NULL; + PerlIO *saveofp = NULL; int savefd = -1; char savetype = IoTYPE_CLOSED; int writing = 0; @@ -76,7 +76,7 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, bool was_fdopen = FALSE; bool in_raw = 0, in_crlf = 0, out_raw = 0, out_crlf = 0; char *type = NULL; - char mode[PERL_MODE_MAX]; /* stdio file mode ("r\0", "rb\0", "r+b\0" etc.) */ + char mode[PERL_MODE_MAX]; /* file mode ("r\0", "rb\0", "ab\0" etc.) */ SV *namesv; Zero(mode,sizeof(mode),char); @@ -125,7 +125,7 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, "Warning: unable to close filehandle %s properly.\n", GvENAME(gv)); } - IoOFP(io) = IoIFP(io) = Nullfp; + IoOFP(io) = IoIFP(io) = NULL; } if (as_raw) { @@ -179,7 +179,7 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, namesv = sv_2mortal(newSVpv(oname,0)); num_svs = 1; svp = &namesv; - type = Nullch; + type = NULL; fp = PerlIO_openn(aTHX_ type, mode, -1, rawmode, rawperm, NULL, num_svs, svp); } else { @@ -188,14 +188,14 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, STRLEN olen = len; char *tend; int dodup = 0; - PerlIO *that_fp = NULL; type = savepvn(oname, len); tend = type+len; SAVEFREEPV(type); /* Lose leading and trailing white space */ - for (; isSPACE(*type); type++) ; + while (isSPACE(*type)) + type++; while (tend > type && isSPACE(tend[-1])) *--tend = '\0'; @@ -234,7 +234,9 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, } type++; } - for (type++; isSPACE(*type); type++) ; + do { + type++; + } while (isSPACE(*type)); if (!num_svs) { name = type; len = tend-type; @@ -246,7 +248,7 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, errno = EPIPE; goto say_false; } - if ((*name == '-' && name[1] == '\0') || num_svs) + if (!(*name == '-' && name[1] == '\0') || num_svs) TAINT_ENV(); TAINT_PROPER("piped open"); if (!num_svs && name[len-1] == '|') { @@ -258,9 +260,9 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, writing = 1; #ifdef HAS_STRLCAT if (out_raw) - strlcat(mode, "b", PERL_MODE_MAX); + strlcat(mode, "b", PERL_MODE_MAX - 1); else if (out_crlf) - strlcat(mode, "t", PERL_MODE_MAX); + strlcat(mode, "t", PERL_MODE_MAX - 1); #else if (out_raw) strcat(mode, "b"); @@ -296,9 +298,9 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, #ifdef HAS_STRLCAT if (out_raw) - strlcat(mode, "b", PERL_MODE_MAX); + strlcat(mode, "b", PERL_MODE_MAX - 1); else if (out_crlf) - strlcat(mode, "t", PERL_MODE_MAX); + strlcat(mode, "t", PERL_MODE_MAX - 1); #else if (out_raw) strcat(mode, "b"); @@ -318,10 +320,12 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, fp = supplied_fp; } else { + PerlIO *that_fp = NULL; if (num_svs > 1) { Perl_croak(aTHX_ "More than one argument to '%c&' open",IoTYPE(io)); } - for (; isSPACE(*type); type++) ; + while (isSPACE(*type)) + type++; if (num_svs && (SvIOK(*svp) || (SvPOK(*svp) && looks_like_number(*svp)))) { fd = SvUV(*svp); num_svs = 0; @@ -335,8 +339,7 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, thatio = sv_2io(*svp); } else { - GV *thatgv; - thatgv = gv_fetchpvn_flags(type, tend - type, + GV * const thatgv = gv_fetchpvn_flags(type, tend - type, 0, SVt_PVIO); thatio = GvIO(thatgv); } @@ -381,7 +384,7 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, fd = -1; } if (!num_svs) - type = Nullch; + type = NULL; if (that_fp) { fp = PerlIO_fdupopen(aTHX_ that_fp, NULL, dodup); } @@ -398,7 +401,8 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, } } /* & */ else { - for (; isSPACE(*type); type++) ; + while (isSPACE(*type)) + type++; if (*type == IoTYPE_STD && (!type[1] || isSPACE(type[1]) || type[1] == ':')) { type++; fp = PerlIO_stdout(); @@ -412,7 +416,7 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, namesv = sv_2mortal(newSVpvn(type,tend - type)); num_svs = 1; svp = &namesv; - type = Nullch; + type = NULL; } fp = PerlIO_openn(aTHX_ type,mode,-1,0,0,NULL,num_svs,svp); } @@ -421,13 +425,15 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, goto unknown_open_mode; } /* IoTYPE_WRONLY */ else if (*type == IoTYPE_RDONLY) { - for (type++; isSPACE(*type); type++) ; + do { + type++; + } while (isSPACE(*type)); mode[0] = 'r'; #ifdef HAS_STRLCAT if (in_raw) - strlcat(mode, "b", PERL_MODE_MAX); + strlcat(mode, "b", PERL_MODE_MAX - 1); else if (in_crlf) - strlcat(mode, "t", PERL_MODE_MAX); + strlcat(mode, "t", PERL_MODE_MAX - 1); #else if (in_raw) strcat(mode, "b"); @@ -450,7 +456,7 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, namesv = sv_2mortal(newSVpvn(type,tend - type)); num_svs = 1; svp = &namesv; - type = Nullch; + type = NULL; } fp = PerlIO_openn(aTHX_ type,mode,-1,0,0,NULL,num_svs,svp); } @@ -486,9 +492,9 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, #ifdef HAS_STRLCAT if (in_raw) - strlcat(mode, "b", PERL_MODE_MAX); + strlcat(mode, "b", PERL_MODE_MAX - 1); else if (in_crlf) - strlcat(mode, "t", PERL_MODE_MAX); + strlcat(mode, "t", PERL_MODE_MAX - 1); #else if (in_raw) strcat(mode, "b"); @@ -504,7 +510,8 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, } IoTYPE(io) = IoTYPE_PIPE; if (num_svs) { - for (; isSPACE(*type); type++) ; + while (isSPACE(*type)) + type++; if (*type) { if (PerlIO_apply_layers(aTHX_ fp, mode, type) != 0) { goto say_false; @@ -523,9 +530,9 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, #ifdef HAS_STRLCAT if (in_raw) - strlcat(mode, "b", PERL_MODE_MAX); + strlcat(mode, "b", PERL_MODE_MAX - 1); else if (in_crlf) - strlcat(mode, "t", PERL_MODE_MAX); + strlcat(mode, "t", PERL_MODE_MAX - 1); #else if (in_raw) strcat(mode, "b"); @@ -542,7 +549,7 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, namesv = sv_2mortal(newSVpvn(type,tend - type)); num_svs = 1; svp = &namesv; - type = Nullch; + type = NULL; } fp = PerlIO_openn(aTHX_ type,mode,-1,0,0,NULL,num_svs,svp); } @@ -704,7 +711,7 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, *s = 'w'; if (!(IoOFP(io) = PerlIO_openn(aTHX_ type,s,fd,0,0,NULL,0,svp))) { PerlIO_close(fp); - IoIFP(io) = Nullfp; + IoIFP(io) = NULL; goto say_false; } } @@ -740,7 +747,8 @@ Perl_nextargv(pTHX_ register GV *gv) if (PL_inplace) { if (!PL_argvout_stack) PL_argvout_stack = newAV(); - av_push(PL_argvout_stack, SvREFCNT_inc(PL_defoutgv)); + assert(PL_defoutgv); + av_push(PL_argvout_stack, SvREFCNT_inc_simple_NN(PL_defoutgv)); } } if (PL_filemode & (S_ISUID|S_ISGID)) { @@ -755,7 +763,7 @@ Perl_nextargv(pTHX_ register GV *gv) PL_lastfd = -1; PL_filemode = 0; if (!GvAV(gv)) - return Nullfp; + return NULL; while (av_len(GvAV(gv)) >= 0) { STRLEN oldlen; sv = av_shift(GvAV(gv)); @@ -763,7 +771,7 @@ Perl_nextargv(pTHX_ register GV *gv) sv_setsv(GvSVn(gv),sv); SvSETMAGIC(GvSV(gv)); PL_oldname = SvPVx(GvSV(gv), oldlen); - if (do_open(gv,PL_oldname,oldlen,PL_inplace!=0,O_RDONLY,0,Nullfp)) { + if (do_open(gv,PL_oldname,oldlen,PL_inplace!=0,O_RDONLY,0,NULL)) { if (PL_inplace) { TAINT_PROPER("inplace open"); if (oldlen == 1 && *PL_oldname == '-') { @@ -825,7 +833,7 @@ Perl_nextargv(pTHX_ register GV *gv) if (ckWARN_d(WARN_INPLACE)) Perl_warner(aTHX_ packWARN(WARN_INPLACE), "Can't rename %s to %"SVf": %s, skipping file", - PL_oldname, sv, Strerror(errno) ); + PL_oldname, (void*)sv, Strerror(errno)); do_close(gv,FALSE); continue; } @@ -834,7 +842,7 @@ Perl_nextargv(pTHX_ register GV *gv) (void)PerlLIO_unlink(SvPVX_const(sv)); (void)PerlLIO_rename(PL_oldname,SvPVX_const(sv)); do_open(gv,(char*)SvPVX_const(sv),SvCUR(sv),PL_inplace!=0, - O_RDONLY,0,Nullfp); + O_RDONLY,0,NULL); #endif /* DOSISH */ #else (void)UNLINK(SvPVX_const(sv)); @@ -871,11 +879,11 @@ Perl_nextargv(pTHX_ register GV *gv) SETERRNO(0,0); /* in case sprintf set errno */ #ifdef VMS if (!do_open(PL_argvoutgv,(char*)SvPVX_const(sv),SvCUR(sv), - PL_inplace!=0,O_WRONLY|O_CREAT|O_TRUNC,0,Nullfp)) + PL_inplace!=0,O_WRONLY|O_CREAT|O_TRUNC,0,NULL)) #else if (!do_open(PL_argvoutgv,(char*)SvPVX_const(sv),SvCUR(sv), PL_inplace!=0,O_WRONLY|O_CREAT|OPEN_EXCL,0666, - Nullfp)) + NULL)) #endif { if (ckWARN_d(WARN_INPLACE)) @@ -930,14 +938,14 @@ Perl_nextargv(pTHX_ register GV *gv) if (io && (IoFLAGS(io) & IOf_ARGV) && PL_argvout_stack && AvFILLp(PL_argvout_stack) >= 0) { - GV *oldout = (GV*)av_pop(PL_argvout_stack); + GV * const oldout = (GV*)av_pop(PL_argvout_stack); setdefout(oldout); SvREFCNT_dec(oldout); - return Nullfp; + return NULL; } setdefout(gv_fetchpvs("STDOUT", GV_ADD|GV_NOTQUAL, SVt_PVIO)); } - return Nullfp; + return NULL; } /* explicit renamed to avoid C++ conflict -- kja */ @@ -1004,7 +1012,7 @@ Perl_io_close(pTHX_ IO *io, bool not_implicit) retval = (PerlIO_close(IoIFP(io)) != EOF && !prev_err); } } - IoOFP(io) = IoIFP(io) = Nullfp; + IoOFP(io) = IoIFP(io) = NULL; } else if (not_implicit) { SETERRNO(EBADF,SS_IVCHAN); @@ -1175,7 +1183,6 @@ my_chsize(int fd, Off_t length) /* code courtesy of William Kucharski */ #define HAS_CHSIZE - struct flock fl; Stat_t filebuf; if (PerlLIO_fstat(fd, &filebuf) < 0) @@ -1195,7 +1202,7 @@ my_chsize(int fd, Off_t length) } else { /* truncate length */ - + struct flock fl; fl.l_whence = 0; fl.l_len = 0; fl.l_start = length; @@ -1227,6 +1234,8 @@ Perl_do_print(pTHX_ register SV *sv, PerlIO *fp) dVAR; register const char *tmps; STRLEN len; + U8 *tmpbuf = NULL; + bool happy = TRUE; /* assuming fp is checked earlier */ if (!sv) @@ -1238,7 +1247,7 @@ Perl_do_print(pTHX_ register SV *sv, PerlIO *fp) return TRUE; case SVt_IV: if (SvIOK(sv)) { - SvGETMAGIC(sv); + assert(!SvGMAGICAL(sv)); if (SvIsUV(sv)) PerlIO_printf(fp, "%"UVuf, (UV)SvUVX(sv)); else @@ -1247,19 +1256,32 @@ Perl_do_print(pTHX_ register SV *sv, PerlIO *fp) } /* FALL THROUGH */ default: + /* Do this first to trigger any overloading. */ + tmps = SvPV_const(sv, len); if (PerlIO_isutf8(fp)) { - if (!SvUTF8(sv)) - sv_utf8_upgrade_flags(sv = sv_mortalcopy(sv), - SV_GMAGIC|SV_UTF8_NO_ENCODING); + if (!SvUTF8(sv)) { + /* We don't modify the original scalar. */ + tmpbuf = bytes_to_utf8((const U8*) tmps, &len); + tmps = (char *) tmpbuf; + } } else if (DO_UTF8(sv)) { - if (!sv_utf8_downgrade((sv = sv_mortalcopy(sv)), TRUE) - && ckWARN_d(WARN_UTF8)) - { - Perl_warner(aTHX_ packWARN(WARN_UTF8), "Wide character in print"); + STRLEN tmplen = len; + bool utf8 = TRUE; + U8 * const result = bytes_from_utf8((const U8*) tmps, &tmplen, &utf8); + if (!utf8) { + tmpbuf = result; + tmps = (char *) tmpbuf; + len = tmplen; + } + else { + assert((char *)result == tmps); + if (ckWARN_d(WARN_UTF8)) { + Perl_warner(aTHX_ packWARN(WARN_UTF8), + "Wide character in print"); + } } } - tmps = SvPV_const(sv, len); break; } /* To detect whether the process is about to overstep its @@ -1269,8 +1291,9 @@ Perl_do_print(pTHX_ register SV *sv, PerlIO *fp) * at which we would get EPERM. Note that when using buffered * io the write failure can be delayed until the flush/close. --jhi */ if (len && (PerlIO_write(fp,tmps,len) == 0)) - return FALSE; - return !PerlIO_error(fp); + happy = FALSE; + Safefree(tmpbuf); + return happy ? !PerlIO_error(fp) : FALSE; } I32 @@ -1297,7 +1320,7 @@ Perl_my_stat(pTHX) return PL_laststatval; if (ckWARN2(WARN_UNOPENED,WARN_CLOSED)) report_evil_fh(gv, io, PL_op->op_type); - PL_statgv = Nullgv; + PL_statgv = NULL; sv_setpvn(PL_statname,"", 0); return (PL_laststatval = -1); } @@ -1320,7 +1343,7 @@ Perl_my_stat(pTHX) } s = SvPV_const(sv, len); - PL_statgv = Nullgv; + PL_statgv = NULL; sv_setpvn(PL_statname, s, len); s = SvPVX_const(PL_statname); /* s now NUL-terminated */ PL_laststype = OP_STAT; @@ -1357,7 +1380,7 @@ Perl_my_lstat(pTHX) Perl_croak(aTHX_ no_prev_lstat); PL_laststype = OP_LSTAT; - PL_statgv = Nullgv; + PL_statgv = NULL; sv = POPs; PUTBACK; if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVGV && ckWARN(WARN_IO)) { @@ -1373,6 +1396,19 @@ Perl_my_lstat(pTHX) return PL_laststatval; } +static void +S_exec_failed(pTHX_ const char *cmd, int fd, int do_report) +{ + const int e = errno; + if (ckWARN(WARN_EXEC)) + Perl_warner(aTHX_ packWARN(WARN_EXEC), "Can't exec \"%s\": %s", + cmd, Strerror(e)); + if (do_report) { + PerlLIO_write(fd, (void*)&e, sizeof(int)); + PerlLIO_close(fd); + } +} + bool Perl_do_aexec5(pTHX_ SV *really, register SV **mark, register SV **sp, int fd, int do_report) @@ -1405,15 +1441,7 @@ Perl_do_aexec5(pTHX_ SV *really, register SV **mark, register SV **sp, else PerlProc_execvp(PL_Argv[0],EXEC_ARGV_CAST(PL_Argv)); PERL_FPU_POST_EXEC - if (ckWARN(WARN_EXEC)) - Perl_warner(aTHX_ packWARN(WARN_EXEC), "Can't exec \"%s\": %s", - (really ? tmps : PL_Argv[0]), Strerror(errno)); - if (do_report) { - const int e = errno; - - PerlLIO_write(fd, (void*)&e, sizeof(int)); - PerlLIO_close(fd); - } + S_exec_failed(aTHX_ (really ? tmps : PL_Argv[0]), fd, do_report); } do_execfree(); #endif @@ -1425,9 +1453,9 @@ Perl_do_execfree(pTHX) { dVAR; Safefree(PL_Argv); - PL_Argv = Null(char **); + PL_Argv = NULL; Safefree(PL_Cmd); - PL_Cmd = Nullch; + PL_Cmd = NULL; } #ifdef PERL_DEFAULT_DO_EXEC3_IMPLEMENTATION @@ -1465,7 +1493,7 @@ Perl_do_exec3(pTHX_ const char *incmd, int fd, int do_report) if (*s == 'f') { s++; #ifdef HAS_STRLCPY - strlcat(flags, "f", PERL_FLAGS_MAX); + strlcat(flags, "f", PERL_FLAGS_MAX - 2); #else strcat(flags,"f"); #endif @@ -1482,9 +1510,10 @@ Perl_do_exec3(pTHX_ const char *incmd, int fd, int do_report) if (s[-1] == '\'') { *--s = '\0'; PERL_FPU_PRE_EXEC - PerlProc_execl(PL_cshname,"csh", flags, ncmd, (char*)0); + PerlProc_execl(PL_cshname, "csh", flags, ncmd, NULL); PERL_FPU_POST_EXEC *s = '\''; + S_exec_failed(aTHX_ PL_cshname, fd, do_report); Safefree(cmd); return FALSE; } @@ -1501,7 +1530,9 @@ Perl_do_exec3(pTHX_ const char *incmd, int fd, int do_report) if (strnEQ(cmd,"exec",4) && isSPACE(cmd[4])) goto doshell; - for (s = cmd; *s && isALNUM(*s); s++) ; /* catch VAR=val gizmo */ + s = cmd; + while (isALNUM(*s)) + s++; /* catch VAR=val gizmo */ if (*s == '=') goto doshell; @@ -1528,8 +1559,9 @@ Perl_do_exec3(pTHX_ const char *incmd, int fd, int do_report) } doshell: PERL_FPU_PRE_EXEC - PerlProc_execl(PL_sh_path, "sh", "-c", cmd, (char*)0); + PerlProc_execl(PL_sh_path, "sh", "-c", cmd, NULL); PERL_FPU_POST_EXEC + S_exec_failed(aTHX_ PL_sh_path, fd, do_report); Safefree(cmd); return FALSE; } @@ -1539,10 +1571,12 @@ Perl_do_exec3(pTHX_ const char *incmd, int fd, int do_report) PL_Cmd = savepvn(cmd, s-cmd); a = PL_Argv; for (s = PL_Cmd; *s;) { - while (*s && isSPACE(*s)) s++; + while (isSPACE(*s)) + s++; if (*s) *(a++) = s; - while (*s && !isSPACE(*s)) s++; + while (*s && !isSPACE(*s)) + s++; if (*s) *s++ = '\0'; } @@ -1555,14 +1589,7 @@ Perl_do_exec3(pTHX_ const char *incmd, int fd, int do_report) do_execfree(); goto doshell; } - if (ckWARN(WARN_EXEC)) - Perl_warner(aTHX_ packWARN(WARN_EXEC), "Can't exec \"%s\": %s", - PL_Argv[0], Strerror(errno)); - if (do_report) { - const int e = errno; - PerlLIO_write(fd, (const void*)&e, sizeof(int)); - PerlLIO_close(fd); - } + S_exec_failed(aTHX_ PL_Argv[0], fd, do_report); } do_execfree(); Safefree(cmd); @@ -1974,7 +2001,8 @@ Perl_do_ipcget(pTHX_ I32 optype, SV **mark, SV **sp) const key_t key = (key_t)SvNVx(*++mark); const I32 n = (optype == OP_MSGGET) ? 0 : SvIVx(*++mark); const I32 flags = SvIVx(*++mark); - (void)sp; + + PERL_UNUSED_ARG(sp); SETERRNO(0,0); switch (optype) @@ -2006,7 +2034,9 @@ Perl_do_ipcctl(pTHX_ I32 optype, SV **mark, SV **sp) char *a; I32 ret = -1; const I32 id = SvIVx(*++mark); +#ifdef Semctl const I32 n = (optype == OP_SEMCTL) ? SvIVx(*++mark) : 0; +#endif const I32 cmd = SvIVx(*++mark); SV * const astr = *++mark; STRLEN infosize = 0; @@ -2250,11 +2280,11 @@ Perl_do_shmio(pTHX_ I32 optype, SV **mark, SV **sp) SETERRNO(0,0); if (shmctl(id, IPC_STAT, &shmds) == -1) return -1; - if (mpos < 0 || msize < 0 || mpos + msize > shmds.shm_segsz) { + if (mpos < 0 || msize < 0 || (size_t)mpos + msize > shmds.shm_segsz) { SETERRNO(EFAULT,SS_ACCVIO); /* can't do as caller requested */ return -1; } - shm = (char *)shmat(id, (char*)NULL, (optype == OP_SHMREAD) ? SHM_RDONLY : 0); + shm = (char *)shmat(id, NULL, (optype == OP_SHMREAD) ? SHM_RDONLY : 0); if (shm == (char *)-1) /* I hate System V IPC, I really do */ return -1; if (optype == OP_SHMREAD) { @@ -2263,7 +2293,7 @@ Perl_do_shmio(pTHX_ I32 optype, SV **mark, SV **sp) if (! SvOK(mstr)) sv_setpvn(mstr, "", 0); SvPV_force_nolen(mstr); - mbuf = SvGROW(mstr, msize+1); + mbuf = SvGROW(mstr, (STRLEN)msize+1); Copy(shm + mpos, mbuf, msize, char); SvCUR_set(mstr, msize); @@ -2275,12 +2305,10 @@ Perl_do_shmio(pTHX_ I32 optype, SV **mark, SV **sp) #endif } else { - I32 n; STRLEN len; const char *mbuf = SvPV_const(mstr, len); - if ((n = len) > msize) - n = msize; + const I32 n = (len > msize) ? msize : len; Copy(mbuf, shm + mpos, n, char); if (n < msize) memzero(shm + mpos + n, msize - n); @@ -2316,89 +2344,14 @@ Perl_start_glob (pTHX_ SV *tmpglob, IO *io) SAVEFREESV(tmpcmd); #ifdef VMS /* expand the wildcards right here, rather than opening a pipe, */ /* since spawning off a process is a real performance hit */ - { -#include -#include -#include -#include - char rslt[NAM$C_MAXRSS+1+sizeof(unsigned short int)] = {'\0','\0'}; - char vmsspec[NAM$C_MAXRSS+1]; - char * const rstr = rslt + sizeof(unsigned short int); - char *begin, *end, *cp; - $DESCRIPTOR(dfltdsc,"SYS$DISK:[]*.*;"); - PerlIO *tmpfp; - STRLEN i; - struct dsc$descriptor_s wilddsc - = {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0}; - struct dsc$descriptor_vs rsdsc - = {sizeof rslt, DSC$K_DTYPE_VT, DSC$K_CLASS_VS, rslt}; - unsigned long int cxt = 0, sts = 0, ok = 1, hasdir = 0, hasver = 0, isunix = 0; - - /* We could find out if there's an explicit dev/dir or version - by peeking into lib$find_file's internal context at - ((struct NAM *)((struct FAB *)cxt)->fab$l_nam)->nam$l_fnb - but that's unsupported, so I don't want to do it now and - have it bite someone in the future. */ - cp = SvPV(tmpglob,i); - for (; i; i--) { - if (cp[i] == ';') hasver = 1; - if (cp[i] == '.') { - if (sts) hasver = 1; - else sts = 1; - } - if (cp[i] == '/') { - hasdir = isunix = 1; - break; - } - if (cp[i] == ']' || cp[i] == '>' || cp[i] == ':') { - hasdir = 1; - break; - } - } - if ((tmpfp = PerlIO_tmpfile()) != NULL) { - Stat_t st; - if (!PerlLIO_stat(SvPVX_const(tmpglob),&st) && S_ISDIR(st.st_mode)) - ok = ((wilddsc.dsc$a_pointer = tovmspath(SvPVX(tmpglob),vmsspec)) != NULL); - else ok = ((wilddsc.dsc$a_pointer = tovmsspec(SvPVX(tmpglob),vmsspec)) != NULL); - if (ok) wilddsc.dsc$w_length = (unsigned short int) strlen(wilddsc.dsc$a_pointer); - for (cp=wilddsc.dsc$a_pointer; ok && cp && *cp; cp++) - if (*cp == '?') *cp = '%'; /* VMS style single-char wildcard */ - while (ok && ((sts = lib$find_file(&wilddsc,&rsdsc,&cxt, - &dfltdsc,NULL,NULL,NULL))&1)) { - /* with varying string, 1st word of buffer contains result length */ - end = rstr + *((unsigned short int*)rslt); - if (!hasver) while (*end != ';' && end > rstr) end--; - *(end++) = '\n'; *end = '\0'; - for (cp = rstr; *cp; cp++) *cp = _tolower(*cp); - if (hasdir) { - if (isunix) trim_unixpath(rstr,SvPVX(tmpglob),1); - begin = rstr; - } - else { - begin = end; - while (*(--begin) != ']' && *begin != '>') ; - ++begin; - } - ok = (PerlIO_puts(tmpfp,begin) != EOF); - } - if (cxt) (void)lib$find_file_end(&cxt); - if (ok && sts != RMS$_NMF && - sts != RMS$_DNF && sts != RMS_FNF) ok = 0; - if (!ok) { - if (!(sts & 1)) { - SETERRNO((sts == RMS$_SYN ? EINVAL : EVMSERR),sts); - } - PerlIO_close(tmpfp); - fp = NULL; - } - else { - PerlIO_rewind(tmpfp); - IoTYPE(io) = IoTYPE_RDONLY; - IoIFP(io) = fp = tmpfp; - IoFLAGS(io) &= ~IOf_UNTAINT; /* maybe redundant */ - } - } - } + +PerlIO * +Perl_vms_start_glob + (pTHX_ SV *tmpglob, + IO *io); + + fp = Perl_vms_start_glob(aTHX_ tmpglob, io); + #else /* !VMS */ #ifdef MACOS_TRADITIONAL sv_setpv(tmpcmd, "glob "); @@ -2438,7 +2391,7 @@ Perl_start_glob (pTHX_ SV *tmpglob, IO *io) #endif /* !DOSISH */ #endif /* MACOS_TRADITIONAL */ (void)do_open(PL_last_in_gv, (char*)SvPVX_const(tmpcmd), SvCUR(tmpcmd), - FALSE, O_RDONLY, 0, Nullfp); + FALSE, O_RDONLY, 0, NULL); fp = IoIFP(io); #endif /* !VMS */ LEAVE;