[ID 20001203.001] Not OK: perl v5.7.0 +DEVEL7965 on os2-64int-ld 2.30 (UNINSTALLED)
[p5sagit/p5-mst-13.2.git] / perlio.c
index d0c3b2e..41d4a8e 100644 (file)
--- a/perlio.c
+++ b/perlio.c
@@ -95,7 +95,6 @@ PerlIO_binmode(pTHX_ PerlIO *fp, int iotype, int mode, const char *names)
 
 #endif
 
-#if !defined(PERL_IMPLICIT_SYS)
 
 #ifdef PERLIO_IS_STDIO
 
@@ -172,6 +171,7 @@ void PerlIO_debug(const char *fmt,...) __attribute__((format(__printf__,1,2)));
 void
 PerlIO_debug(const char *fmt,...)
 {
+ dTHX;
  static int dbg = 0;
  va_list ap;
  va_start(ap,fmt);
@@ -1162,6 +1162,7 @@ PerlIOUnix_fdopen(PerlIO_funcs *self, int fd,const char *mode)
 PerlIO *
 PerlIOUnix_open(PerlIO_funcs *self, const char *path,const char *mode)
 {
+ dTHX;
  PerlIO *f = NULL;
  int oflags = PerlIOUnix_oflags(mode);
  if (oflags != -1)
@@ -1187,6 +1188,7 @@ PerlIOUnix_reopen(const char *path, const char *mode, PerlIO *f)
   (*PerlIOBase(f)->tab->Close)(f);
  if (oflags != -1)
   {
+   dTHX;
    int fd = PerlLIO_open3(path,oflags,0666);
    if (fd >= 0)
     {
@@ -1202,6 +1204,7 @@ PerlIOUnix_reopen(const char *path, const char *mode, PerlIO *f)
 SSize_t
 PerlIOUnix_read(PerlIO *f, void *vbuf, Size_t count)
 {
+ dTHX;
  int fd = PerlIOSelf(f,PerlIOUnix)->fd;
  if (!(PerlIOBase(f)->flags & PERLIO_F_CANREAD))
   return 0;
@@ -1222,6 +1225,7 @@ PerlIOUnix_read(PerlIO *f, void *vbuf, Size_t count)
 SSize_t
 PerlIOUnix_write(PerlIO *f, const void *vbuf, Size_t count)
 {
+ dTHX;
  int fd = PerlIOSelf(f,PerlIOUnix)->fd;
  while (1)
   {
@@ -1238,6 +1242,7 @@ PerlIOUnix_write(PerlIO *f, const void *vbuf, Size_t count)
 IV
 PerlIOUnix_seek(PerlIO *f, Off_t offset, int whence)
 {
+ dTHX;
  Off_t new = PerlLIO_lseek(PerlIOSelf(f,PerlIOUnix)->fd,offset,whence);
  PerlIOBase(f)->flags &= ~PERLIO_F_EOF;
  return (new == (Off_t) -1) ? -1 : 0;
@@ -1246,12 +1251,14 @@ PerlIOUnix_seek(PerlIO *f, Off_t offset, int whence)
 Off_t
 PerlIOUnix_tell(PerlIO *f)
 {
+ dTHX;
  return PerlLIO_lseek(PerlIOSelf(f,PerlIOUnix)->fd,0,SEEK_CUR);
 }
 
 IV
 PerlIOUnix_close(PerlIO *f)
 {
+ dTHX;
  int fd = PerlIOSelf(f,PerlIOUnix)->fd;
  int code = 0;
  while (PerlLIO_close(fd) != 0)
@@ -1310,7 +1317,8 @@ typedef struct
 IV
 PerlIOStdio_fileno(PerlIO *f)
 {
- return fileno(PerlIOSelf(f,PerlIOStdio)->stdio);
+ dTHX;
+ return PerlSIO_fileno(PerlIOSelf(f,PerlIOStdio)->stdio);
 }
 
 const char *
@@ -1333,6 +1341,7 @@ PerlIOStdio_mode(const char *mode,char *tmode)
 PerlIO *
 PerlIOStdio_fdopen(PerlIO_funcs *self, int fd,const char *mode)
 {
+ dTHX;
  PerlIO *f = NULL;
  int init = 0;
  char tmode[8];
@@ -1349,19 +1358,19 @@ PerlIOStdio_fdopen(PerlIO_funcs *self, int fd,const char *mode)
      switch(fd)
       {
        case 0:
-        stdio = stdin;
+        stdio = PerlSIO_stdin;
         break;
        case 1:
-        stdio = stdout;
+        stdio = PerlSIO_stdout;
         break;
        case 2:
-        stdio = stderr;
+        stdio = PerlSIO_stderr;
         break;
       }
     }
    else
     {
-     stdio = fdopen(fd,mode = PerlIOStdio_mode(mode,tmode));
+     stdio = PerlSIO_fdopen(fd,mode = PerlIOStdio_mode(mode,tmode));
     }
    if (stdio)
     {
@@ -1388,8 +1397,9 @@ PerlIO_importFILE(FILE *stdio, int fl)
 PerlIO *
 PerlIOStdio_open(PerlIO_funcs *self, const char *path,const char *mode)
 {
+ dTHX;
  PerlIO *f = NULL;
- FILE *stdio = fopen(path,mode);
+ FILE *stdio = PerlSIO_fopen(path,mode);
  if (stdio)
   {
    char tmode[8];
@@ -1404,9 +1414,10 @@ PerlIOStdio_open(PerlIO_funcs *self, const char *path,const char *mode)
 int
 PerlIOStdio_reopen(const char *path, const char *mode, PerlIO *f)
 {
+ dTHX;
  PerlIOStdio *s = PerlIOSelf(f,PerlIOStdio);
  char tmode[8];
- FILE *stdio = freopen(path,(mode = PerlIOStdio_mode(mode,tmode)),s->stdio);
+ FILE *stdio = PerlSIO_freopen(path,(mode = PerlIOStdio_mode(mode,tmode)),s->stdio);
  if (!s->stdio)
   return -1;
  s->stdio = stdio;
@@ -1416,6 +1427,7 @@ PerlIOStdio_reopen(const char *path, const char *mode, PerlIO *f)
 SSize_t
 PerlIOStdio_read(PerlIO *f, void *vbuf, Size_t count)
 {
+ dTHX;
  FILE *s = PerlIOSelf(f,PerlIOStdio)->stdio;
  SSize_t got = 0;
  if (count == 1)
@@ -1424,7 +1436,7 @@ PerlIOStdio_read(PerlIO *f, void *vbuf, Size_t count)
    /* Perl is expecting PerlIO_getc() to fill the buffer
     * Linux's stdio does not do that for fread()
     */
-   int ch = fgetc(s);
+   int ch = PerlSIO_fgetc(s);
    if (ch != EOF)
     {
      *buf = ch;
@@ -1432,20 +1444,21 @@ PerlIOStdio_read(PerlIO *f, void *vbuf, Size_t count)
     }
   }
  else
-  got = fread(vbuf,1,count,s);
+  got = PerlSIO_fread(vbuf,1,count,s);
  return got;
 }
 
 SSize_t
 PerlIOStdio_unread(PerlIO *f, const void *vbuf, Size_t count)
 {
+ dTHX;
  FILE *s = PerlIOSelf(f,PerlIOStdio)->stdio;
  STDCHAR *buf = ((STDCHAR *)vbuf)+count-1;
  SSize_t unread = 0;
  while (count > 0)
   {
    int ch = *buf-- & 0xff;
-   if (ungetc(ch,s) != ch)
+   if (PerlSIO_ungetc(ch,s) != ch)
     break;
    unread++;
    count--;
@@ -1456,41 +1469,54 @@ PerlIOStdio_unread(PerlIO *f, const void *vbuf, Size_t count)
 SSize_t
 PerlIOStdio_write(PerlIO *f, const void *vbuf, Size_t count)
 {
- return fwrite(vbuf,1,count,PerlIOSelf(f,PerlIOStdio)->stdio);
+ dTHX;
+ return PerlSIO_fwrite(vbuf,1,count,PerlIOSelf(f,PerlIOStdio)->stdio);
 }
 
 IV
 PerlIOStdio_seek(PerlIO *f, Off_t offset, int whence)
 {
+ dTHX;
  FILE *stdio = PerlIOSelf(f,PerlIOStdio)->stdio;
- return fseek(stdio,offset,whence);
+ return PerlSIO_fseek(stdio,offset,whence);
 }
 
 Off_t
 PerlIOStdio_tell(PerlIO *f)
 {
+ dTHX;
  FILE *stdio = PerlIOSelf(f,PerlIOStdio)->stdio;
- return ftell(stdio);
+ return PerlSIO_ftell(stdio);
 }
 
 IV
 PerlIOStdio_close(PerlIO *f)
 {
+ dTHX;
+#ifdef HAS_SOCKET
  int optval, optlen = sizeof(int);
+#endif
  FILE *stdio = PerlIOSelf(f,PerlIOStdio)->stdio;
  return(
+#ifdef HAS_SOCKET
    (getsockopt(PerlIO_fileno(f), SOL_SOCKET, SO_TYPE, (char *)&optval, &optlen) < 0) ?
-       fclose(stdio) :
-       close(PerlIO_fileno(f)));
+       PerlSIO_fclose(stdio) :
+       close(PerlIO_fileno(f))
+#else
+   PerlSIO_fclose(stdio)
+#endif
+     );
+
 }
 
 IV
 PerlIOStdio_flush(PerlIO *f)
 {
+ dTHX;
  FILE *stdio = PerlIOSelf(f,PerlIOStdio)->stdio;
  if (PerlIOBase(f)->flags & PERLIO_F_CANWRITE)
   {
-   return fflush(stdio);
+   return PerlSIO_fflush(stdio);
   }
  else
   {
@@ -1502,7 +1528,7 @@ PerlIOStdio_flush(PerlIO *f)
     */
    /* Not writeable - sync by attempting a seek */
    int err = errno;
-   if (fseek(stdio,(Off_t) 0, SEEK_CUR) != 0)
+   if (PerlSIO_fseek(stdio,(Off_t) 0, SEEK_CUR) != 0)
     errno = err;
 #endif
   }
@@ -1512,16 +1538,17 @@ PerlIOStdio_flush(PerlIO *f)
 IV
 PerlIOStdio_fill(PerlIO *f)
 {
+ dTHX;
  FILE *stdio = PerlIOSelf(f,PerlIOStdio)->stdio;
  int c;
  /* fflush()ing read-only streams can cause trouble on some stdio-s */
  if ((PerlIOBase(f)->flags & PERLIO_F_CANWRITE))
   {
-   if (fflush(stdio) != 0)
+   if (PerlSIO_fflush(stdio) != 0)
     return EOF;
   }
- c = fgetc(stdio);
- if (c == EOF || ungetc(c,stdio) != c)
+ c = PerlSIO_fgetc(stdio);
+ if (c == EOF || PerlSIO_ungetc(c,stdio) != c)
   return EOF;
  return 0;
 }
@@ -1529,28 +1556,32 @@ PerlIOStdio_fill(PerlIO *f)
 IV
 PerlIOStdio_eof(PerlIO *f)
 {
- return feof(PerlIOSelf(f,PerlIOStdio)->stdio);
+ dTHX;
+ return PerlSIO_feof(PerlIOSelf(f,PerlIOStdio)->stdio);
 }
 
 IV
 PerlIOStdio_error(PerlIO *f)
 {
- return ferror(PerlIOSelf(f,PerlIOStdio)->stdio);
+ dTHX;
+ return PerlSIO_ferror(PerlIOSelf(f,PerlIOStdio)->stdio);
 }
 
 void
 PerlIOStdio_clearerr(PerlIO *f)
 {
- clearerr(PerlIOSelf(f,PerlIOStdio)->stdio);
+ dTHX;
+ PerlSIO_clearerr(PerlIOSelf(f,PerlIOStdio)->stdio);
 }
 
 void
 PerlIOStdio_setlinebuf(PerlIO *f)
 {
+ dTHX;
 #ifdef HAS_SETLINEBUF
- setlinebuf(PerlIOSelf(f,PerlIOStdio)->stdio);
+ PerlSIO_setlinebuf(PerlIOSelf(f,PerlIOStdio)->stdio);
 #else
- setvbuf(PerlIOSelf(f,PerlIOStdio)->stdio, Nullch, _IOLBF, 0);
+ PerlSIO_setvbuf(PerlIOSelf(f,PerlIOStdio)->stdio, Nullch, _IOLBF, 0);
 #endif
 }
 
@@ -1558,15 +1589,17 @@ PerlIOStdio_setlinebuf(PerlIO *f)
 STDCHAR *
 PerlIOStdio_get_base(PerlIO *f)
 {
+ dTHX;
  FILE *stdio  = PerlIOSelf(f,PerlIOStdio)->stdio;
- return FILE_base(stdio);
+ return PerlSIO_get_base(stdio);
 }
 
 Size_t
 PerlIOStdio_get_bufsiz(PerlIO *f)
 {
+ dTHX;
  FILE *stdio = PerlIOSelf(f,PerlIOStdio)->stdio;
- return FILE_bufsiz(stdio);
+ return PerlSIO_get_bufsiz(stdio);
 }
 #endif
 
@@ -1574,30 +1607,33 @@ PerlIOStdio_get_bufsiz(PerlIO *f)
 STDCHAR *
 PerlIOStdio_get_ptr(PerlIO *f)
 {
+ dTHX;
  FILE *stdio = PerlIOSelf(f,PerlIOStdio)->stdio;
- return FILE_ptr(stdio);
+ return PerlSIO_get_ptr(stdio);
 }
 
 SSize_t
 PerlIOStdio_get_cnt(PerlIO *f)
 {
+ dTHX;
  FILE *stdio = PerlIOSelf(f,PerlIOStdio)->stdio;
- return FILE_cnt(stdio);
+ return PerlSIO_get_cnt(stdio);
 }
 
 void
 PerlIOStdio_set_ptrcnt(PerlIO *f,STDCHAR *ptr,SSize_t cnt)
 {
+ dTHX;
  FILE *stdio = PerlIOSelf(f,PerlIOStdio)->stdio;
  if (ptr != NULL)
   {
 #ifdef STDIO_PTR_LVALUE
-   FILE_ptr(stdio) = ptr;
+   PerlSIO_set_ptr(stdio,ptr);
 #ifdef STDIO_PTR_LVAL_SETS_CNT
-   if (FILE_cnt(stdio) != (cnt))
+   if (PerlSIO_get_cnt(stdio) != (cnt))
     {
      dTHX;
-     assert(FILE_cnt(stdio) == (cnt));
+     assert(PerlSIO_get_cnt(stdio) == (cnt));
     }
 #endif
 #if (!defined(STDIO_PTR_LVAL_NOCHANGE_CNT))
@@ -1605,17 +1641,17 @@ PerlIOStdio_set_ptrcnt(PerlIO *f,STDCHAR *ptr,SSize_t cnt)
    return;
 #endif
 #else  /* STDIO_PTR_LVALUE */
-   abort();
+   PerlProc_abort();
 #endif /* STDIO_PTR_LVALUE */
   }
 /* Now (or only) set cnt */
 #ifdef STDIO_CNT_LVALUE
- FILE_cnt(stdio) = cnt;
+ PerlSIO_set_cnt(stdio,cnt);
 #else  /* STDIO_CNT_LVALUE */
 #if (defined(STDIO_PTR_LVALUE) && defined(STDIO_PTR_LVAL_SETS_CNT))
- FILE_ptr(stdio) = FILE_ptr(stdio)+(FILE_cnt(stdio)-cnt);
+ PerlSIO_set_ptr(stdio,PerlSIO_get_ptr(stdio)+(PerlSIO_get_cnt(stdio)-cnt));
 #else  /* STDIO_PTR_LVAL_SETS_CNT */
- abort();
+ PerlProc_abort();
 #endif /* STDIO_PTR_LVAL_SETS_CNT */
 #endif /* STDIO_CNT_LVALUE */
 }
@@ -1702,6 +1738,7 @@ PerlIOBuf_pushed(PerlIO *f, const char *mode)
 PerlIO *
 PerlIOBuf_fdopen(PerlIO_funcs *self, int fd, const char *mode)
 {
+ dTHX;
  PerlIO_funcs *tab = PerlIO_default_btm();
  int init = 0;
  PerlIO *f;
@@ -3017,8 +3054,9 @@ PerlIO_tmpfile(void)
 {
  /* I have no idea how portable mkstemp() is ... */
 #if defined(WIN32) || !defined(HAVE_MKSTEMP)
+ dTHX;
  PerlIO *f = NULL;
- FILE *stdio = tmpfile();
+ FILE *stdio = PerlSIO_tmpfile();
  if (stdio)
   {
    PerlIOStdio *s = PerlIOSelf(PerlIO_push(f = PerlIO_allocate(),&PerlIO_stdio,"w+"),PerlIOStdio);
@@ -3150,5 +3188,4 @@ PerlIO_sprintf(char *s, int n, const char *fmt,...)
 }
 #endif
 
-#endif /* !PERL_IMPLICIT_SYS */