From da1495a11d8331fb8ae6d8b41661132adafad657 Mon Sep 17 00:00:00 2001 From: antona Date: Sat, 15 Oct 2005 21:48:37 +0000 Subject: [PATCH] Fix compilation on OSX in ntfscmp.c where stderr = stdout is not legal (but happens to work on Linux) to do portable low-level file descriptor mangling. --- ChangeLog | 6 +++--- ntfsprogs/ntfscmp.c | 15 +++++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 03e77e15..cdf35a96 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,9 +12,9 @@ xx/xx/2005 - 1.12.2-WIP - Fix silly bug introduced in 1.12.0 which breaks ntfsfix (and others possibly) when calling ntfs_attr_lookup() with AT_UNNAMED name and no ntfs inode in the search context. (Anton) - - Fix compilation on OSX in ntfsresize.c and ntfsclone.c where stderr = - stdout is not legal (but happens to work on Linux) to do proper - low-level file descriptor mangling which is portable. (Anton) + - Fix compilation on OSX in ntfsresize.c, ntfsclone.c, and ntfscmp.c + where stderr = stdout is not legal (but happens to work on Linux) to + do portable low-level file descriptor mangling. (Anton) - Add test/runlist-data to EXTRA_DIST so it gets included in the distribution otherwise make test fails on released sources. Solution is not perfect as it also adds the test/runlist-data/CVS directory diff --git a/ntfsprogs/ntfscmp.c b/ntfsprogs/ntfscmp.c index 95cd03db..13ab60bb 100644 --- a/ntfsprogs/ntfscmp.c +++ b/ntfsprogs/ntfscmp.c @@ -224,13 +224,20 @@ static void parse_options(int argc, char **argv) usage(); } - stderr = stdout; + /* Redirect stderr to stdout, note fflush()es are essential! */ + fflush(stdout); + fflush(stderr); + if (dup2(STDOUT_FILENO, STDERR_FILENO) == -1) { + perror("Failed to redirect stderr to stdout"); + exit(1); + } + fflush(stdout); + fflush(stderr); #ifdef DEBUG if (!opt.debug) - if (!(stderr = fopen("/dev/null", "rw"))) - perr_exit("Couldn't open /dev/null"); - + if (!freopen("/dev/null", "w", stderr)) + perr_exit("Failed to redirect stderr to /dev/null"); #endif }