2001-11-04 Stefan Jahn <stefan@lkcc.org>
[bpt/guile.git] / libguile / fports.c
index 9466214..426db6f 100644 (file)
@@ -59,6 +59,9 @@
 #else
 size_t fwrite ();
 #endif
+#ifdef HAVE_IO_H
+#include <io.h>
+#endif
 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
 #include <sys/stat.h>
 #endif
@@ -86,7 +89,6 @@ static void
 scm_fport_buffer_add (SCM port, long read_size, int write_size)
 #define FUNC_NAME "scm_fport_buffer_add"
 {
-  scm_t_fport *fp = SCM_FSTREAM (port);
   scm_t_port *pt = SCM_PTAB_ENTRY (port);
 
   if (read_size == -1 || write_size == -1)
@@ -94,6 +96,7 @@ scm_fport_buffer_add (SCM port, long read_size, int write_size)
       size_t default_size;
 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
       struct stat st;
+      scm_t_fport *fp = SCM_FSTREAM (port);
       
       default_size = (fstat (fp->fdes, &st) == -1) ? default_buffer_size
        : st.st_blksize;
@@ -209,9 +212,9 @@ scm_evict_ports (int fd)
 {
   long i;
 
-  for (i = 0; i < scm_t_portable_size; i++)
+  for (i = 0; i < scm_port_table_size; i++)
     {
-      SCM port = scm_t_portable[i]->port;
+      SCM port = scm_port_table[i]->port;
 
       if (SCM_FPORTP (port))
        {
@@ -297,8 +300,6 @@ SCM_DEFINE (scm_open_file, "open-file", 2, 0, 0,
 
   SCM_VALIDATE_STRING (1, filename);
   SCM_VALIDATE_STRING (2, mode);
-  SCM_STRING_COERCE_0TERMINATION_X (filename);
-  SCM_STRING_COERCE_0TERMINATION_X (mode);
 
   file = SCM_STRING_CHARS (filename);
   md = SCM_STRING_CHARS (mode);
@@ -378,13 +379,15 @@ static int getflags (int fdes)
   else
     {
       /* Or an anonymous pipe handle ? */
-      if (buf.st_mode & 0x1000 /* _O_SHORT_LIVED */)
-       flags = O_RDWR;
+      if (buf.st_mode & _S_IFIFO)
+       flags = PeekNamedPipe ((HANDLE) _get_osfhandle (fdes), NULL, 0, 
+                              NULL, NULL, NULL) ? O_RDONLY : O_WRONLY;
       /* stdin ? */
-      else if (fdes == 0 && isatty (fdes))
+      else if (fdes == fileno (stdin) && isatty (fdes))
        flags = O_RDONLY;
       /* stdout / stderr ? */
-      else if ((fdes == 1 || fdes == 2) && isatty (fdes))
+      else if ((fdes == fileno (stdout) || fdes == fileno (stderr)) && 
+              isatty (fdes))
        flags = O_WRONLY;
       else
        flags = buf.st_mode;