if (IoIFP(io)) {
fd = PerlIO_fileno(IoIFP(io));
- if (IoTYPE(io) == '-')
+ if (IoTYPE(io) == IoTYPE_STD)
result = 0;
else if (fd <= PL_maxsysfd) {
saveifp = IoIFP(io);
savetype = IoTYPE(io);
result = 0;
}
- else if (IoTYPE(io) == '|')
+ else if (IoTYPE(io) == IoTYPE_PIPE)
result = PerlProc_pclose(IoIFP(io));
else if (IoIFP(io) != IoOFP(io)) {
if (IoOFP(io)) {
switch (result = rawmode & O_ACCMODE) {
case O_RDONLY:
- IoTYPE(io) = '<';
+ IoTYPE(io) = IoTYPE_RDONLY;
break;
case O_WRONLY:
- IoTYPE(io) = '>';
+ IoTYPE(io) = IoTYPE_WRONLY;
break;
case O_RDWR:
default:
- IoTYPE(io) = '+';
+ IoTYPE(io) = IoTYPE_RDWR;
break;
}
TAINT_PROPER("open");
type++;
if (*type == '>') {
- mode[0] = IoTYPE(io) = 'a';
+ mode[0] = IoTYPE(io) = IoTYPE_APPEND;
type++;
tlen--;
}
* fsetpos(src)+fgetpos(dst)? --nik */
PerlIO_flush(fp);
fd = PerlIO_fileno(fp);
- if (IoTYPE(thatio) == 's')
- IoTYPE(io) = 's';
+ if (IoTYPE(thatio) == IoTYPE_SOCKET)
+ IoTYPE(io) = IoTYPE_SOCKET;
}
else
fd = -1;
for (; isSPACE(*type); type++) ;
if (strEQ(type,"-")) {
fp = PerlIO_stdout();
- IoTYPE(io) = '-';
+ IoTYPE(io) = IoTYPE_STD;
}
else {
fp = PerlIO_open((num_svs ? name : type), mode);
}
if (strEQ(type,"-")) {
fp = PerlIO_stdin();
- IoTYPE(io) = '-';
+ IoTYPE(io) = IoTYPE_STD;
}
else
fp = PerlIO_open((num_svs ? name : type), mode);
mode = "r";
fp = PerlProc_popen(name,mode);
}
- IoTYPE(io) = '|';
+ IoTYPE(io) = IoTYPE_PIPE;
}
else {
if (num_svs)
goto unknown_desr;
name = type;
- IoTYPE(io) = '<';
+ IoTYPE(io) = IoTYPE_RDONLY;
/*SUPPRESS 530*/
for (; isSPACE(*name); name++) ;
if (strEQ(name,"-")) {
fp = PerlIO_stdin();
- IoTYPE(io) = '-';
+ IoTYPE(io) = IoTYPE_STD;
}
else {
char *mode;
}
if (!fp) {
dTHR;
- if (ckWARN(WARN_NEWLINE) && IoTYPE(io) == '<' && strchr(name, '\n'))
+ if (ckWARN(WARN_NEWLINE) && IoTYPE(io) == IoTYPE_RDONLY && strchr(name, '\n'))
Perl_warner(aTHX_ WARN_NEWLINE, PL_warn_nl, "open");
goto say_false;
}
if (IoTYPE(io) &&
- IoTYPE(io) != '|' && IoTYPE(io) != '-') {
+ IoTYPE(io) != IoTYPE_PIPE && IoTYPE(io) != IoTYPE_STD) {
dTHR;
if (PerlLIO_fstat(PerlIO_fileno(fp),&PL_statbuf) < 0) {
(void)PerlIO_close(fp);
goto say_false;
}
if (S_ISSOCK(PL_statbuf.st_mode))
- IoTYPE(io) = 's'; /* in case a socket was passed in to us */
+ IoTYPE(io) = IoTYPE_SOCKET; /* in case a socket was passed in to us */
#ifdef HAS_SOCKET
else if (
#ifdef S_IFMT
if (PerlSock_getsockname(PerlIO_fileno(fp), (struct sockaddr *)tmpbuf,
&buflen) >= 0
|| errno != ENOTSOCK)
- IoTYPE(io) = 's'; /* some OS's return 0 on fstat()ed socket */
+ IoTYPE(io) = IoTYPE_SOCKET; /* some OS's return 0 on fstat()ed socket */
/* but some return 0 for streams too, sigh */
}
#endif
IoFLAGS(io) &= ~IOf_NOLINE;
if (writing) {
dTHR;
- if (IoTYPE(io) == 's'
- || (IoTYPE(io) == '>' && S_ISCHR(PL_statbuf.st_mode)) )
+ if (IoTYPE(io) == IoTYPE_SOCKET
+ || (IoTYPE(io) == IoTYPE_WRONLY && S_ISCHR(PL_statbuf.st_mode)) )
{
char *mode;
if (out_raw)
IoIFP(rstio) = PerlIO_fdopen(fd[0], "r");
IoOFP(wstio) = PerlIO_fdopen(fd[1], "w");
IoIFP(wstio) = IoOFP(wstio);
- IoTYPE(rstio) = '<';
- IoTYPE(wstio) = '>';
+ IoTYPE(rstio) = IoTYPE_RDONLY;
+ IoTYPE(wstio) = IoTYPE_WRONLY;
if (!IoIFP(rstio) || !IoOFP(wstio)) {
if (IoIFP(rstio)) PerlIO_close(IoIFP(rstio));
else PerlLIO_close(fd[0]);
IoPAGE(io) = 0;
IoLINES_LEFT(io) = IoPAGE_LEN(io);
}
- IoTYPE(io) = ' ';
+ IoTYPE(io) = IoTYPE_CLOSED;
return retval;
}
int status;
if (IoIFP(io)) {
- if (IoTYPE(io) == '|') {
+ if (IoTYPE(io) == IoTYPE_PIPE) {
status = PerlProc_pclose(IoIFP(io));
if (not_implicit) {
STATUS_NATIVE_SET(status);
retval = (status != -1);
}
}
- else if (IoTYPE(io) == '-')
+ else if (IoTYPE(io) == IoTYPE_STD)
retval = TRUE;
else {
if (IoOFP(io) && IoOFP(io) != IoIFP(io)) { /* a socket */
if (!io)
return TRUE;
else if (ckWARN(WARN_IO)
- && (IoTYPE(io) == '>' || IoIFP(io) == PerlIO_stdout()
+ && (IoTYPE(io) == IoTYPE_WRONLY || IoIFP(io) == PerlIO_stdout()
|| IoIFP(io) == PerlIO_stderr()))
{
/* integrate to report_evil_fh()? */
if (io) {
tryrsfp = IoIFP(io);
- if (IoTYPE(io) == '|') {
+ if (IoTYPE(io) == IoTYPE_PIPE) {
/* reading from a child process doesn't
nest -- when returning from reading
the inner module, the outer one is
IoIFP(rstio) = PerlIO_fdopen(fd[0], "r");
IoOFP(wstio) = PerlIO_fdopen(fd[1], "w");
IoIFP(wstio) = IoOFP(wstio);
- IoTYPE(rstio) = '<';
- IoTYPE(wstio) = '>';
+ IoTYPE(rstio) = IoTYPE_RDONLY;
+ IoTYPE(wstio) = IoTYPE_WRONLY;
if (!IoIFP(rstio) || !IoOFP(wstio)) {
if (IoIFP(rstio)) PerlIO_close(IoIFP(rstio));
}
if (PL_op->op_type == OP_SYSREAD) {
#ifdef PERL_SOCK_SYSREAD_IS_RECV
- if (IoTYPE(io) == 's') {
+ if (IoTYPE(io) == IoTYPE_SOCKET) {
length = PerlSock_recv(PerlIO_fileno(IoIFP(io)),
buffer+offset, length, 0);
}
}
else
#ifdef HAS_SOCKET__bad_code_maybe
- if (IoTYPE(io) == 's') {
+ if (IoTYPE(io) == IoTYPE_SOCKET) {
char namebuf[MAXPATHLEN];
#if defined(VMS_DO_SOCKETS) && defined(DECCRTL_SOCKETS)
bufsize = sizeof (struct sockaddr_in);
length = -1;
}
if (length < 0) {
- if ((IoTYPE(io) == '>' || IoIFP(io) == PerlIO_stdout()
+ if ((IoTYPE(io) == IoTYPE_WRONLY || IoIFP(io) == PerlIO_stdout()
|| IoIFP(io) == PerlIO_stderr()) && ckWARN(WARN_IO))
{
/* integrate with report_evil_fh()? */
if (length > blen - offset)
length = blen - offset;
#ifdef PERL_SOCK_SYSWRITE_IS_SEND
- if (IoTYPE(io) == 's') {
+ if (IoTYPE(io) == IoTYPE_SOCKET) {
retval = PerlSock_send(PerlIO_fileno(IoIFP(io)),
buffer+offset, length, 0);
}
RETPUSHUNDEF;
IoIFP(io) = PerlIO_fdopen(fd, "r"); /* stdio gets confused about sockets */
IoOFP(io) = PerlIO_fdopen(fd, "w");
- IoTYPE(io) = 's';
+ IoTYPE(io) = IoTYPE_SOCKET;
if (!IoIFP(io) || !IoOFP(io)) {
if (IoIFP(io)) PerlIO_close(IoIFP(io));
if (IoOFP(io)) PerlIO_close(IoOFP(io));
RETPUSHUNDEF;
IoIFP(io1) = PerlIO_fdopen(fd[0], "r");
IoOFP(io1) = PerlIO_fdopen(fd[0], "w");
- IoTYPE(io1) = 's';
+ IoTYPE(io1) = IoTYPE_SOCKET;
IoIFP(io2) = PerlIO_fdopen(fd[1], "r");
IoOFP(io2) = PerlIO_fdopen(fd[1], "w");
- IoTYPE(io2) = 's';
+ IoTYPE(io2) = IoTYPE_SOCKET;
if (!IoIFP(io1) || !IoOFP(io1) || !IoIFP(io2) || !IoOFP(io2)) {
if (IoIFP(io1)) PerlIO_close(IoIFP(io1));
if (IoOFP(io1)) PerlIO_close(IoOFP(io1));
goto badexit;
IoIFP(nstio) = PerlIO_fdopen(fd, "r");
IoOFP(nstio) = PerlIO_fdopen(fd, "w");
- IoTYPE(nstio) = 's';
+ IoTYPE(nstio) = IoTYPE_SOCKET;
if (!IoIFP(nstio) || !IoOFP(nstio)) {
if (IoIFP(nstio)) PerlIO_close(IoIFP(nstio));
if (IoOFP(nstio)) PerlIO_close(IoOFP(nstio));
#define IoTYPE(sv) ((XPVIO*) SvANY(sv))->xio_type
#define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags
-/*
-IoTYPE(sv) is a single character saying what type of I/O connection
-this is:
- | pipe
- - stdin or stdout
- < read-only
- > write-only
- a append
- + read and write
- s socket
- space closed
-*/
+/* IoTYPE(sv) is a single character telling the type of I/O connection. */
+#define IoTYPE_RDONLY '<'
+#define IoTYPE_WRONLY '>'
+#define IoTYPE_RDWR '+'
+#define IoTYPE_APPEND 'a'
+#define IoTYPE_PIPE '|'
+#define IoTYPE_STD '-' /* stdin or stdout */
+#define IoTYPE_SOCKET 's'
+#define IoTYPE_CLOSED ' '
/*
=for apidoc Am|bool|SvTAINTED|SV* sv
/* Mark this internal pseudo-handle as clean */
IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
if (PL_preprocess)
- IoTYPE(GvIOp(gv)) = '|';
+ IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
- IoTYPE(GvIOp(gv)) = '-';
+ IoTYPE(GvIOp(gv)) = IoTYPE_STD;
else
- IoTYPE(GvIOp(gv)) = '<';
+ IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
#if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
/* if the script was opened in binmode, we need to revert
* it to text mode for compatibility; but only iff it has CRs
&& PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
{
Off_t loc = 0;
- if (IoTYPE(GvIOp(gv)) == '<') {
+ if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
loc = PerlIO_tell(PL_rsfp);
(void)PerlIO_seek(PL_rsfp, 0L, 0);
}
op == OP_LEAVEWRITE ? "write" :
PL_op_desc[op];
char *pars = OP_IS_FILETEST(op) ? "" : "()";
- char *type = OP_IS_SOCKET(op) || (io && IoTYPE(io) == 's') ?
+ char *type = OP_IS_SOCKET(op) || (io && IoTYPE(io) == IoTYPE_SOCKET) ?
"socket" : "filehandle";
char *name = NULL;
name = SvPVX(sv);
}
- if (io && IoTYPE(io) == ' ') {
+ if (io && IoTYPE(io) == IoTYPE_CLOSED) {
vile = "closed";
warn = WARN_CLOSED;
}