This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[gfortran] MinGW uses chsize instead of ftruncate
- From: FranÃois-Xavier Coudert <Francois-Xavier dot Coudert at lcp dot u-psud dot fr>
- To: gfortran <fortran at gcc dot gnu dot org>, patch <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 29 Apr 2005 10:31:04 +0200
- Subject: [gfortran] MinGW uses chsize instead of ftruncate
This patch enables the libgfortran to be built using chsize instead of
ftruncate if the latter is not present in the system (which is the case of
MinGW).
Regtested on i386-linux and i386-mingw32. OK for mainline and 4.0?
FX
2005-04-29 Francois-Xavier Coudert <coudert@clipper.ens.fr>
* configure.ac: Check for ftruncate and chsize.
* io/unix.c (fd_truncate): Provide chsize as alternative to
ftruncate.
* config.h.in: Regenerate.
* configure: Regenerate.
Index: configure.ac
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/configure.ac,v
retrieving revision 1.23
diff -p -u -r1.23 configure.ac
--- configure.ac 7 Apr 2005 21:06:27 -0000 1.23
+++ configure.ac 29 Apr 2005 08:00:49 -0000
@@ -166,7 +166,7 @@ AC_CHECK_MEMBERS([struct stat.st_rdev])
AC_CHECK_LIB([m],[csin],[need_math="no"],[need_math="yes"])
# Check for library functions.
-AC_CHECK_FUNCS(getrusage times mkstemp strtof snprintf)
+AC_CHECK_FUNCS(getrusage times mkstemp strtof snprintf ftruncate chsize)
AC_CHECK_FUNCS(chdir strerror getlogin gethostname kill link symlink perror)
AC_CHECK_FUNCS(sleep time)
Index: io/unix.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/io/unix.c,v
retrieving revision 1.21
diff -p -u -r1.21 unix.c
--- io/unix.c 23 Jan 2005 00:14:31 -0000 1.21
+++ io/unix.c 29 Apr 2005 08:00:49 -0000
@@ -513,8 +513,15 @@ fd_truncate (unix_stream * s)
/* non-seekable files, like terminals and fifo's fail the lseek.
the fd is a regular file at this point */
+#ifdef HAVE_FTRUNCATE
if (ftruncate (s->fd, s->logical_offset))
return FAILURE;
+#else
+#ifdef HAVE_CHSIZE
+ if (chsize (s->fd, s->logical_offset))
+ return FAILURE;
+#endif
+#endif
s->physical_offset = s->file_length = s->logical_offset;