diff options
author | Lv Zheng <lv.zheng@intel.com> | 2014-07-07 22:07:19 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2014-07-08 08:22:26 -0400 |
commit | 3c9349c93712f68dc9fc4caadb2fc1b7c9407316 (patch) | |
tree | 98684dea66a38606bbc05ba19190c20c89ab0277 /tools/power/acpi | |
parent | d9cf147dbd9cef05fa08bcc1dda9b2d14d9fe567 (diff) |
ACPICA: Common: Enhance cm_get_file_size() to improve portability
This patch uses abstract file IO and acpi_log_error() APIs to enhance
cm_get_file_size() so that applications that invoke this API could have
portability improved.
With actual references added to abstract file IO and acpi_log_error(), the
applications need to link oslibcfs.o, utdebug.o, utexcep.o, utmath.o,
utprint.o and utxferror.o.
It is also required to add acpi_os_initialize() invocations if an
application starts to use acpi_log_error().
acpidump has already invoked acpi_os_initialize() in this way. 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>
Diffstat (limited to 'tools/power/acpi')
-rw-r--r-- | tools/power/acpi/Makefile | 3 | ||||
-rw-r--r-- | tools/power/acpi/common/cmfsize.c | 20 |
2 files changed, 14 insertions, 9 deletions
diff --git a/tools/power/acpi/Makefile b/tools/power/acpi/Makefile index f88a251863c5..3d1537b93c64 100644 --- a/tools/power/acpi/Makefile +++ b/tools/power/acpi/Makefile | |||
@@ -112,11 +112,14 @@ DUMP_OBJS = \ | |||
112 | tbprint.o\ | 112 | tbprint.o\ |
113 | tbxfroot.o\ | 113 | tbxfroot.o\ |
114 | utbuffer.o\ | 114 | utbuffer.o\ |
115 | utdebug.o\ | ||
115 | utexcep.o\ | 116 | utexcep.o\ |
116 | utglobal.o\ | 117 | utglobal.o\ |
117 | utmath.o\ | 118 | utmath.o\ |
119 | utprint.o\ | ||
118 | utstring.o\ | 120 | utstring.o\ |
119 | utxferror.o\ | 121 | utxferror.o\ |
122 | oslibcfs.o\ | ||
120 | oslinuxtbl.o\ | 123 | oslinuxtbl.o\ |
121 | cmfsize.o\ | 124 | cmfsize.o\ |
122 | getopt.o | 125 | getopt.o |
diff --git a/tools/power/acpi/common/cmfsize.c b/tools/power/acpi/common/cmfsize.c index 5140e5edae1f..f4b953354ff7 100644 --- a/tools/power/acpi/common/cmfsize.c +++ b/tools/power/acpi/common/cmfsize.c | |||
@@ -58,44 +58,46 @@ ACPI_MODULE_NAME("cmfsize") | |||
58 | * RETURN: File Size. On error, -1 (ACPI_UINT32_MAX) | 58 | * RETURN: File Size. On error, -1 (ACPI_UINT32_MAX) |
59 | * | 59 | * |
60 | * DESCRIPTION: Get the size of a file. Uses seek-to-EOF. File must be open. | 60 | * DESCRIPTION: Get the size of a file. Uses seek-to-EOF. File must be open. |
61 | * Does not disturb the current file pointer. Uses perror for | 61 | * Does not disturb the current file pointer. |
62 | * error messages. | ||
63 | * | 62 | * |
64 | ******************************************************************************/ | 63 | ******************************************************************************/ |
65 | u32 cm_get_file_size(FILE * file) | 64 | u32 cm_get_file_size(ACPI_FILE file) |
66 | { | 65 | { |
67 | long file_size; | 66 | long file_size; |
68 | long current_offset; | 67 | long current_offset; |
68 | acpi_status status; | ||
69 | 69 | ||
70 | /* Save the current file pointer, seek to EOF to obtain file size */ | 70 | /* Save the current file pointer, seek to EOF to obtain file size */ |
71 | 71 | ||
72 | current_offset = ftell(file); | 72 | current_offset = acpi_os_get_file_offset(file); |
73 | if (current_offset < 0) { | 73 | if (current_offset < 0) { |
74 | goto offset_error; | 74 | goto offset_error; |
75 | } | 75 | } |
76 | 76 | ||
77 | if (fseek(file, 0, SEEK_END)) { | 77 | status = acpi_os_set_file_offset(file, 0, ACPI_FILE_END); |
78 | if (ACPI_FAILURE(status)) { | ||
78 | goto seek_error; | 79 | goto seek_error; |
79 | } | 80 | } |
80 | 81 | ||
81 | file_size = ftell(file); | 82 | file_size = acpi_os_get_file_offset(file); |
82 | if (file_size < 0) { | 83 | if (file_size < 0) { |
83 | goto offset_error; | 84 | goto offset_error; |
84 | } | 85 | } |
85 | 86 | ||
86 | /* Restore original file pointer */ | 87 | /* Restore original file pointer */ |
87 | 88 | ||
88 | if (fseek(file, current_offset, SEEK_SET)) { | 89 | status = acpi_os_set_file_offset(file, current_offset, ACPI_FILE_BEGIN); |
90 | if (ACPI_FAILURE(status)) { | ||
89 | goto seek_error; | 91 | goto seek_error; |
90 | } | 92 | } |
91 | 93 | ||
92 | return ((u32)file_size); | 94 | return ((u32)file_size); |
93 | 95 | ||
94 | offset_error: | 96 | offset_error: |
95 | perror("Could not get file offset"); | 97 | acpi_log_error("Could not get file offset"); |
96 | return (ACPI_UINT32_MAX); | 98 | return (ACPI_UINT32_MAX); |
97 | 99 | ||
98 | seek_error: | 100 | seek_error: |
99 | perror("Could not seek file"); | 101 | acpi_log_error("Could not set file offset"); |
100 | return (ACPI_UINT32_MAX); | 102 | return (ACPI_UINT32_MAX); |
101 | } | 103 | } |