From 698ca7249ffdbfe8d99757aea41ee97a96c3984f Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 11 Dec 2020 11:47:30 +0100 Subject: [PATCH] execute-tests: Fix compilation error on AIX in 32-bit mode. * tests/test-execute-child.c: In order to get the original definition of fstat, don't use '#undef fstat' and '#undef stat'. Instead, arrange to include the system's and use it before including other header files. --- ChangeLog | 8 ++++++++ tests/test-execute-child.c | 37 ++++++++++++++++++++++++++----------- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 19fd550771..9d72635863 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2020-12-11 Bruno Haible + + execute-tests: Fix compilation error on AIX in 32-bit mode. + * tests/test-execute-child.c: In order to get the original definition of + fstat, don't use '#undef fstat' and '#undef stat'. Instead, arrange to + include the system's and use it before including other + header files. + 2020-12-10 Bruno Haible windows-spawn: Relicense under LGPLv2+. diff --git a/tests/test-execute-child.c b/tests/test-execute-child.c index 8197c300de..16ccff7d60 100644 --- a/tests/test-execute-child.c +++ b/tests/test-execute-child.c @@ -14,8 +14,32 @@ You should have received a copy of the GNU General Public License along with this program; if not, see . */ +/* If the user's config.h happens to include , let it include only + the system's here. */ +#define __need_system_sys_stat_h #include +/* Get the original definition of fstat. It might be defined as a macro. + Also, 'stat' might be defined as a macro. */ +#include +#include +#undef __need_system_sys_stat_h + +/* Return non-zero if FD is opened to a device. */ +static int +is_device (int fd) +{ + struct stat st; + return +#if defined _WIN32 && ! defined __CYGWIN__ + _fstat (fd, &st) >= 0 +#else + fstat (fd, &st) >= 0 +#endif + && !S_ISREG (st.st_mode); +} + +/* Now include the other header files. */ #include #include #include @@ -23,7 +47,6 @@ #include #include #include -#include #if defined _WIN32 && ! defined __CYGWIN__ /* Get declarations of the native Windows API functions. */ @@ -40,13 +63,11 @@ #undef fgetc #undef fprintf #undef fputs -#undef fstat #undef getcwd #undef isatty #undef raise #undef read #undef sprintf -#undef stat #undef strcmp #undef strlen #undef write @@ -127,10 +148,7 @@ main (int argc, char *argv[]) /* Check stdout is inherited, part 2 (device). */ case 10: /* Check null_stdout = true. */ - { - struct stat st; - return !(fstat (STDOUT_FILENO, &st) >= 0 && !S_ISREG (st.st_mode)); - } + return !is_device (STDOUT_FILENO); case 11: /* Check stderr is inherited, part 1 (regular file). */ return !(fputs ("bar", stderr) != EOF && fflush (stderr) == 0); @@ -138,10 +156,7 @@ main (int argc, char *argv[]) /* Check stderr is inherited, part 2 (device). */ case 13: /* Check null_stderr = true. */ - { - struct stat st; - return !(fstat (STDERR_FILENO, &st) >= 0 && !S_ISREG (st.st_mode)); - } + return !is_device (STDERR_FILENO); case 14: case 15: /* Check file descriptors >= 3 can be inherited. */ -- 2.11.4.GIT