Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1 | From 540d80469e6a7dce6baf7214df90e86daffc5175 Mon Sep 17 00:00:00 2001 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2 | From: Fan Xin <fan.xin@jp.fujitsu.com> |
| 3 | Date: Mon, 5 Jun 2017 13:26:38 +0900 |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 4 | Subject: [PATCH] aslfiles.c: manipulate fds instead of FILE |
| 5 | |
| 6 | Copying what stdout/stderr point to is not portable and fails with |
| 7 | musl because FILE is an undefined struct. |
| 8 | |
| 9 | Instead, use lower-level Unix functions to modify the file that stderr |
| 10 | writes into. This works on the platforms that Yocto targets. |
| 11 | |
| 12 | Upstream-Status: Inappropriate [embedded specific] |
| 13 | |
| 14 | Signed-off-by: Patrick Ohly <patrick.ohly@intel.com> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 15 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 16 | Rebase on acpica 20170303 |
| 17 | |
| 18 | Signed-off-by: Fan Xin <fan.xin@jp.fujitsu.com> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 19 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 20 | --- |
| 21 | source/compiler/aslfiles.c | 15 ++++++++++++--- |
| 22 | 1 file changed, 12 insertions(+), 3 deletions(-) |
| 23 | |
| 24 | diff --git a/source/compiler/aslfiles.c b/source/compiler/aslfiles.c |
| 25 | index 82865db..cc072dc 100644 |
| 26 | --- a/source/compiler/aslfiles.c |
| 27 | +++ b/source/compiler/aslfiles.c |
| 28 | @@ -43,6 +43,11 @@ |
| 29 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 30 | #include "aslcompiler.h" |
| 31 | #include "acapps.h" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 32 | +#include "dtcompiler.h" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 33 | +#include <sys/types.h> |
| 34 | +#include <sys/stat.h> |
| 35 | +#include <fcntl.h> |
| 36 | +#include <unistd.h> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 37 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 38 | #define _COMPONENT ACPI_COMPILER |
| 39 | ACPI_MODULE_NAME ("aslfiles") |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 40 | @@ -606,6 +611,8 @@ FlOpenMiscOutputFiles ( |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 41 | |
| 42 | if (Gbl_DebugFlag) |
| 43 | { |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 44 | + int fd; |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 45 | + |
| 46 | Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG); |
| 47 | if (!Filename) |
| 48 | { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 49 | @@ -617,10 +624,10 @@ FlOpenMiscOutputFiles ( |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 50 | /* Open the debug file as STDERR, text mode */ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 51 | |
| 52 | Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename; |
| 53 | - Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle = |
| 54 | - freopen (Filename, "w+t", stderr); |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 55 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 56 | - if (!Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle) |
| 57 | + fd = open(Filename, O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); |
| 58 | + if (fd < 0 || |
| 59 | + dup2(fd, fileno(stderr))) |
| 60 | { |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 61 | /* |
| 62 | * A problem with freopen is that on error, we no longer |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 63 | @@ -634,6 +641,8 @@ FlOpenMiscOutputFiles ( |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 64 | exit (1); |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 65 | } |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 66 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 67 | + Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle = stderr; |
| 68 | + |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 69 | AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT); |
| 70 | AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT); |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 71 | } |