blob: d8b5f9aa8a14090ca9bfdbbef192f73bda258a40 [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001From 540d80469e6a7dce6baf7214df90e86daffc5175 Mon Sep 17 00:00:00 2001
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002From: Fan Xin <fan.xin@jp.fujitsu.com>
3Date: Mon, 5 Jun 2017 13:26:38 +0900
Brad Bishop6e60e8b2018-02-01 10:27:11 -05004Subject: [PATCH] aslfiles.c: manipulate fds instead of FILE
5
6Copying what stdout/stderr point to is not portable and fails with
7musl because FILE is an undefined struct.
8
9Instead, use lower-level Unix functions to modify the file that stderr
10writes into. This works on the platforms that Yocto targets.
11
12Upstream-Status: Inappropriate [embedded specific]
13
14Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050015
Brad Bishopd7bf8c12018-02-25 22:55:05 -050016Rebase on acpica 20170303
17
18Signed-off-by: Fan Xin <fan.xin@jp.fujitsu.com>
Brad Bishopd7bf8c12018-02-25 22:55:05 -050019
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080020---
21 source/compiler/aslfiles.c | 15 ++++++++++++---
22 1 file changed, 12 insertions(+), 3 deletions(-)
23
24diff --git a/source/compiler/aslfiles.c b/source/compiler/aslfiles.c
25index 82865db..cc072dc 100644
26--- a/source/compiler/aslfiles.c
27+++ b/source/compiler/aslfiles.c
28@@ -43,6 +43,11 @@
29
Brad Bishop6e60e8b2018-02-01 10:27:11 -050030 #include "aslcompiler.h"
31 #include "acapps.h"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080032+#include "dtcompiler.h"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050033+#include <sys/types.h>
34+#include <sys/stat.h>
35+#include <fcntl.h>
36+#include <unistd.h>
Brad Bishopd7bf8c12018-02-25 22:55:05 -050037
Brad Bishop6e60e8b2018-02-01 10:27:11 -050038 #define _COMPONENT ACPI_COMPILER
39 ACPI_MODULE_NAME ("aslfiles")
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080040@@ -606,6 +611,8 @@ FlOpenMiscOutputFiles (
Brad Bishop6e60e8b2018-02-01 10:27:11 -050041
42 if (Gbl_DebugFlag)
43 {
Brad Bishopd7bf8c12018-02-25 22:55:05 -050044+ int fd;
Brad Bishop6e60e8b2018-02-01 10:27:11 -050045+
46 Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG);
47 if (!Filename)
48 {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080049@@ -617,10 +624,10 @@ FlOpenMiscOutputFiles (
Brad Bishopd7bf8c12018-02-25 22:55:05 -050050 /* Open the debug file as STDERR, text mode */
Brad Bishop6e60e8b2018-02-01 10:27:11 -050051
52 Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename;
53- Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle =
54- freopen (Filename, "w+t", stderr);
Brad Bishopd7bf8c12018-02-25 22:55:05 -050055
Brad Bishop6e60e8b2018-02-01 10:27:11 -050056- 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 Bishopd7bf8c12018-02-25 22:55:05 -050061 /*
62 * A problem with freopen is that on error, we no longer
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080063@@ -634,6 +641,8 @@ FlOpenMiscOutputFiles (
Brad Bishopd7bf8c12018-02-25 22:55:05 -050064 exit (1);
Brad Bishop6e60e8b2018-02-01 10:27:11 -050065 }
Brad Bishop6e60e8b2018-02-01 10:27:11 -050066
Brad Bishopd7bf8c12018-02-25 22:55:05 -050067+ Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle = stderr;
68+
Brad Bishop6e60e8b2018-02-01 10:27:11 -050069 AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT);
70 AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT);
Brad Bishopd7bf8c12018-02-25 22:55:05 -050071 }