]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/43409 (I/O: INQUIRE for SIZE does not work.)
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Sat, 20 Mar 2010 14:39:00 +0000 (14:39 +0000)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Sat, 20 Mar 2010 14:39:00 +0000 (14:39 +0000)
2010-03-20  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

PR fortran/43409
* ioparm.def: Change inquire size variable to type pointer to
GFC_IO_INT type.

2010-03-20  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

PR fortran/43409
* io/unix.h: Add prototype for new function to return file size.
* io/unix.c (file_size): New function.
* io/inquire.c (inquire_via_unit): Use new function.
(inquire_via_filename): Use new function.

From-SVN: r157593

gcc/fortran/ChangeLog
gcc/fortran/ioparm.def
libgfortran/ChangeLog
libgfortran/io/inquire.c
libgfortran/io/unix.c
libgfortran/io/unix.h

index dc155fa1574def7ed14092452217e8337ef592fa..d8a2d3ee7909a24c667b661d7d35fb5b95d2c663 100644 (file)
@@ -1,3 +1,9 @@
+2010-03-20  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       PR fortran/43409
+       * ioparm.def: Change inquire size variable to type pointer to
+       GFC_IO_INT type.
+
 2010-03-18  Paul Thomas  <pault@gcc.gnu.org>
 
         PR fortran/43039
index 7de7a5101dcb86381c13ce209c48f0e75d2f2545..ba1ba232b449a857a18d3febb1e8d5c642d30df4 100644 (file)
@@ -85,7 +85,7 @@ IOPARM (inquire, encoding,    1 << 2,  char1)
 IOPARM (inquire, round,                1 << 3,  char2)
 IOPARM (inquire, sign,         1 << 4,  char1)
 IOPARM (inquire, pending,      1 << 5,  pint4)
-IOPARM (inquire, size,         1 << 6,  pint4)
+IOPARM (inquire, size,         1 << 6,  pintio)
 IOPARM (inquire, id,           1 << 7,  pint4)
 IOPARM (wait,    common,       0,       common)
 IOPARM (wait,    id,           1 << 7,  pint4)
index 6f2198b48ad1c5833f67425239f0625fa8e3e0bb..7a80556532cd055b2ab32281246e17b1fc0bef57 100644 (file)
@@ -1,7 +1,15 @@
+2010-03-20  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       PR fortran/43409
+       * io/unix.h: Add prototype for new function to return file size.
+       * io/unix.c (file_size): New function.
+       * io/inquire.c (inquire_via_unit): Use new function.
+       (inquire_via_filename): Use new function.
+
 2010-03-17  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        * io/transfer.c (read_sf_internal): Remove stray function declaration
-       used during debigging.
+       used during debugging.
 
 2010-03-17  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
index c36b9e5fa69cd36a76f62e8e4a61bb28f609ab74..cd44c04251e4d99aa433bb7649d930f052868291 100644 (file)
@@ -371,6 +371,14 @@ inquire_via_unit (st_parameter_inquire *iqp, gfc_unit * u)
 
          cf_strcpy (iqp->round, iqp->round_len, p);
        }
+
+      if ((cf2 & IOPARM_INQUIRE_HAS_SIZE) != 0)
+       {
+         if (u == NULL)
+           *iqp->size = -1;
+         else
+           *iqp->size = file_size (u->file, (gfc_charlen_type) u->file_len);
+       }
     }
 
   if ((cf & IOPARM_INQUIRE_HAS_POSITION) != 0)
@@ -601,6 +609,9 @@ inquire_via_filename (st_parameter_inquire *iqp)
   
       if ((cf2 & IOPARM_INQUIRE_HAS_ENCODING) != 0)
        cf_strcpy (iqp->encoding, iqp->encoding_len, undefined);
+
+      if ((cf2 & IOPARM_INQUIRE_HAS_SIZE) != 0)
+       *iqp->size = file_size (iqp->file, iqp->file_len);
     }
 
   if ((cf & IOPARM_INQUIRE_HAS_POSITION) != 0)
index bd2b6594d52ee8bd1d2d4baf4758922f5bda7adf..4435674b46d76499e63b102414ce64c71c2d8dbb 100644 (file)
@@ -1475,6 +1475,22 @@ file_exists (const char *file, gfc_charlen_type file_len)
 }
 
 
+/* file_size()-- Returns the size of the file.  */
+
+GFC_IO_INT
+file_size (const char *file, gfc_charlen_type file_len)
+{
+  char path[PATH_MAX + 1];
+  gfstat_t statbuf;
+
+  if (unpack_filename (path, file, file_len))
+    return -1;
+
+  if (stat (path, &statbuf) < 0)
+    return -1;
+
+  return (GFC_IO_INT) statbuf.st_size;
+}
 
 static const char yes[] = "YES", no[] = "NO", unknown[] = "UNKNOWN";
 
index e691982e505d96778757f60568c3ce2e3bd40dd3..e567fdfe205241d7c33695293585bf6ba9711ea1 100644 (file)
@@ -121,6 +121,9 @@ internal_proto(delete_file);
 extern int file_exists (const char *file, gfc_charlen_type file_len);
 internal_proto(file_exists);
 
+extern GFC_IO_INT file_size (const char *file, gfc_charlen_type file_len);
+internal_proto(file_size);
+
 extern const char *inquire_sequential (const char *, int);
 internal_proto(inquire_sequential);