PerlIO_openn is called from do_openn, with narg being the number of scalar arguments (3rd arg for Perl open) and args being the scalar values. You'll see that no matter what, if the args are undef, it returns the PerlIO_tmpfile. There is no check for mode here, because that was done in the previous function, do_openn (which is defined as Perl_do_openn)PerlIO * PerlIO_openn(pTHX_ const char *layers, const char *mode, int fd, int imode, int perm, PerlIO *old, int narg, SV **args) { if (narg) { if (narg > 1) { Perl_croak(aTHX_ "More than one argument to open"); } if (*args == &PL_sv_undef) return PerlIO_tmpfile(); else { char *name = SvPV_nolen(*args); if (*mode == IoTYPE_NUMERIC) { fd = PerlLIO_open3(name, imode, perm); if (fd >= 0) return PerlIO_fdopen(fd, (char *) mode + 1); } else if (old) { return PerlIO_reopen(name, mode, old); } else { return PerlIO_open(name, mode); } } } else { return PerlIO_fdopen(fd, (char *) mode); } return NULL; }
Here is the check for the leading '+' (IoTYPE_RDWR). It is the ONLY check in this function and just sets the writing flag and moves the pointer on the "type" up by one.... if ((*type == IoTYPE_RDWR) && /* scary */ (*(type+1) == IoTYPE_RDONLY || *(type+1) == IoTYPE_WRONLY) && ((!num_svs || (tend > type+1 && tend[-1] != IoTYPE_PIPE)))) { TAINT_PROPER("open"); mode[1] = *type++; writing = 1; }
so far so good.. unless we're doing a <& or <- we can skip this if logic.else if (*type == IoTYPE_RDONLY) { /*SUPPRESS 530*/ for (type++; isSPACE(*type); type++) ; mode[0] = 'r'; #ifdef HAS_STRLCAT if (in_raw) strlcat(mode, "b", PERL_MODE_MAX); else if (in_crlf) strlcat(mode, "t", PERL_MODE_MAX); #else if (in_raw) strcat(mode, "b"); else if (in_crlf) strcat(mode, "t"); #endif if (*type == '&') { goto duplicity; } if (*type == IoTYPE_STD && (!type[1] || isSPACE(type[1]) | +| type[1] == ':')) {
Well, as we can see, regardless of the original num_svs, there is going to be a value of at least 1 passed to the above PerlIO_openn. Even if svp is undef, it goes and opens a temp file.... else { if (!num_svs) { namesv = sv_2mortal(newSVpvn(type,strlen(type))); num_svs = 1; svp = &namesv; type = Nullch; } fp = PerlIO_openn(aTHX_ type,mode,-1,0,0,NULL,num_svs, +svp); }
Since we have a valid fp (PerlIO_tmpfile), we're in the clear.if (!fp && type && *type && *type != ':' && !isIDFIRST(*ty +pe)) goto unknown_open_mode; }
In reply to Re: 3-arg open() does not give warnings!?
by Transient
in thread 3-arg open() does not give warnings!?
by graff
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |