From 10375f38cec7e121a602f2d39f212169ffbfe4bf Mon Sep 17 00:00:00 2001 From: Akira Kakuto Date: Sat, 21 Oct 2017 10:30:18 +0000 Subject: openclose.c: If opened fname is a directory in output_directory, discard it in Unix platforms. git-svn-id: svn://tug.org/texlive/trunk@45565 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/texk/web2c/lib/ChangeLog | 9 +++++++++ Build/source/texk/web2c/lib/openclose.c | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) (limited to 'Build/source/texk/web2c/lib') diff --git a/Build/source/texk/web2c/lib/ChangeLog b/Build/source/texk/web2c/lib/ChangeLog index 96160bd4078..7875fda5b35 100644 --- a/Build/source/texk/web2c/lib/ChangeLog +++ b/Build/source/texk/web2c/lib/ChangeLog @@ -1,3 +1,12 @@ +2017-10-21 Akira Kakuto + + * openclose.c: If opened fname is a directory in + output_directory, discard it in Unix platforms. + In windows, fopen (fname, mode) is always NULL, in the case + where fname is a directory, thus it is discarded automatically. + Thanks to Hironobu Yamashita for the information: + http://tug.org/pipermail/tex-live/2017-October/040735.html. + 2017-09-05 Karl Berry and Akira Kakuto 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 #endif +#if !defined(_WIN32) +#include +#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); -- cgit v1.2.3