OSDN Git Service

* unix.c (stream_at_bof): Don't assume that all non-mmapped files
[pf3gnuchains/gcc-fork.git] / libgfortran / io / unix.c
index 2d8286c..1158458 100644 (file)
@@ -1,4 +1,5 @@
-/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2003, 2004, 2005
+   Free Software Foundation, Inc.
    Contributed by Andy Vaught
 
 This file is part of the GNU Fortran 95 runtime library (libgfortran).
    Contributed by Andy Vaught
 
 This file is part of the GNU Fortran 95 runtime library (libgfortran).
@@ -153,26 +154,22 @@ move_pos_offset (stream* st, int pos_off)
   unix_stream * str = (unix_stream*)st;
   if (pos_off < 0)
     {
   unix_stream * str = (unix_stream*)st;
   if (pos_off < 0)
     {
-      str->active  += pos_off;
-      if (str->active < 0)
-         str->active = 0;
+      str->logical_offset += pos_off;
 
 
-      str->logical_offset  += pos_off;
-
-      if (str->dirty_offset+str->ndirty > str->logical_offset)
+      if (str->dirty_offset + str->ndirty > str->logical_offset)
         {
         {
-          if (str->ndirty +  pos_off > 0)
-            str->ndirty += pos_off ;
+          if (str->ndirty + pos_off > 0)
+            str->ndirty += pos_off;
           else
             {
               str->dirty_offset +=  pos_off + pos_off;
           else
             {
               str->dirty_offset +=  pos_off + pos_off;
-              str->ndirty = 0 ;
+              str->ndirty = 0;
             }
         }
 
             }
         }
 
-    return pos_off ;
+    return pos_off;
   }
   }
-  return 0 ;
+  return 0;
 }
 
 
 }
 
 
@@ -329,7 +326,8 @@ fd_flush (unix_stream * s)
  * to come next. */
 
 static void
  * to come next. */
 
 static void
-fd_alloc (unix_stream * s, gfc_offset where, int *len)
+fd_alloc (unix_stream * s, gfc_offset where,
+         int *len __attribute__ ((unused)))
 {
   char *new_buffer;
   int n, read_len;
 {
   char *new_buffer;
   int n, read_len;
@@ -540,8 +538,11 @@ fd_close (unix_stream * s)
   if (s->buffer != NULL && s->buffer != s->small_buffer)
     free_mem (s->buffer);
 
   if (s->buffer != NULL && s->buffer != s->small_buffer)
     free_mem (s->buffer);
 
-  if (close (s->fd) < 0)
-    return FAILURE;
+  if (s->fd != STDOUT_FILENO && s->fd != STDERR_FILENO)
+    {
+      if (close (s->fd) < 0)
+        return FAILURE;
+    }
 
   free_mem (s);
 
 
   free_mem (s);
 
@@ -606,7 +607,8 @@ mmap_flush (unix_stream * s)
  * guaranteed to be mappable. */
 
 static try
  * guaranteed to be mappable. */
 
 static try
-mmap_alloc (unix_stream * s, gfc_offset where, int *len)
+mmap_alloc (unix_stream * s, gfc_offset where,
+           int *len __attribute__ ((unused)))
 {
   gfc_offset offset;
   int length;
 {
   gfc_offset offset;
   int length;
@@ -711,7 +713,7 @@ mmap_close (unix_stream * s)
 
 
 static try
 
 
 static try
-mmap_sfree (unix_stream * s)
+mmap_sfree (unix_stream * s __attribute__ ((unused)))
 {
   return SUCCESS;
 }
 {
   return SUCCESS;
 }
@@ -721,7 +723,7 @@ mmap_sfree (unix_stream * s)
  * mmap()-ed, we fall back to the file descriptor functions. */
 
 static try
  * mmap()-ed, we fall back to the file descriptor functions. */
 
 static try
-mmap_open (unix_stream * s)
+mmap_open (unix_stream * s __attribute__ ((unused)))
 {
   char *p;
   int i;
 {
   char *p;
   int i;
@@ -827,7 +829,7 @@ mem_seek (unix_stream * s, gfc_offset offset)
 
 
 static int
 
 
 static int
-mem_truncate (unix_stream * s)
+mem_truncate (unix_stream * s __attribute__ ((unused)))
 {
   return SUCCESS;
 }
 {
   return SUCCESS;
 }
@@ -843,7 +845,7 @@ mem_close (unix_stream * s)
 
 
 static try
 
 
 static try
-mem_sfree (unix_stream * s)
+mem_sfree (unix_stream * s __attribute__ ((unused)))
 {
   return SUCCESS;
 }
 {
   return SUCCESS;
 }
@@ -1296,10 +1298,10 @@ stream_at_bof (stream * s)
 {
   unix_stream *us;
 
 {
   unix_stream *us;
 
-  us = (unix_stream *) s;
+  if (!is_seekable (s))
+    return 0;
 
 
-  if (!us->mmaped)
-    return 0;                  /* File is not seekable */
+  us = (unix_stream *) s;
 
   return us->logical_offset == 0;
 }
 
   return us->logical_offset == 0;
 }
@@ -1313,10 +1315,10 @@ stream_at_eof (stream * s)
 {
   unix_stream *us;
 
 {
   unix_stream *us;
 
-  us = (unix_stream *) s;
+  if (!is_seekable (s))
+    return 0;
 
 
-  if (!us->mmaped)
-    return 0;                  /* File is not seekable */
+  us = (unix_stream *) s;
 
   return us->logical_offset == us->dirty_offset;
 }
 
   return us->logical_offset == us->dirty_offset;
 }