manipulate-fds-instead-of-FILE.patch 2.2 KB

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