fstat returns wrong filesize

Alex Waugh alex at alexwaugh.com
Thu Aug 8 14:46:36 PDT 2002


Hi

Calling fstat often results in a wrong value being returned for the
filesize. This is because OS_File which is used to get the file info
returns the size allocated to the file, which (if the file is open at
the time) can be different to the extent of the file.
The following patch fixes this.


Index: unixlib/source/unix/fstat.c
===================================================================
RCS file: /usr/local/cvsroot/gccsdk/unixlib/source/unix/fstat.c,v
retrieving revision 1.2.2.1
diff -u -r1.2.2.1 fstat.c
--- unixlib/source/unix/fstat.c	4 Sep 2001 16:32:04 -0000	1.2.2.1
+++ unixlib/source/unix/fstat.c	8 Aug 2002 21:26:18 -0000
@@ -43,6 +43,7 @@
     {
       char *buffer;
       _kernel_oserror *err;
+      int argsregs[3];
 
       if (file_desc->dflag & FILE_ISDIR)
         buffer = ((DIR *) file_desc->handle)->dd_name_can;
@@ -62,6 +63,16 @@
 	}
       buf->st_ino = __get_file_ino (NULL, buffer);
       free (buffer);
+
+      /* __os_file returns the allocated size of the file,
+         but we want the current extent of the file */
+      err = __os_args(2, file_desc->handle, 0, argsregs);
+      if (err)
+        {
+          __seterr (err);
+          return __set_errno (EIO);
+        }
+      regs[4] = argsregs[2];
     }
   else
     {

-- 
Alex Waugh                               alex at alexwaugh.com

PHP, Roots, WebJames and more from http://www.alexwaugh.com/



More information about the gcc mailing list