summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/lib/openclose.c
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/web2c/lib/openclose.c')
-rw-r--r--Build/source/texk/web2c/lib/openclose.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/Build/source/texk/web2c/lib/openclose.c b/Build/source/texk/web2c/lib/openclose.c
index c5e1414ab3e..4ecf3827c93 100644
--- a/Build/source/texk/web2c/lib/openclose.c
+++ b/Build/source/texk/web2c/lib/openclose.c
@@ -12,6 +12,10 @@
#include <ptexenc/ptexenc.h>
#endif
+#if !defined(_WIN32)
+#include <sys/stat.h>
+#endif
+
#ifdef WIN32
#undef fopen
#undef xfopen
@@ -146,6 +150,14 @@ recorder_record_output (const_string name)
whether or not the open succeeded. If it did, `nameoffile' is set to
the full filename opened, and `namelength' to its length. */
+#if !defined(_WIN32)
+static int is_dirp (char *buff)
+{
+ struct stat stats;
+ return stat (buff, &stats) == 0 && S_ISDIR (stats.st_mode);
+}
+#endif
+
boolean
open_input (FILE **f_ptr, int filefmt, const_string fopen_mode)
{
@@ -173,6 +185,15 @@ open_input (FILE **f_ptr, int filefmt, const_string fopen_mode)
if (output_directory && !kpse_absolute_p (nameoffile+1, false)) {
fname = concat3 (output_directory, DIR_SEP_STRING, nameoffile + 1);
*f_ptr = fopen (fname, fopen_mode);
+#if !defined(_WIN32)
+/*
+ if fname is a directory, discard it.
+*/
+ if (*f_ptr && is_dirp (fname)) {
+ fclose (*f_ptr);
+ *f_ptr = NULL;
+ }
+#endif
if (*f_ptr) {
free (nameoffile);
namelength = strlen (fname);