]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR libfortran/23262
authorfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 7 Sep 2005 21:25:40 +0000 (21:25 +0000)
committerfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 7 Sep 2005 21:25:40 +0000 (21:25 +0000)
* acinclude.m4 (LIBGFOR_CHECK_CRLF): New check.
* configure.ac: Use new check.
* configure.in: Regenerate.
* config.h.in: Regenerate.
* configure: Regenerate.
* io/transfer.c (next_record_w): Add case for CRLF as line
terminator.
* io/unix.c (tempfile, regular_file): Open files with
O_BINARY on systems with CRLF.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@104009 138bc75d-0d04-0410-961f-82ee72b054a4

libgfortran/ChangeLog
libgfortran/acinclude.m4
libgfortran/config.h.in
libgfortran/configure
libgfortran/configure.ac
libgfortran/io/transfer.c
libgfortran/io/unix.c

index 8b2bb625a468a1bde21eebdd3d5a7b4c7904be44..d43be2e02c80b7d7d9f6f19bf429fbe01a1cc2ed 100644 (file)
@@ -1,3 +1,16 @@
+2005-09-07  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
+
+       PR libfortran/23262
+       * acinclude.m4 (LIBGFOR_CHECK_CRLF): New check.
+       * configure.ac: Use new check.
+       * configure.in: Regenerate.
+       * config.h.in: Regenerate.
+       * configure: Regenerate.
+       * io/transfer.c (next_record_w): Add case for CRLF as line
+       terminator.
+       * io/unix.c (tempfile, regular_file): Open files with
+       O_BINARY on systems with CRLF.
+
 2005-09-07  Steve Ellcey  <sje@cup.hp.com>
 
        PR libfortran/23419
index 4355d3a12fc87f6528eb4441de95df6ae02db531..f9fcca666598652be2df1647c89573b55ab65c02 100644 (file)
@@ -183,3 +183,50 @@ esac])])
 if test x"$have_unlink_open_file" = xyes; then
   AC_DEFINE(HAVE_UNLINK_OPEN_FILE, 1, [Define if target can unlink open files.])
 fi])
+
+dnl Check whether CRLF is the line terminator
+AC_DEFUN([LIBGFOR_CHECK_CRLF], [
+  AC_CACHE_CHECK([whether the target has CRLF as line terminator],
+                  have_crlf, [
+  AC_TRY_RUN([
+/* This test program should exit with status 0 if system uses a CRLF as
+   line terminator, and status 1 otherwise.  
+   Since it is used to check for mingw systems, and should return 0 in any
+   other case, in case of a failure we will not use CRLF.  */
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <stdio.h>
+
+int main ()
+{
+#ifndef O_BINARY
+  exit(1);
+#else
+  int fd, bytes;
+  char buff[5];
+
+  fd = open ("foo", O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
+  if (fd < 0)
+    exit(1);
+  if (write (fd, "\n", 1) < 0)
+    perror ("write");
+  
+  close (fd);
+  
+  if ((fd = open ("foo", O_RDONLY | O_BINARY, S_IRWXU)) < 0)
+    exit(1);
+  bytes = read (fd, buff, 5);
+  if (bytes == 2 && buff[0] == '\r' && buff[1] == '\n')
+    exit(0);
+  else
+    exit(1);
+#endif
+}], have_crlf=yes, have_crlf=no, [
+case "${target}" in
+  *mingw*) have_crlf=yes ;;
+  *) have_crlf=no;;
+esac])])
+if test x"$have_crlf" = xyes; then
+  AC_DEFINE(HAVE_CRLF, 1, [Define if CRLF is line terminator.])
+fi])
index bc110c9fffaf9a9dccc3628ccce6d251f08b50cb..923b2037ec254c1942212f9e1ab7dce8adc40dc0 100644 (file)
@@ -54,6 +54,9 @@
 /* libm includes coshf */
 #undef HAVE_COSHF
 
+/* Define if CRLF is line terminator. */
+#undef HAVE_CRLF
+
 /* libm includes erf */
 #undef HAVE_ERF
 
index 6b6df14c4f902771de4d84821579289a5d0dea99..74f922b95b365919e6131cfef7f71f5abaaba8c4 100755 (executable)
@@ -12300,6 +12300,96 @@ _ACEOF
 
 fi
 
+# Check whether line terminator is LF or CRLF
+
+  echo "$as_me:$LINENO: checking whether the target has CRLF as line terminator" >&5
+echo $ECHO_N "checking whether the target has CRLF as line terminator... $ECHO_C" >&6
+if test "${have_crlf+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+
+  if test "$cross_compiling" = yes; then
+
+case "${target}" in
+  *mingw*) have_crlf=yes ;;
+  *) have_crlf=no;;
+esac
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* This test program should exit with status 0 if system uses a CRLF as
+   line terminator, and status 1 otherwise.
+   Since it is used to check for mingw systems, and should return 0 in any
+   other case, in case of a failure we will not use CRLF.  */
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <stdio.h>
+
+int main ()
+{
+#ifndef O_BINARY
+  exit(1);
+#else
+  int fd, bytes;
+  char buff[5];
+
+  fd = open ("foo", O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
+  if (fd < 0)
+    exit(1);
+  if (write (fd, "\n", 1) < 0)
+    perror ("write");
+
+  close (fd);
+
+  if ((fd = open ("foo", O_RDONLY | O_BINARY, S_IRWXU)) < 0)
+    exit(1);
+  bytes = read (fd, buff, 5);
+  if (bytes == 2 && buff[0] == '\r' && buff[1] == '\n')
+    exit(0);
+  else
+    exit(1);
+#endif
+}
+_ACEOF
+rm -f conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  have_crlf=yes
+else
+  echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+have_crlf=no
+fi
+rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+fi
+echo "$as_me:$LINENO: result: $have_crlf" >&5
+echo "${ECHO_T}$have_crlf" >&6
+if test x"$have_crlf" = xyes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_CRLF 1
+_ACEOF
+
+fi
+
 cat >confcache <<\_ACEOF
 # This file is a shell script that caches the results of configure
 # tests run on this system so they can be shared between configure
index 8968d45bf3a498c0e450a50c8b4fad0c87d0d9de..f9f2b4d46ed34209dfcc4d2b64042007c796341c 100644 (file)
@@ -261,6 +261,9 @@ LIBGFOR_CHECK_ATTRIBUTE_ALIAS
 # Various other checks on target
 LIBGFOR_CHECK_UNLINK_OPEN_FILE
 
+# Check whether line terminator is LF or CRLF
+LIBGFOR_CHECK_CRLF
+
 AC_CACHE_SAVE
 
 if test ${multilib} = yes; then
index 59eb22d3dec1a2c218d227b746f667a8483299d4..9251cf8f24f3f69dd3d4c9beabbcbc3d9b25d065 100644 (file)
@@ -1422,13 +1422,24 @@ next_record_w (void)
       break;
 
     case FORMATTED_SEQUENTIAL:
+#ifdef HAVE_CRLF
+      length = 2;
+#else
       length = 1;
+#endif
       p = salloc_w (current_unit->s, &length);
 
       if (!is_internal_unit())
        {
          if (p)
-           *p = '\n'; /* No CR for internal writes.  */
+           {  /* No new line for internal writes.  */
+#ifdef HAVE_CRLF
+             p[0] = '\r';
+             p[1] = '\n';
+#else
+             *p = '\n';
+#endif
+           }
          else
            goto io_error;
        }
index 69101efff0433c44536025cffdf29300e25b87ae..87b839b6dd393ca6691b32b824bf271d3387d4bb 100644 (file)
@@ -1000,7 +1000,12 @@ tempfile (void)
 
   if (mktemp (template))
     do
+#ifdef HAVE_CRLF
+      fd = open (template, O_RDWR | O_CREAT | O_EXCL | O_BINARY,
+                 S_IREAD | S_IWRITE);
+#else
       fd = open (template, O_RDWR | O_CREAT | O_EXCL, S_IREAD | S_IWRITE);
+#endif
     while (!(fd == -1 && errno == EEXIST) && mktemp (template));
   else
     fd = -1;
@@ -1085,6 +1090,10 @@ regular_file (unit_flags *flags)
 
   /* rwflag |= O_LARGEFILE; */
 
+#ifdef HAVE_CRLF
+  crflag |= O_BINARY;
+#endif
+
   mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
   fd = open (path, rwflag | crflag, mode);
   if (flags->action != ACTION_UNSPECIFIED)