#include <sys/mman.h>
#endif
-
+/*
+ * Why is this here - not in perlio.h? RMB
+ */
void PerlIO_debug(const char *fmt, ...)
- __attribute__ ((format(__printf__, 1, 2)));
+#ifdef CHECK_FORMAT
+ __attribute__ ((__format__(__printf__, 1, 2)))
+#endif
+;
void
PerlIO_debug(const char *fmt, ...)
return PerlIOSelf(f, PerlIOUnix)->fd;
}
+static void
+PerlIOUnix_setfd(pTHX_ PerlIO *f, int fd, int imode)
+{
+ PerlIOUnix *s = PerlIOSelf(f, PerlIOUnix);
+#if defined(WIN32)
+ Stat_t st;
+ if (PerlLIO_fstat(fd, &st) == 0) {
+ if (!S_ISREG(st.st_mode)) {
+ PerlIO_debug("%d is not regular file\n",fd);
+ PerlIOBase(f)->flags |= PERLIO_F_NOTREG;
+ }
+ else {
+ PerlIO_debug("%d _is_ a regular file\n",fd);
+ }
+ }
+#endif
+ s->fd = fd;
+ s->oflags = imode;
+ PerlIOUnix_refcnt_inc(fd);
+}
+
IV
PerlIOUnix_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab)
{
IV code = PerlIOBase_pushed(aTHX_ f, mode, arg, tab);
- PerlIOUnix *s = PerlIOSelf(f, PerlIOUnix);
if (*PerlIONext(f)) {
/* We never call down so do any pending stuff now */
PerlIO_flush(PerlIONext(f));
- s->fd = PerlIO_fileno(PerlIONext(f));
/*
* XXX could (or should) we retrieve the oflags from the open file
* handle rather than believing the "mode" we are passed in? XXX
* Should the value on NULL mode be 0 or -1?
*/
- s->oflags = mode ? PerlIOUnix_oflags(mode) : -1;
+ PerlIOUnix_setfd(aTHX_ f, PerlIO_fileno(PerlIONext(f)),
+ mode ? PerlIOUnix_oflags(mode) : -1);
}
PerlIOBase(f)->flags |= PERLIO_F_OPEN;
+
return code;
}
}
}
if (fd >= 0) {
- PerlIOUnix *s;
if (*mode == 'I')
mode++;
if (!f) {
return NULL;
}
}
- s = PerlIOSelf(f, PerlIOUnix);
- s->fd = fd;
- s->oflags = imode;
+ PerlIOUnix_setfd(aTHX_ f, fd, imode);
PerlIOBase(f)->flags |= PERLIO_F_OPEN;
- PerlIOUnix_refcnt_inc(fd);
return f;
}
else {
f = PerlIOBase_dup(aTHX_ f, o, param, flags);
if (f) {
/* If all went well overwrite fd in dup'ed lay with the dup()'ed fd */
- PerlIOUnix *s = PerlIOSelf(f, PerlIOUnix);
- s->fd = fd;
- PerlIOUnix_refcnt_inc(fd);
+ PerlIOUnix_setfd(aTHX_ f, fd, os->oflags);
return f;
}
}
IV
PerlIOUnix_seek(pTHX_ PerlIO *f, Off_t offset, int whence)
{
- Off_t new =
- PerlLIO_lseek(PerlIOSelf(f, PerlIOUnix)->fd, offset, 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 (new == (Off_t) - 1) ? -1 : 0;
+ return 0;
}
Off_t