Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1 | From 69171c22f3872ecb4c1ab27985e93ca44084595e Mon Sep 17 00:00:00 2001 |
| 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> |
| 19 | --- |
| 20 | acpica-unix2-20170303/source/compiler/aslfiles.c | 14 +++++++++++--- |
| 21 | 1 file changed, 11 insertions(+), 3 deletions(-) |
| 22 | |
| 23 | diff --git a/acpica-unix2-20170303/source/compiler/aslfiles.c b/acpica-unix2-20170303/source/compiler/aslfiles.c |
| 24 | index 809090c..97898b1 100644 |
| 25 | --- a/acpica-unix2-20170303/source/compiler/aslfiles.c |
| 26 | +++ b/acpica-unix2-20170303/source/compiler/aslfiles.c |
| 27 | @@ -44,6 +44,10 @@ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 28 | #include "aslcompiler.h" |
| 29 | #include "acapps.h" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 30 | #include "dtcompiler.h" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 31 | +#include <sys/types.h> |
| 32 | +#include <sys/stat.h> |
| 33 | +#include <fcntl.h> |
| 34 | +#include <unistd.h> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 35 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 36 | #define _COMPONENT ACPI_COMPILER |
| 37 | ACPI_MODULE_NAME ("aslfiles") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 38 | @@ -607,6 +611,8 @@ FlOpenMiscOutputFiles ( |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 39 | |
| 40 | if (Gbl_DebugFlag) |
| 41 | { |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 42 | + int fd; |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 43 | + |
| 44 | Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG); |
| 45 | if (!Filename) |
| 46 | { |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 47 | @@ -618,10 +624,10 @@ FlOpenMiscOutputFiles ( |
| 48 | /* Open the debug file as STDERR, text mode */ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 49 | |
| 50 | Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename; |
| 51 | - Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle = |
| 52 | - freopen (Filename, "w+t", stderr); |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 53 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 54 | - if (!Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle) |
| 55 | + fd = open(Filename, O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); |
| 56 | + if (fd < 0 || |
| 57 | + dup2(fd, fileno(stderr))) |
| 58 | { |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 59 | /* |
| 60 | * A problem with freopen is that on error, we no longer |
| 61 | @@ -635,6 +641,8 @@ FlOpenMiscOutputFiles ( |
| 62 | exit (1); |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 63 | } |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 64 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 65 | + Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle = stderr; |
| 66 | + |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 67 | AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT); |
| 68 | AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT); |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 69 | } |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 70 | -- |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 71 | 1.9.1 |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 72 | |