[PATCH] algol68: Open source files in binary mode

Peter Damianov peter0x44@disroot.org
Sun May 24 18:59:46 GMT 2026


When building a source file with CRLF newlines on Windows, the CRLFs were
getting converted to LFs, so a86_file_read was returning "short" byte counts
and tripping an assert. Make sure files get opened in binary mode to avoid this.

gcc/algol68/ChangeLog:

	* a68-lang.cc (a68_handle_option): Open file in binary mode.
	* a68-parser-scanner.cc (read_source_file): Open file in binary mode.
	(include_files): Likewise.
---
 gcc/algol68/a68-lang.cc           | 2 +-
 gcc/algol68/a68-parser-scanner.cc | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/algol68/a68-lang.cc b/gcc/algol68/a68-lang.cc
index df9ef0abf11..0fa38c210e4 100644
--- a/gcc/algol68/a68-lang.cc
+++ b/gcc/algol68/a68-lang.cc
@@ -538,7 +538,7 @@ a68_handle_option (size_t scode,
     case OPT_fmodules_map_file:
     case OPT_fmodules_map_file_:
       {
-	FILE *file = fopen (arg, "r");
+	FILE *file = fopen (arg, "rb");
 	if (file == NULL)
 	  fatal_error (UNKNOWN_LOCATION,
 		       "cannot open modules map file %<%s%>", arg);
diff --git a/gcc/algol68/a68-parser-scanner.cc b/gcc/algol68/a68-parser-scanner.cc
index 097accd5322..4dcbc263a97 100644
--- a/gcc/algol68/a68-parser-scanner.cc
+++ b/gcc/algol68/a68-parser-scanner.cc
@@ -334,7 +334,7 @@ read_source_file (const char *filename)
   bool ret = true;
 
   /* First open the given file.  */
-  if (!(FILE_SOURCE_FD (&A68_JOB) = fopen (filename, "r")))
+  if (!(FILE_SOURCE_FD (&A68_JOB) = fopen (filename, "rb")))
     fatal_error (UNKNOWN_LOCATION, "could not open source file %s",
 		 filename);
   FILE_SOURCE_NAME (&A68_JOB) = ggc_strdup (filename);
@@ -1076,7 +1076,7 @@ include_files (LINE_T *top)
 	      t = NO_LINE;
 
 	      /* Access the file.  */
-	      fp = fopen (fn, "r");
+	      fp = fopen (fn, "rb");
 	      SCAN_ERROR (fp == NULL, start_l, start_c,
 			  "error opening included file");
 	      ssize = a68_file_size (fileno (fp));
-- 
2.54.0



More information about the Algol68 mailing list