From 30224c5e78aefeac1177e58d01936e49817eb92f Mon Sep 17 00:00:00 2001
From: Luigi Scarso <luigi.scarso@gmail.com>
Date: Sat, 30 Jul 2022 23:04:11 +0000
Subject: [PATCH] Fixed loading .tex when  --output-directory is enabled. Sync
 trunk with experimental.

[[Split portion of a mixed commit.]]
---
 source/texk/web2c/luatexdir/ChangeLog       |  3 +++
 source/texk/web2c/luatexdir/tex/texfileio.c | 13 ++++---------
 2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/source/texk/web2c/luatexdir/ChangeLog b/source/texk/web2c/luatexdir/ChangeLog
index 9454d04d5..d0be010ac 100644
--- a/source/texk/web2c/luatexdir/ChangeLog
+++ b/source/texk/web2c/luatexdir/ChangeLog
@@ -1,3 +1,6 @@
+2022-07-31  Luigi Scarso <luigi.scarso@gmail.com>
+    * Fixed loading .tex when  --output-directory is enabled
+
 2022-07-30  Luigi Scarso <luigi.scarso@gmail.com>
     * Backtrack replace pointer when successive disc in exceptions  (H.Hagen)
 
diff --git a/source/texk/web2c/luatexdir/tex/texfileio.c b/source/texk/web2c/luatexdir/tex/texfileio.c
index 8d8cdc043..83a76a21f 100644
--- a/source/texk/web2c/luatexdir/tex/texfileio.c
+++ b/source/texk/web2c/luatexdir/tex/texfileio.c
@@ -92,17 +92,12 @@ int read_file_callback_id[17];
 static char *find_in_output_directory(const char *s)
 {
     if (output_directory && !kpse_absolute_p(s, false)) {
-        FILE *f_ptr;
         char *ftemp = concat3(output_directory, DIR_SEP_STRING, s);
+	char *ret_val = NULL ;
         /*tex This code is used for input files only. */
-        f_ptr = fopen(ftemp, "rb");
-        if (f_ptr) {
-            fclose(f_ptr);
-            return ftemp;
-        } else {
-            free(ftemp);
-
-        }
+	ret_val = kpse_find_file(ftemp, kpse_tex_format, 1);
+	free(ftemp);
+	return ret_val;
     }
     return NULL;
 }
-- 
GitLab