Change 20958 by [EMAIL PROTECTED] on 2003/08/30 18:55:20
Integrate:
[ 20956]
This is probably a wrong fix for
[perl #23645] tell with perlio on appended files
but maybe this gets NI-S agitated enough to present the correct fix :-)
[ 20957]
Fewer naked char constants.
Affected files ...
... //depot/maint-5.8/perl/doio.c#19 integrate
... //depot/maint-5.8/perl/perlio.c#34 integrate
... //depot/maint-5.8/perl/sv.h#19 integrate
... //depot/maint-5.8/perl/t/io/tell.t#5 integrate
Differences ...
==== //depot/maint-5.8/perl/doio.c#19 (text) ====
Index: perl/doio.c
--- perl/doio.c#18~20649~ Tue Aug 12 05:14:31 2003
+++ perl/doio.c Sat Aug 30 11:55:20 2003
@@ -179,7 +179,7 @@
(ismodifying & (O_CREAT|appendtrunc)))
TAINT_PROPER("sysopen");
}
- mode[ix++] = '#'; /* Marker to openn to use numeric "sysopen" */
+ mode[ix++] = IoTYPE_NUMERIC; /* Marker to openn to use numeric "sysopen" */
#if defined(USE_64_BIT_RAWIO) && defined(O_LARGEFILE)
rawmode |= O_LARGEFILE; /* Transparently largefiley. */
@@ -674,8 +674,8 @@
if (IoTYPE(io) == IoTYPE_SOCKET
|| (IoTYPE(io) == IoTYPE_WRONLY && fd >= 0 && S_ISCHR(PL_statbuf.st_mode))
) {
char *s = mode;
- if (*s == 'I' || *s == '#')
- s++;
+ if (*s == IoTYPE_IMPLICIT || *s == IoTYPE_NUMERIC)
+ s++;
*s = 'w';
if (!(IoOFP(io) = PerlIO_openn(aTHX_ type,s,fd,0,0,NULL,0,svp))) {
PerlIO_close(fp);
==== //depot/maint-5.8/perl/perlio.c#34 (text) ====
Index: perl/perlio.c
--- perl/perlio.c#33~20955~ Sat Aug 30 10:17:57 2003
+++ perl/perlio.c Sat Aug 30 11:55:20 2003
@@ -288,7 +288,7 @@
return PerlIO_tmpfile();
else {
char *name = SvPV_nolen(*args);
- if (*mode == '#') {
+ if (*mode == IoTYPE_NUMERIC) {
fd = PerlLIO_open3(name, imode, perm);
if (fd >= 0)
return PerlIO_fdopen(fd, (char *) mode + 1);
@@ -1960,7 +1960,7 @@
if (tab->Set_ptrcnt != NULL)
l->flags |= PERLIO_F_FASTGETS;
if (mode) {
- if (*mode == '#' || *mode == 'I')
+ if (*mode == IoTYPE_NUMERIC || *mode == IoTYPE_IMPLICIT)
mode++;
switch (*mode++) {
case 'r':
@@ -2276,7 +2276,7 @@
PerlIOUnix_oflags(const char *mode)
{
int oflags = -1;
- if (*mode == 'I' || *mode == '#')
+ if (*mode == IoTYPE_IMPLICIT || *mode == IoTYPE_NUMERIC)
mode++;
switch (*mode) {
case 'r':
@@ -2375,6 +2375,28 @@
return code;
}
+IV
+PerlIOUnix_seek(pTHX_ PerlIO *f, Off_t offset, int whence)
+{
+ int fd = PerlIOSelf(f, PerlIOUnix)->fd;
+ Off_t new;
+ if (PerlIOBase(f)->flags & PERLIO_F_NOTREG) {
+#ifdef ESPIPE
+ SETERRNO(ESPIPE, LIB_INVARG);
+#else
+ SETERRNO(EINVAL, LIB_INVARG);
+#endif
+ return -1;
+ }
+ new = PerlLIO_lseek(fd, offset, whence);
+ if (new == (Off_t) - 1)
+ {
+ return -1;
+ }
+ PerlIOBase(f)->flags &= ~PERLIO_F_EOF;
+ return 0;
+}
+
PerlIO *
PerlIOUnix_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers,
IV n, const char *mode, int fd, int imode,
@@ -2386,7 +2408,7 @@
}
if (narg > 0) {
char *path = SvPV_nolen(*args);
- if (*mode == '#')
+ if (*mode == IoTYPE_NUMERIC)
mode++;
else {
imode = PerlIOUnix_oflags(mode);
@@ -2397,7 +2419,7 @@
}
}
if (fd >= 0) {
- if (*mode == 'I')
+ if (*mode == IoTYPE_IMPLICIT)
mode++;
if (!f) {
f = PerlIO_allocate(aTHX);
@@ -2409,6 +2431,8 @@
}
PerlIOUnix_setfd(aTHX_ f, fd, imode);
PerlIOBase(f)->flags |= PERLIO_F_OPEN;
+ if (*mode == IoTYPE_APPEND)
+ PerlIOUnix_seek(aTHX_ f, 0, SEEK_END);
return f;
}
else {
@@ -2485,28 +2509,6 @@
}
}
-IV
-PerlIOUnix_seek(pTHX_ PerlIO *f, Off_t offset, int whence)
-{
- int fd = PerlIOSelf(f, PerlIOUnix)->fd;
- Off_t new;
- if (PerlIOBase(f)->flags & PERLIO_F_NOTREG) {
-#ifdef ESPIPE
- SETERRNO(ESPIPE, LIB_INVARG);
-#else
- SETERRNO(EINVAL, LIB_INVARG);
-#endif
- return -1;
- }
- new = PerlLIO_lseek(fd, offset, whence);
- if (new == (Off_t) - 1)
- {
- return -1;
- }
- PerlIOBase(f)->flags &= ~PERLIO_F_EOF;
- return 0;
-}
-
Off_t
PerlIOUnix_tell(pTHX_ PerlIO *f)
{
@@ -2705,7 +2707,7 @@
else {
if (narg > 0) {
char *path = SvPV_nolen(*args);
- if (*mode == '#') {
+ if (*mode == IoTYPE_NUMERIC) {
mode++;
fd = PerlLIO_open3(path, imode, perm);
}
@@ -2741,7 +2743,7 @@
if (fd >= 0) {
FILE *stdio = NULL;
int init = 0;
- if (*mode == 'I') {
+ if (*mode == IoTYPE_IMPLICIT) {
init = 1;
mode++;
}
@@ -3431,7 +3433,7 @@
else {
PerlIO_funcs *tab = PerlIO_layer_fetch(aTHX_ layers, n - 1,
PerlIO_default_btm());
int init = 0;
- if (*mode == 'I') {
+ if (*mode == IoTYPE_IMPLICIT) {
init = 1;
/*
* mode++;
==== //depot/maint-5.8/perl/sv.h#19 (text) ====
Index: perl/sv.h
--- perl/sv.h#18~20947~ Fri Aug 29 23:07:56 2003
+++ perl/sv.h Sat Aug 30 11:55:20 2003
@@ -807,14 +807,16 @@
#define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags
/* 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 ' '
+#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 ' '
+#define IoTYPE_IMPLICIT 'I' /* stdin or stdout or stderr */
+#define IoTYPE_NUMERIC '#' /* fdopen */
/*
=for apidoc Am|bool|SvTAINTED|SV* sv
==== //depot/maint-5.8/perl/t/io/tell.t#5 (xtext) ====
Index: perl/t/io/tell.t
--- perl/t/io/tell.t#4~19591~ Thu May 22 04:59:21 2003
+++ perl/t/io/tell.t Sat Aug 30 11:55:20 2003
@@ -7,7 +7,7 @@
@INC = '../lib';
}
-print "1..27\n";
+print "1..28\n";
$TST = 'tst';
@@ -143,4 +143,12 @@
close($tst);
+open($tst,">$written") || die "Cannot open $written:$!";
+print $tst "foobar";
+close $tst;
+open($tst,">>$written") || die "Cannot open $written:$!";
+
+if (tell($tst) == 6)
+{ print "ok 28\n"; } else { print "not ok 28\n"; }
+close $tst;
End of Patch.