summaryrefslogtreecommitdiff
path: root/doio.c
diff options
context:
space:
mode:
authorPerl 5 Porters <perl5-porters@africa.nicoh.com>1996-02-02 18:52:27 -0800
committerLarry Wall <lwall@sems.com>1996-02-02 18:52:27 -0800
commitc07a80fdfe3926b5eb0585b674aa5d1f57b32ade (patch)
tree6d56135571eb9ea6635748469bdaf72ad481247a /doio.c
parent91b7def858c29dac014df40946a128c06b3aa2ed (diff)
downloadperl-c07a80fdfe3926b5eb0585b674aa5d1f57b32ade.tar.gz
perl5.002beta3
[editor's note: no patch file was found for this release, so no fine-grained changes] I can't find the password for our ftp server, so I had to drop it into ftp://ftp.sems.com/pub/incoming/perl5.002b3.tar.gz, which is a drop directory you can't ls. The current plan is that Andy is gonna whack on this a little more, and then release a gamma in a few days when he's happy with it. So don't get carried away. This is now *late* beta. In other words, have less than the appropriate amount of fun. :-) Larry
Diffstat (limited to 'doio.c')
-rw-r--r--doio.c205
1 files changed, 112 insertions, 93 deletions
diff --git a/doio.c b/doio.c
index 0e8713eb04..f20d9f736c 100644
--- a/doio.c
+++ b/doio.c
@@ -54,30 +54,25 @@
#endif
bool
-do_open(gv,name,len,supplied_fp)
+do_open(gv,name,len,as_raw,rawmode,rawperm,supplied_fp)
GV *gv;
register char *name;
I32 len;
+int as_raw;
+int rawmode, rawperm;
FILE *supplied_fp;
{
- FILE *fp;
register IO *io = GvIOn(gv);
- char *myname = savepv(name);
- int result;
- int fd;
- int writing = 0;
- int dodup;
- char mode[3]; /* stdio file mode ("r\0" or "r+\0") */
FILE *saveifp = Nullfp;
FILE *saveofp = Nullfp;
char savetype = ' ';
+ int writing = 0;
+ FILE *fp;
+ int fd;
+ int result;
- SAVEFREEPV(myname);
- mode[0] = mode[1] = mode[2] = '\0';
- name = myname;
forkprocess = 1; /* assume true if no fork */
- while (len && isSPACE(name[len-1]))
- name[--len] = '\0';
+
if (IoIFP(io)) {
fd = fileno(IoIFP(io));
if (IoTYPE(io) == '-')
@@ -105,95 +100,119 @@ FILE *supplied_fp;
GvENAME(gv));
IoOFP(io) = IoIFP(io) = Nullfp;
}
- if (*name == '+' && len > 1 && name[len-1] != '|') { /* scary */
- mode[1] = *name++;
- mode[2] = '\0';
- --len;
- writing = 1;
- }
- else {
- mode[1] = '\0';
- }
- IoTYPE(io) = *name;
- if (*name == '|') {
- /*SUPPRESS 530*/
- for (name++; isSPACE(*name); name++) ;
- if (strNE(name,"-"))
- TAINT_ENV();
- TAINT_PROPER("piped open");
- if (dowarn && name[strlen(name)-1] == '|')
- warn("Can't do bidirectional pipe");
- fp = my_popen(name,"w");
- writing = 1;
+
+ if (as_raw) {
+ result = rawmode & 3;
+ IoTYPE(io) = "<>++"[result];
+ writing = (result > 0);
+ fd = open(name, rawmode, rawperm);
+ if (fd == -1)
+ fp = NULL;
+ else {
+ fp = fdopen(fd, ((result == 0) ? "r"
+ : (result == 1) ? "w"
+ : "r+"));
+ if (!fp)
+ close(fd);
+ }
}
- else if (*name == '>') {
- TAINT_PROPER("open");
- name++;
- if (*name == '>') {
- mode[0] = IoTYPE(io) = 'a';
- name++;
+ else {
+ char *myname;
+ char mode[3]; /* stdio file mode ("r\0" or "r+\0") */
+ int dodup;
+
+ myname = savepvn(name, len);
+ SAVEFREEPV(myname);
+ name = myname;
+ while (len && isSPACE(name[len-1]))
+ name[--len] = '\0';
+
+ mode[0] = mode[1] = mode[2] = '\0';
+ IoTYPE(io) = *name;
+ if (*name == '+' && len > 1 && name[len-1] != '|') { /* scary */
+ mode[1] = *name++;
+ --len;
+ writing = 1;
}
- else
- mode[0] = 'w';
- writing = 1;
- if (*name == '&') {
- duplicity:
- dodup = 1;
+
+ if (*name == '|') {
+ /*SUPPRESS 530*/
+ for (name++; isSPACE(*name); name++) ;
+ if (strNE(name,"-"))
+ TAINT_ENV();
+ TAINT_PROPER("piped open");
+ if (dowarn && name[strlen(name)-1] == '|')
+ warn("Can't do bidirectional pipe");
+ fp = my_popen(name,"w");
+ writing = 1;
+ }
+ else if (*name == '>') {
+ TAINT_PROPER("open");
name++;
- if (*name == '=') {
- dodup = 0;
+ if (*name == '>') {
+ mode[0] = IoTYPE(io) = 'a';
name++;
}
- if (!*name && supplied_fp)
- fp = supplied_fp;
- else {
- while (isSPACE(*name))
+ else
+ mode[0] = 'w';
+ writing = 1;
+
+ if (*name == '&') {
+ duplicity:
+ dodup = 1;
+ name++;
+ if (*name == '=') {
+ dodup = 0;
name++;
- if (isDIGIT(*name))
- fd = atoi(name);
+ }
+ if (!*name && supplied_fp)
+ fp = supplied_fp;
else {
- IO* thatio;
- gv = gv_fetchpv(name,FALSE,SVt_PVIO);
- thatio = GvIO(gv);
- if (!thatio) {
+ /*SUPPRESS 530*/
+ for (; isSPACE(*name); name++) ;
+ if (isDIGIT(*name))
+ fd = atoi(name);
+ else {
+ IO* thatio;
+ gv = gv_fetchpv(name,FALSE,SVt_PVIO);
+ thatio = GvIO(gv);
+ if (!thatio) {
#ifdef EINVAL
- SETERRNO(EINVAL,SS$_IVCHAN);
+ SETERRNO(EINVAL,SS$_IVCHAN);
#endif
- goto say_false;
+ goto say_false;
+ }
+ if (IoIFP(thatio)) {
+ fd = fileno(IoIFP(thatio));
+ if (IoTYPE(thatio) == 's')
+ IoTYPE(io) = 's';
+ }
+ else
+ fd = -1;
}
- if (IoIFP(thatio)) {
- fd = fileno(IoIFP(thatio));
- if (IoTYPE(thatio) == 's')
- IoTYPE(io) = 's';
- }
- else
- fd = -1;
- }
- if (dodup)
- fd = dup(fd);
- if (!(fp = fdopen(fd,mode)))
if (dodup)
- close(fd);
- }
- }
- else {
- while (isSPACE(*name))
- name++;
- if (strEQ(name,"-")) {
- fp = stdout;
- IoTYPE(io) = '-';
+ fd = dup(fd);
+ if (!(fp = fdopen(fd,mode)))
+ if (dodup)
+ close(fd);
+ }
}
- else {
- fp = fopen(name,mode);
+ else {
+ /*SUPPRESS 530*/
+ for (; isSPACE(*name); name++) ;
+ if (strEQ(name,"-")) {
+ fp = stdout;
+ IoTYPE(io) = '-';
+ }
+ else {
+ fp = fopen(name,mode);
+ }
}
}
- }
- else {
- if (*name == '<') {
+ else if (*name == '<') {
+ /*SUPPRESS 530*/
+ for (name++; isSPACE(*name); name++) ;
mode[0] = 'r';
- name++;
- while (isSPACE(*name))
- name++;
if (*name == '&')
goto duplicity;
if (strEQ(name,"-")) {
@@ -340,7 +359,7 @@ register GV *gv;
sv_setsv(GvSV(gv),sv);
SvSETMAGIC(GvSV(gv));
oldname = SvPVx(GvSV(gv), len);
- if (do_open(gv,oldname,len,Nullfp)) {
+ if (do_open(gv,oldname,len,FALSE,0,0,Nullfp)) {
if (inplace) {
TAINT_PROPER("inplace open");
if (strEQ(oldname,"-")) {
@@ -388,7 +407,7 @@ register GV *gv;
do_close(gv,FALSE);
(void)unlink(SvPVX(sv));
(void)rename(oldname,SvPVX(sv));
- do_open(gv,SvPVX(sv),SvCUR(GvSV(gv)),Nullfp);
+ do_open(gv,SvPVX(sv),SvCUR(GvSV(gv)),FALSE,0,0,Nullfp);
#endif /* MSDOS */
#else
(void)UNLINK(SvPVX(sv));
@@ -417,7 +436,7 @@ register GV *gv;
sv_setpvn(sv,">",1);
sv_catpv(sv,oldname);
SETERRNO(0,0); /* in case sprintf set errno */
- if (!do_open(argvoutgv,SvPVX(sv),SvCUR(sv),Nullfp)) {
+ if (!do_open(argvoutgv,SvPVX(sv),SvCUR(sv),FALSE,0,0,Nullfp)) {
warn("Can't do inplace edit on %s: %s",
oldname, Strerror(errno) );
do_close(gv,FALSE);
@@ -1286,7 +1305,7 @@ SV **sp;
#endif
#if !defined(HAS_MSG) || !defined(HAS_SEM) || !defined(HAS_SHM)
default:
- croak("%s not implemented", op_name[optype]);
+ croak("%s not implemented", op_desc[optype]);
#endif
}
return -1; /* should never happen */
@@ -1342,7 +1361,7 @@ SV **sp;
#endif
#if !defined(HAS_MSG) || !defined(HAS_SEM) || !defined(HAS_SHM)
default:
- croak("%s not implemented", op_name[optype]);
+ croak("%s not implemented", op_desc[optype]);
#endif
}
@@ -1359,7 +1378,7 @@ SV **sp;
a = SvPV(astr, len);
if (len != infosize)
croak("Bad arg length for %s, is %d, should be %d",
- op_name[optype], len, infosize);
+ op_desc[optype], len, infosize);
}
}
else