supplied_fp, &svs, 1);
}
-static char *S_layers(pTHX_ char *mode);
-
-static char *
-S_layers(pTHX_ char *mode)
-{
- char *type = NULL;
- /* Need to supply default layer info from open.pm */
- SV *layers = PL_curcop->cop_io;
- if (layers) {
- STRLEN len;
- type = SvPV(layers,len);
- if (type && mode[0] != 'r') {
- /* Skip to write part */
- char *s = strchr(type,0);
- if (s && (s-type) < len) {
- type = s+1;
- }
- }
- }
- return type;
-}
-
bool
Perl_do_openn(pTHX_ GV *gv, register char *name, I32 len, int as_raw,
int rawmode, int rawperm, PerlIO *supplied_fp, SV **svp,
namesv = sv_2mortal(newSVpvn(name,strlen(name)));
num_svs = 1;
svp = &namesv;
- fp = PerlIO_openn(aTHX_ S_layers(aTHX_ mode),mode, -1, rawmode, rawperm, saveifp, num_svs, svp);
+ type = Nullch;
+ fp = PerlIO_openn(aTHX_ type,mode, -1, rawmode, rawperm, NULL, num_svs, svp);
}
else {
/* Regular (non-sys) open */
*tend-- = '\0';
if (num_svs) {
/* New style explict name, type is just mode and discipline/layer info */
- STRLEN l;
- name = SvPV(*svp, l) ;
+ STRLEN l = 0;
+ name = SvOK(*svp) ? SvPV(*svp, l) : "";
len = (I32)l;
name = savepvn(name, len);
SAVEFREEPV(name);
else
was_fdopen = TRUE;
if (!num_svs)
- type = S_layers(aTHX_ mode);
+ type = Nullch;
if (!(fp = PerlIO_openn(aTHX_ type,mode,fd,0,0,NULL,num_svs,svp))) {
if (dodup)
PerlLIO_close(fd);
namesv = sv_2mortal(newSVpvn(type,strlen(type)));
num_svs = 1;
svp = &namesv;
- type = S_layers(aTHX_ mode);
+ type = Nullch;
}
- fp = PerlIO_openn(aTHX_ type,mode,-1,0,0,saveifp,num_svs,svp);
+ fp = PerlIO_openn(aTHX_ type,mode,-1,0,0,NULL,num_svs,svp);
}
} /* !& */
}
namesv = sv_2mortal(newSVpvn(type,strlen(type)));
num_svs = 1;
svp = &namesv;
- type = S_layers(aTHX_ mode);
+ type = Nullch;
}
- fp = PerlIO_openn(aTHX_ type,mode,-1,0,0,saveifp,num_svs,svp);
+ fp = PerlIO_openn(aTHX_ type,mode,-1,0,0,NULL,num_svs,svp);
}
}
else if ((num_svs && type[0] == IoTYPE_STD && type[1] == IoTYPE_PIPE) ||
namesv = sv_2mortal(newSVpvn(type,strlen(type)));
num_svs = 1;
svp = &namesv;
- type = S_layers(aTHX_ mode);
+ type = Nullch;
}
- fp = PerlIO_openn(aTHX_ type,mode,-1,0,0,saveifp,num_svs,svp);
+ fp = PerlIO_openn(aTHX_ type,mode,-1,0,0,NULL,num_svs,svp);
}
}
}
if (ckWARN(WARN_IO)) {
if ((IoTYPE(io) == IoTYPE_RDONLY) &&
(fp == PerlIO_stdout() || fp == PerlIO_stderr())) {
- Perl_warner(aTHX_ WARN_IO, "'std%s' opened only for input",
- (fp == PerlIO_stdout()) ? "out" : "err");
+ Perl_warner(aTHX_ WARN_IO,
+ "Filehandle STD%s opened only for input",
+ (fp == PerlIO_stdout()) ? "OUT" : "ERR");
}
else if ((IoTYPE(io) == IoTYPE_WRONLY) && fp == PerlIO_stdin()) {
- Perl_warner(aTHX_ WARN_IO, "'stdin' opened only for output");
+ Perl_warner(aTHX_ WARN_IO,
+ "Filehandle STDIN opened only for output");
}
}
- if (IoTYPE(io) && IoTYPE(io) != IoTYPE_PIPE && IoTYPE(io) != IoTYPE_STD) {
+ if (IoTYPE(io) && IoTYPE(io) != IoTYPE_PIPE && IoTYPE(io) != IoTYPE_STD &&
+ /* FIXME: This next term is a hack to avoid fileno on PerlIO::Scalar */
+ !(num_svs && SvROK(*svp))) {
if (PerlLIO_fstat(PerlIO_fileno(fp),&PL_statbuf) < 0) {
(void)PerlIO_close(fp);
goto say_false;
/* If fd is less that PL_maxsysfd i.e. STDIN..STDERR
then dup the new fileno down
*/
+ fd = PerlIO_fileno(fp);
if (saveofp) {
PerlIO_flush(saveofp); /* emulate PerlIO_close() */
if (saveofp != saveifp) { /* was a socket? */
PerlIO_close(saveofp);
}
}
- if (savefd != PerlIO_fileno(fp)) {
+ if (savefd != fd) {
Pid_t pid;
SV *sv;
-
- PerlLIO_dup2(PerlIO_fileno(fp), fd);
+ if (PerlLIO_dup2(fd, savefd) < 0) {
+ (void)PerlIO_close(fp);
+ goto say_false;
+ }
#ifdef VMS
- if (fd != PerlIO_fileno(PerlIO_stdin())) {
+ if (savefd != PerlIO_fileno(PerlIO_stdin())) {
char newname[FILENAME_MAX+1];
if (fgetname(fp, newname)) {
- if (fd == PerlIO_fileno(PerlIO_stdout())) Perl_vmssetuserlnm("SYS$OUTPUT", newname);
- if (fd == PerlIO_fileno(PerlIO_stderr())) Perl_vmssetuserlnm("SYS$ERROR", newname);
+ if (savefd == PerlIO_fileno(PerlIO_stdout())) Perl_vmssetuserlnm("SYS$OUTPUT", newname);
+ if (savefd == PerlIO_fileno(PerlIO_stderr())) Perl_vmssetuserlnm("SYS$ERROR", newname);
}
}
#endif
LOCK_FDPID_MUTEX;
- sv = *av_fetch(PL_fdpid,PerlIO_fileno(fp),TRUE);
+ sv = *av_fetch(PL_fdpid,fd,TRUE);
(void)SvUPGRADE(sv, SVt_IV);
pid = SvIVX(sv);
SvIVX(sv) = 0;
- sv = *av_fetch(PL_fdpid,fd,TRUE);
+ sv = *av_fetch(PL_fdpid,savefd,TRUE);
UNLOCK_FDPID_MUTEX;
(void)SvUPGRADE(sv, SVt_IV);
SvIVX(sv) = pid;
if (IoTYPE(io) == IoTYPE_SOCKET
|| (IoTYPE(io) == IoTYPE_WRONLY && S_ISCHR(PL_statbuf.st_mode)) ) {
mode[0] = 'w';
- if (!(IoOFP(io) = PerlIO_openn(aTHX_ S_layers(aTHX_ mode),mode,PerlIO_fileno(fp),0,0,saveofp,num_svs,svp))) {
+ if (!(IoOFP(io) = PerlIO_openn(aTHX_ type,mode,PerlIO_fileno(fp),0,0,NULL,num_svs,svp))) {
PerlIO_close(fp);
IoIFP(io) = Nullfp;
goto say_false;
if (!SvUTF8(sv))
sv_utf8_upgrade(sv = sv_mortalcopy(sv));
}
- else if (DO_UTF8(sv))
- sv_utf8_downgrade((sv = sv_mortalcopy(sv)), FALSE);
+ else if (DO_UTF8(sv)) {
+ if (!sv_utf8_downgrade((sv = sv_mortalcopy(sv)), TRUE)) {
+ Perl_warner(aTHX_ WARN_UTF8, "Wide character in print");
+ }
+ }
tmps = SvPV(sv, len);
break;
}