]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
ACPICA: acpidump: Reduce freopen() invocations to improve portability
authorLv Zheng <lv.zheng@intel.com>
Tue, 8 Jul 2014 02:07:52 +0000 (10:07 +0800)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 8 Jul 2014 12:22:27 +0000 (14:22 +0200)
This patch reduces the requirement of invoking freopen() in acpidump in order
to reduce the porting effort of acpidump.

This patch achieves this by turning all acpi_os_printf(stdout) into
acpi_ut_file_printf(gbl_output_file). Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/acpi/acpica/acutils.h
drivers/acpi/acpica/utbuffer.c
tools/power/acpi/tools/acpidump/apdump.c
tools/power/acpi/tools/acpidump/apfiles.c
tools/power/acpi/tools/acpidump/apmain.c

index 035dc29798bbf74a78c793f717a6d5d91ddb3b63..ed614f4b218273f8b000ebc017d699e0d09ef141 100644 (file)
@@ -353,6 +353,13 @@ acpi_ut_debug_dump_buffer(u8 *buffer, u32 count, u32 display, u32 component_id);
 
 void acpi_ut_dump_buffer(u8 *buffer, u32 count, u32 display, u32 offset);
 
+#ifdef ACPI_APPLICATION
+void
+acpi_ut_dump_buffer_to_file(ACPI_FILE file,
+                           u8 *buffer,
+                           u32 count, u32 display, u32 base_offset);
+#endif
+
 void acpi_ut_report_error(char *module_name, u32 line_number);
 
 void acpi_ut_report_info(char *module_name, u32 line_number);
index 3c16997406535dc2e85445af0fd1b60cd0db2610..038ea887f56292c430bce8222697fde5cac243ee 100644 (file)
@@ -199,3 +199,131 @@ acpi_ut_debug_dump_buffer(u8 *buffer, u32 count, u32 display, u32 component_id)
 
        acpi_ut_dump_buffer(buffer, count, display, 0);
 }
+
+#ifdef ACPI_APPLICATION
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ut_dump_buffer_to_file
+ *
+ * PARAMETERS:  file                - File descriptor
+ *              buffer              - Buffer to dump
+ *              count               - Amount to dump, in bytes
+ *              display             - BYTE, WORD, DWORD, or QWORD display:
+ *                                      DB_BYTE_DISPLAY
+ *                                      DB_WORD_DISPLAY
+ *                                      DB_DWORD_DISPLAY
+ *                                      DB_QWORD_DISPLAY
+ *              base_offset         - Beginning buffer offset (display only)
+ *
+ * RETURN:      None
+ *
+ * DESCRIPTION: Generic dump buffer in both hex and ascii to a file.
+ *
+ ******************************************************************************/
+
+void
+acpi_ut_dump_buffer_to_file(ACPI_FILE file,
+                           u8 *buffer, u32 count, u32 display, u32 base_offset)
+{
+       u32 i = 0;
+       u32 j;
+       u32 temp32;
+       u8 buf_char;
+
+       if (!buffer) {
+               acpi_ut_file_printf(file,
+                                   "Null Buffer Pointer in DumpBuffer!\n");
+               return;
+       }
+
+       if ((count < 4) || (count & 0x01)) {
+               display = DB_BYTE_DISPLAY;
+       }
+
+       /* Nasty little dump buffer routine! */
+
+       while (i < count) {
+
+               /* Print current offset */
+
+               acpi_ut_file_printf(file, "%6.4X: ", (base_offset + i));
+
+               /* Print 16 hex chars */
+
+               for (j = 0; j < 16;) {
+                       if (i + j >= count) {
+
+                               /* Dump fill spaces */
+
+                               acpi_ut_file_printf(file, "%*s",
+                                                   ((display * 2) + 1), " ");
+                               j += display;
+                               continue;
+                       }
+
+                       switch (display) {
+                       case DB_BYTE_DISPLAY:
+                       default:        /* Default is BYTE display */
+
+                               acpi_ut_file_printf(file, "%02X ",
+                                                   buffer[(acpi_size) i + j]);
+                               break;
+
+                       case DB_WORD_DISPLAY:
+
+                               ACPI_MOVE_16_TO_32(&temp32,
+                                                  &buffer[(acpi_size) i + j]);
+                               acpi_ut_file_printf(file, "%04X ", temp32);
+                               break;
+
+                       case DB_DWORD_DISPLAY:
+
+                               ACPI_MOVE_32_TO_32(&temp32,
+                                                  &buffer[(acpi_size) i + j]);
+                               acpi_ut_file_printf(file, "%08X ", temp32);
+                               break;
+
+                       case DB_QWORD_DISPLAY:
+
+                               ACPI_MOVE_32_TO_32(&temp32,
+                                                  &buffer[(acpi_size) i + j]);
+                               acpi_ut_file_printf(file, "%08X", temp32);
+
+                               ACPI_MOVE_32_TO_32(&temp32,
+                                                  &buffer[(acpi_size) i + j +
+                                                          4]);
+                               acpi_ut_file_printf(file, "%08X ", temp32);
+                               break;
+                       }
+
+                       j += display;
+               }
+
+               /*
+                * Print the ASCII equivalent characters but watch out for the bad
+                * unprintable ones (printable chars are 0x20 through 0x7E)
+                */
+               acpi_ut_file_printf(file, " ");
+               for (j = 0; j < 16; j++) {
+                       if (i + j >= count) {
+                               acpi_ut_file_printf(file, "\n");
+                               return;
+                       }
+
+                       buf_char = buffer[(acpi_size) i + j];
+                       if (ACPI_IS_PRINT(buf_char)) {
+                               acpi_ut_file_printf(file, "%c", buf_char);
+                       } else {
+                               acpi_ut_file_printf(file, ".");
+                       }
+               }
+
+               /* Done with that line. */
+
+               acpi_ut_file_printf(file, "\n");
+               i += 16;
+       }
+
+       return;
+}
+#endif
index 34fa5f25be39658fe977e3e29d0e109c9b8fd86c..53cee781e24e646f98a041ff1906b1fb13158a3a 100644 (file)
@@ -195,12 +195,13 @@ ap_dump_table_buffer(struct acpi_table_header *table,
         * Note: simplest to just always emit a 64-bit address. acpi_xtract
         * utility can handle this.
         */
-       acpi_os_printf("%4.4s @ 0x%8.8X%8.8X\n", table->signature,
-                      ACPI_FORMAT_UINT64(address));
+       acpi_ut_file_printf(gbl_output_file, "%4.4s @ 0x%8.8X%8.8X\n",
+                           table->signature, ACPI_FORMAT_UINT64(address));
 
-       acpi_ut_dump_buffer(ACPI_CAST_PTR(u8, table), table_length,
-                           DB_BYTE_DISPLAY, 0);
-       acpi_os_printf("\n");
+       acpi_ut_dump_buffer_to_file(gbl_output_file,
+                                   ACPI_CAST_PTR(u8, table), table_length,
+                                   DB_BYTE_DISPLAY, 0);
+       acpi_ut_file_printf(gbl_output_file, "\n");
        return (0);
 }
 
index 5699ca1d0922d0f16ba479dc59087e0c4ee794a7..5781c13ae333e764c4f6c6827d73be376fe052f9 100644 (file)
@@ -60,7 +60,7 @@
 int ap_open_output_file(char *pathname)
 {
        struct stat stat_info;
-       FILE *file;
+       ACPI_FILE file;
 
        /* If file exists, prompt for overwrite */
 
@@ -74,9 +74,9 @@ int ap_open_output_file(char *pathname)
 
        /* Point stdout to the file */
 
-       file = freopen(pathname, "w", stdout);
+       file = acpi_os_open_file(pathname, ACPI_FILE_WRITING);
        if (!file) {
-               perror("Could not open output file");
+               acpi_log_error("Could not open output file: %s\n", pathname);
                return (-1);
        }
 
index 63f7bc9fdf2961cea11a0d869b9813f0acabec64..35bd6740306e448e042ca6e00b04f9b9442f2f5f 100644 (file)
@@ -300,6 +300,7 @@ int ACPI_SYSTEM_XFACE main(int argc, char *argv[])
 
        ACPI_DEBUG_INITIALIZE();        /* For debug version only */
        acpi_os_initialize();
+       gbl_output_file = ACPI_FILE_OUT;
 
        /* Process command line options */
 
@@ -348,7 +349,7 @@ int ACPI_SYSTEM_XFACE main(int argc, char *argv[])
                }
        }
 
-       if (gbl_output_file) {
+       if (gbl_output_filename) {
                if (gbl_verbose_mode) {
 
                        /* Summary for the output file */