S_openn_setup(pTHX_ GV *gv, char *mode, PerlIO **saveifp, PerlIO **saveofp,
int *savefd, char *savetype)
{
- dVAR;
IO * const io = GvIOn(gv);
PERL_ARGS_ASSERT_OPENN_SETUP;
Perl_do_open_raw(pTHX_ GV *gv, const char *oname, STRLEN len,
int rawmode, int rawperm)
{
- dVAR;
PerlIO *saveifp;
PerlIO *saveofp;
int savefd;
Perl_do_open6(pTHX_ GV *gv, const char *oname, STRLEN len,
PerlIO *supplied_fp, SV **svp, U32 num_svs)
{
- dVAR;
PerlIO *saveifp;
PerlIO *saveofp;
int savefd;
else {
PerlIO *that_fp = NULL;
int wanted_fd;
+ UV uv;
if (num_svs > 1) {
/* diag_listed_as: More than one argument to '%s' open */
Perl_croak(aTHX_ "More than one argument to '%c&' open",IoTYPE(io));
wanted_fd = SvUV(*svp);
num_svs = 0;
}
- else if (isDIGIT(*type)) {
- wanted_fd = atoi(type);
+ else if (isDIGIT(*type)
+ && grok_atoUV(type, &uv, NULL)
+ && uv <= INT_MAX
+ ) {
+ wanted_fd = (int)uv;
}
else {
const IO* thatio;
*s = 'w';
if (!(IoOFP(io) = PerlIO_openn(aTHX_ type,s,fd,0,0,NULL,0,NULL))) {
PerlIO_close(fp);
- IoIFP(io) = NULL;
goto say_false;
}
}
}
return TRUE;
-say_false:
+ say_false:
IoIFP(io) = saveifp;
IoOFP(io) = saveofp;
IoTYPE(io) = savetype;
}
PerlIO *
-Perl_nextargv(pTHX_ GV *gv)
+Perl_nextargv(pTHX_ GV *gv, bool nomagicopen)
{
- dVAR;
IO * const io = GvIOp(gv);
PERL_ARGS_ASSERT_NEXTARGV;
if (!PL_argvoutgv)
PL_argvoutgv = gv_fetchpvs("ARGVOUT", GV_ADD|GV_NOTQUAL, SVt_PVIO);
- if (io && (IoFLAGS(io) & IOf_ARGV) && (IoFLAGS(io) & IOf_START)) {
+ if (io && (IoFLAGS(io) & (IOf_ARGV|IOf_START)) == (IOf_ARGV|IOf_START)) {
IoFLAGS(io) &= ~IOf_START;
if (PL_inplace) {
assert(PL_defoutgv);
SvSETMAGIC(GvSV(gv));
PL_oldname = SvPVx(GvSV(gv), oldlen);
if (LIKELY(!PL_inplace)) {
- if (do_open6(gv, PL_oldname, oldlen, NULL, NULL, 0)) {
+ if (nomagicopen
+ ? do_open6(gv, "<", 1, NULL, &GvSV(gv), 1)
+ : do_open6(gv, PL_oldname, oldlen, NULL, NULL, 0)
+ ) {
return IoIFP(GvIOp(gv));
}
}
bool
Perl_do_close(pTHX_ GV *gv, bool not_implicit)
{
- dVAR;
bool retval;
IO *io;
}
return FALSE;
}
- retval = io_close(io, not_implicit);
+ retval = io_close(io, NULL, not_implicit, FALSE);
if (not_implicit) {
IoLINES(io) = 0;
IoPAGE(io) = 0;
}
bool
-Perl_io_close(pTHX_ IO *io, bool not_implicit)
+Perl_io_close(pTHX_ IO *io, GV *gv, bool not_implicit, bool warn_on_fail)
{
- dVAR;
bool retval = FALSE;
PERL_ARGS_ASSERT_IO_CLOSE;
else {
if (IoOFP(io) && IoOFP(io) != IoIFP(io)) { /* a socket */
const bool prev_err = PerlIO_error(IoOFP(io));
+#ifdef USE_PERLIO
+ if (prev_err)
+ PerlIO_restore_errno(IoOFP(io));
+#endif
retval = (PerlIO_close(IoOFP(io)) != EOF && !prev_err);
PerlIO_close(IoIFP(io)); /* clear stdio, fd already closed */
}
else {
const bool prev_err = PerlIO_error(IoIFP(io));
+#ifdef USE_PERLIO
+ if (prev_err)
+ PerlIO_restore_errno(IoIFP(io));
+#endif
retval = (PerlIO_close(IoIFP(io)) != EOF && !prev_err);
}
}
IoOFP(io) = IoIFP(io) = NULL;
+
+ if (warn_on_fail && !retval) {
+ if (gv)
+ Perl_ck_warner_d(aTHX_ packWARN(WARN_IO),
+ "Warning: unable to close filehandle %"
+ HEKf" properly: %"SVf,
+ GvNAME_HEK(gv), get_sv("!",GV_ADD));
+ else
+ Perl_ck_warner_d(aTHX_ packWARN(WARN_IO),
+ "Warning: unable to close filehandle "
+ "properly: %"SVf,
+ get_sv("!",GV_ADD));
+ }
}
else if (not_implicit) {
SETERRNO(EBADF,SS_IVCHAN);
bool
Perl_do_eof(pTHX_ GV *gv)
{
- dVAR;
IO * const io = GvIO(gv);
PERL_ARGS_ASSERT_DO_EOF;
PerlIO_set_cnt(IoIFP(io),-1);
}
if (PL_op->op_flags & OPf_SPECIAL) { /* not necessarily a real EOF yet? */
- if (gv != PL_argvgv || !nextargv(gv)) /* get another fp handy */
+ if (gv != PL_argvgv || !nextargv(gv, FALSE)) /* get another fp handy */
return TRUE;
}
else
Off_t
Perl_do_tell(pTHX_ GV *gv)
{
- dVAR;
IO *const io = GvIO(gv);
PerlIO *fp;
bool
Perl_do_seek(pTHX_ GV *gv, Off_t pos, int whence)
{
- dVAR;
IO *const io = GvIO(gv);
PerlIO *fp;
Off_t
Perl_do_sysseek(pTHX_ GV *gv, Off_t pos, int whence)
{
- dVAR;
IO *const io = GvIO(gv);
PerlIO *fp;
}
else {
const char *end;
-fail_discipline:
+ fail_discipline:
end = strchr(s+1, ':');
if (!end)
end = s+len;
bool
Perl_do_print(pTHX_ SV *sv, PerlIO *fp)
{
- dVAR;
-
PERL_ARGS_ASSERT_DO_PRINT;
/* assuming fp is checked earlier */
I32
Perl_my_stat_flags(pTHX_ const U32 flags)
{
- dVAR;
dSP;
IO *io;
GV* gv;
I32
Perl_my_lstat_flags(pTHX_ const U32 flags)
{
- dVAR;
static const char* const no_prev_lstat = "The stat preceding -l _ wasn't an lstat";
dSP;
const char *file;
void
Perl_do_execfree(pTHX)
{
- dVAR;
Safefree(PL_Argv);
PL_Argv = NULL;
Safefree(PL_Cmd);
I32
Perl_apply(pTHX_ I32 type, SV **mark, SV **sp)
{
- dVAR;
I32 val;
I32 tot = 0;
const char *const what = PL_op_name[type];
#endif
}
else {
+ SETERRNO(EBADF,RMS_IFI);
tot--;
}
}
#endif
}
else {
+ SETERRNO(EBADF,RMS_IFI);
tot--;
}
}
* is in the list of groups returned from getgroups().
*/
{
- dVAR;
-
PERL_ARGS_ASSERT_CANDO;
PERL_UNUSED_CONTEXT;
static bool
S_ingroup(pTHX_ Gid_t testgid, bool effective)
{
- dVAR;
#ifndef PERL_IMPLICIT_SYS
/* PERL_IMPLICIT_SYS like Win32: getegid() etc. require the context. */
PERL_UNUSED_CONTEXT;
I32
Perl_do_ipcget(pTHX_ I32 optype, SV **mark, SV **sp)
{
- dVAR;
const key_t key = (key_t)SvNVx(*++mark);
SV *nsv = optype == OP_MSGGET ? NULL : *++mark;
const I32 flags = SvIVx(*++mark);
I32
Perl_do_ipcctl(pTHX_ I32 optype, SV **mark, SV **sp)
{
- dVAR;
char *a;
I32 ret = -1;
const I32 id = SvIVx(*++mark);
I32
Perl_do_msgsnd(pTHX_ SV **mark, SV **sp)
{
- dVAR;
#ifdef HAS_MSG
STRLEN len;
const I32 id = SvIVx(*++mark);
Perl_do_msgrcv(pTHX_ SV **mark, SV **sp)
{
#ifdef HAS_MSG
- dVAR;
char *mbuf;
long mtype;
I32 msize, flags, ret;
Perl_do_semop(pTHX_ SV **mark, SV **sp)
{
#ifdef HAS_SEM
- dVAR;
STRLEN opsize;
const I32 id = SvIVx(*++mark);
SV * const opstr = *++mark;
Perl_do_shmio(pTHX_ I32 optype, SV **mark, SV **sp)
{
#ifdef HAS_SHM
- dVAR;
char *shm;
struct shmid_ds shmds;
const I32 id = SvIVx(*++mark);
PerlIO *
Perl_start_glob (pTHX_ SV *tmpglob, IO *io)
{
- dVAR;
SV * const tmpcmd = newSV(0);
PerlIO *fp;
STRLEN len;
}
/*
- * Local variables:
- * c-indentation-style: bsd
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- *
* ex: set ts=8 sts=4 sw=4 et:
*/