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]
Other format: [Raw text]

Re: [PATCH] Slightly revised libgfortran/io/unix.c fixes


Aaron W. LaFramboise wrote:

> This is a slight modification of the unapproved patch at
> <http://gcc.gnu.org/ml/gcc-patches/2004-10/msg01171.html>.  The only
> difference is that it includes a needed <stdio.h> that was missed in the
> last patch.

... And this is the patch.
2004-10-27  Aaron W. LaFramboise <aaronavay62@aaronwl.com>

	PR libfortran/18105
	* config.h.in: Regenerate.
	* configure: Regenerate.
	* configure.ac (AC_CHECK_FUNCS): Add mkstemp.
	* io/unix.c: Include <stdio.h>.
	(S_IRGRP): Define if undefined.
	(S_IWGRP): Same.
	(S_IROTH): Same.
	(S_IWOTH): Same.
	(tempfile): Use mktemp if mkstemp missing, fix typos.

Index: gcc/libgfortran/configure.ac
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/configure.ac,v
retrieving revision 1.11
diff -c -3 -p -r1.11 configure.ac
*** gcc/libgfortran/configure.ac	26 Sep 2004 14:52:03 -0000	1.11
--- gcc/libgfortran/configure.ac	27 Oct 2004 21:11:02 -0000
*************** AC_CHECK_HEADER([complex.h],[AC_DEFINE([
*** 159,165 ****
  AC_CHECK_LIB([m],[csin],[need_math="no"],[need_math="yes"])
  
  # Check for library functions.
! AC_CHECK_FUNCS(getrusage times)
  
  # Check libc for getgid, getpid, getuid
  AC_CHECK_LIB([c],[getgid],[AC_DEFINE([HAVE_GETGID],[1],[libc includes getgid])])
--- 159,165 ----
  AC_CHECK_LIB([m],[csin],[need_math="no"],[need_math="yes"])
  
  # Check for library functions.
! AC_CHECK_FUNCS(getrusage mkstemp times)
  
  # Check libc for getgid, getpid, getuid
  AC_CHECK_LIB([c],[getgid],[AC_DEFINE([HAVE_GETGID],[1],[libc includes getgid])])
Index: gcc/libgfortran/io/unix.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/io/unix.c,v
retrieving revision 1.11
diff -c -3 -p -r1.11 unix.c
*** gcc/libgfortran/io/unix.c	7 Oct 2004 21:30:50 -0000	1.11
--- gcc/libgfortran/io/unix.c	27 Oct 2004 21:11:04 -0000
*************** Boston, MA 02111-1307, USA.  */
*** 22,27 ****
--- 22,28 ----
  
  #include "config.h"
  #include <stdlib.h>
+ #include <stdio.h>
  #include <limits.h>
  
  #include <unistd.h>
*************** Boston, MA 02111-1307, USA.  */
*** 53,58 ****
--- 54,75 ----
  #define PROT_WRITE 2
  #endif
  
+ #ifndef S_IRGRP
+ #define S_IRGRP 0
+ #endif
+ 
+ #ifndef S_IWGRP
+ #define S_IWGRP 0
+ #endif
+ 
+ #ifndef S_IROTH
+ #define S_IROTH 0
+ #endif
+ 
+ #ifndef S_IWOTH
+ #define S_IWOTH 0
+ #endif
+ 
  /* This implementation of stream I/O is based on the paper:
   *
   *  "Exploiting the advantages of mapped files for stream I/O",
*************** unpack_filename (char *cstring, const ch
*** 920,927 ****
  /* tempfile()-- Generate a temporary filename for a scratch file and
   * open it.  mkstemp() opens the file for reading and writing, but the
   * library mode prevents anything that is not allowed.  The descriptor
!  * is returns, which is less than zero on error.  The template is
!  * pointed to by ioparm.file, which is copied into the unit structure
   * and freed later. */
  
  static int
--- 937,944 ----
  /* tempfile()-- Generate a temporary filename for a scratch file and
   * open it.  mkstemp() opens the file for reading and writing, but the
   * library mode prevents anything that is not allowed.  The descriptor
!  * is returned, which is -1 on error.  The template is pointed to by 
!  * ioparm.file, which is copied into the unit structure
   * and freed later. */
  
  static int
*************** tempfile (void)
*** 939,948 ****
  
    template = get_mem (strlen (tempdir) + 20);
  
!   st_sprintf (template, "%s/gfortantmpXXXXXX", tempdir);
  
    fd = mkstemp (template);
  
    if (fd < 0)
      free_mem (template);
    else
--- 956,978 ----
  
    template = get_mem (strlen (tempdir) + 20);
  
!   st_sprintf (template, "%s/gfortrantmpXXXXXX", tempdir);
! 
! #ifdef HAVE_MKSTEMP
  
    fd = mkstemp (template);
  
+ #else /* HAVE_MKSTEMP */
+ 
+   if (mktemp (template))
+     do
+       fd = open (template, O_CREAT | O_EXCL, S_IREAD | S_IWRITE);
+     while (!(fd == -1 && errno == EEXIST) && mktemp (template));
+   else
+     fd = -1;
+ 
+ #endif /* HAVE_MKSTEMP */
+ 
    if (fd < 0)
      free_mem (template);
    else

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