re PR fortran/43409 (I/O: INQUIRE for SIZE does not work.)

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

	PR fortran/43409
	Back port from trunk.
	* io/io.h: Fix type of size in st_parameter_inquire structure.
	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: r157847
This commit is contained in:
Jerry DeLisle 2010-03-31 02:00:51 +00:00
parent 48751b70e4
commit 7388f57e88
4 changed files with 41 additions and 1 deletions

View File

@ -1,3 +1,13 @@
2010-03-30 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR fortran/43409
Back port from trunk.
* io/io.h: Fix type of size in st_parameter_inquire structure.
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-29 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libfortran/43265

View File

@ -370,6 +370,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)
@ -600,6 +608,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)

View File

@ -368,7 +368,7 @@ typedef struct
CHARACTER2 (round);
CHARACTER1 (sign);
GFC_INTEGER_4 *pending;
GFC_INTEGER_4 *size;
GFC_IO_INT *size;
GFC_INTEGER_4 *id;
}
st_parameter_inquire;
@ -728,6 +728,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);

View File

@ -1396,6 +1396,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];
struct stat 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";