aboutsummaryrefslogtreecommitdiff
path: root/libgfortran/acinclude.m4
diff options
context:
space:
mode:
authorFrancois-Xavier Coudert <coudert@clipper.ens.fr>2005-09-07 23:25:40 +0200
committerFrançois-Xavier Coudert <fxcoudert@gcc.gnu.org>2005-09-07 21:25:40 +0000
commit3c12752024a356b71760e09560f5ae6f430fca27 (patch)
tree077176970c902eb386a3e59797dc9538ca553d80 /libgfortran/acinclude.m4
parent2a0abeaf5523ab73d62cd6d84d78e34a25117ecd (diff)
downloadgcc-3c12752024a356b71760e09560f5ae6f430fca27.zip
gcc-3c12752024a356b71760e09560f5ae6f430fca27.tar.gz
gcc-3c12752024a356b71760e09560f5ae6f430fca27.tar.bz2
re PR libfortran/23262 ([mingw32] rewind truncates file)
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. From-SVN: r104009
Diffstat (limited to 'libgfortran/acinclude.m4')
-rw-r--r--libgfortran/acinclude.m447
1 files changed, 47 insertions, 0 deletions
diff --git a/libgfortran/acinclude.m4 b/libgfortran/acinclude.m4
index 4355d3a..f9fcca6 100644
--- a/libgfortran/acinclude.m4
+++ b/libgfortran/acinclude.m4
@@ -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])