This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[Fortran, committed]: Patch to have endfile.c use ftruncate if available.


L.S.,

I just committed the following:

2001-02-26  Toon Moene  <toon@moene.indiv.nluug.nl>

        * libI77/configure.in: Test for ftruncate.
        * libI77/configure: Rebuilt.
        * libI77/endfile.c: Use fflush/ftruncate when available.

*** configure.in.orig   Sat Feb 24 16:56:03 2001
--- configure.in        Mon Feb 26 17:51:07 2001
*************** else
*** 135,138 ****
--- 135,139 ----
  fi
  
+ AC_CHECK_FUNCS(ftruncate)
  AC_CHECK_FUNCS(mkstemp)
  AC_CHECK_FUNCS(tempnam)
*** endfile.c.orig      Sun Mar 12 20:20:47 2000
--- endfile.c   Mon Feb 26 17:53:23 2001
***************
*** 2,5 ****
--- 2,7 ----
  #include "fio.h"
  
+ #include <unistd.h>
+ 
  #ifdef KR_headers
  extern char *strcpy();
*************** integer f_end(alist *a)
*** 39,42 ****
--- 41,45 ----
  }
  
+ #ifndef HAVE_FTRUNCATE
   static int
  #ifdef KR_headers
*************** copy(FILE *from, register long len, FILE
*** 57,60 ****
--- 60,64 ----
        return 0;
        }
+ #endif /* !defined(HAVE_FTRUNCATE) */
  
   int
*************** t_runc(alist *a)
*** 67,72 ****
        long loc, len;
        unit *b;
!       FILE *bf, *tf;
!       int rc = 0;
  
        b = &f__units[a->aunit];
--- 71,79 ----
        long loc, len;
        unit *b;
!       int rc;
!       FILE *bf;
! #ifndef HAVE_FTRUNCATE
!       FILE *tf;
! #endif /* !defined(HAVE_FTRUNCATE) */
  
        b = &f__units[a->aunit];
*************** t_runc(alist *a)
*** 78,81 ****
--- 85,90 ----
        if (loc >= len || b->useek == 0 || b->ufnm == NULL)
                return(0);
+ #ifndef HAVE_FTRUNCATE
+       rc = 0;
        fclose(b->ufd);
        if (!loc) {
*************** done1:
*** 119,122 ****
--- 128,135 ----
  done:
        f__cf = b->ufd = bf;
+ #else  /* !defined(HAVE_FTRUNCATE) */
+       fflush(b->ufd);
+       rc = ftruncate(fileno(b->ufd),loc);
+ #endif /* !defined(HAVE_FTRUNCATE) */
        if (rc)
                err(a->aerr,111,"endfile");

With thanks to David M. Gay for the original code and Kaveh R. Ghazi for
his suggestions for improvement (without which it wouldn't work anyhow).

Mark, is it permitted to apply this change to the branch too ?

Cheers,

-- 
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands
Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
Join GNU Fortran 95: http://g95.sourceforge.net/ (under construction)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]