summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Moore <Robert.Moore@intel.com>2014-02-14 09:17:16 -0800
committerRobert Moore <Robert.Moore@intel.com>2014-02-14 09:17:16 -0800
commitf2ad45360b6c8b656cc22d6344e2fe4d51bea9f4 (patch)
tree0809536f8d3e7a81f2841001d680ba4a73862052
parent56bcdb6f2bc69232effba09a82fd66450cae3226 (diff)
downloadacpica-f2ad45360b6c8b656cc22d6344e2fe4d51bea9f4.tar.gz
iASL: Add error handling to the internal get file size function.
Adds error checking and handling to the get file size function. ACPICA BZ 1050.
-rw-r--r--source/compiler/aslcompiler.h8
-rw-r--r--source/compiler/aslerror.c30
-rw-r--r--source/compiler/aslfileio.c113
3 files changed, 105 insertions, 46 deletions
diff --git a/source/compiler/aslcompiler.h b/source/compiler/aslcompiler.h
index 7960ef01c..49dc7fb7b 100644
--- a/source/compiler/aslcompiler.h
+++ b/source/compiler/aslcompiler.h
@@ -352,6 +352,10 @@ ApCheckRegMethod (
* aslerror - error handling/reporting
*/
void
+AslAbort (
+ void);
+
+void
AslError (
UINT8 Level,
UINT8 MessageId,
@@ -775,10 +779,6 @@ TrLinkPeerNodes (
* aslfiles - File I/O support
*/
void
-AslAbort (
- void);
-
-void
FlAddIncludeDirectory (
char *Dir);
diff --git a/source/compiler/aslerror.c b/source/compiler/aslerror.c
index e1f801519..21ca7d593 100644
--- a/source/compiler/aslerror.c
+++ b/source/compiler/aslerror.c
@@ -128,6 +128,36 @@ AeAddToErrorLog (
/*******************************************************************************
*
+ * FUNCTION: AslAbort
+ *
+ * PARAMETERS: None
+ *
+ * RETURN: None
+ *
+ * DESCRIPTION: Dump the error log and abort the compiler. Used for serious
+ * I/O errors.
+ *
+ ******************************************************************************/
+
+void
+AslAbort (
+ void)
+{
+
+ AePrintErrorLog (ASL_FILE_STDERR);
+ if (Gbl_DebugFlag)
+ {
+ /* Print error summary to stdout also */
+
+ AePrintErrorLog (ASL_FILE_STDOUT);
+ }
+
+ exit (1);
+}
+
+
+/*******************************************************************************
+ *
* FUNCTION: AeClearErrorLog
*
* PARAMETERS: None
diff --git a/source/compiler/aslfileio.c b/source/compiler/aslfileio.c
index b125c6166..50f15340d 100644
--- a/source/compiler/aslfileio.c
+++ b/source/compiler/aslfileio.c
@@ -118,35 +118,9 @@
#define _COMPONENT ACPI_COMPILER
ACPI_MODULE_NAME ("aslfileio")
-
-/*******************************************************************************
- *
- * FUNCTION: AslAbort
- *
- * PARAMETERS: None
- *
- * RETURN: None
- *
- * DESCRIPTION: Dump the error log and abort the compiler. Used for serious
- * I/O errors.
- *
- ******************************************************************************/
-
-void
-AslAbort (
- void)
-{
-
- AePrintErrorLog (ASL_FILE_STDERR);
- if (Gbl_DebugFlag)
- {
- /* Print error summary to stdout also */
-
- AePrintErrorLog (ASL_FILE_STDOUT);
- }
-
- exit (1);
-}
+long
+UtGetFileSize (
+ FILE *fp);
/*******************************************************************************
@@ -213,13 +187,73 @@ FlOpenFile (
/*******************************************************************************
*
+ * FUNCTION: UtGetFileSize
+ *
+ * PARAMETERS: fp - Open file handle
+ *
+ * RETURN: File Size. -1 on error.
+ *
+ * DESCRIPTION: Get current file size. Uses seek-to-EOF. File must be open.
+ * TBD: This function should be used to replace other similar
+ * functions in ACPICA.
+ *
+ ******************************************************************************/
+
+long
+UtGetFileSize (
+ FILE *fp)
+{
+ long FileSize;
+ long CurrentOffset;
+
+
+ CurrentOffset = ftell (fp);
+ if (CurrentOffset < 0)
+ {
+ goto OffsetError;
+ }
+
+ if (fseek (fp, 0, SEEK_END))
+ {
+ goto SeekError;
+ }
+
+ FileSize = ftell (fp);
+ if (FileSize < 0)
+ {
+ goto OffsetError;
+ }
+
+ /* Restore file pointer */
+
+ if (fseek (fp, CurrentOffset, SEEK_SET))
+ {
+ goto SeekError;
+ }
+
+ return (FileSize);
+
+
+OffsetError:
+ perror ("Could not get file offset");
+ return (-1);
+
+SeekError:
+ perror ("Could not seek file");
+ return (-1);
+}
+
+
+/*******************************************************************************
+ *
* FUNCTION: FlGetFileSize
*
* PARAMETERS: FileId - Index into file info array
*
* RETURN: File Size
*
- * DESCRIPTION: Get current file size. Uses seek-to-EOF. File must be open.
+ * DESCRIPTION: Get current file size. Uses common seek-to-EOF function.
+ * File must be open. Aborts compiler on error.
*
******************************************************************************/
@@ -227,21 +261,16 @@ UINT32
FlGetFileSize (
UINT32 FileId)
{
- FILE *fp;
- UINT32 FileSize;
- long Offset;
-
+ long FileSize;
- fp = Gbl_Files[FileId].Handle;
- Offset = ftell (fp);
- fseek (fp, 0, SEEK_END);
- FileSize = (UINT32) ftell (fp);
-
- /* Restore file pointer */
+ FileSize = UtGetFileSize (Gbl_Files[FileId].Handle);
+ if (FileSize == -1)
+ {
+ AslAbort();
+ }
- fseek (fp, Offset, SEEK_SET);
- return (FileSize);
+ return ((UINT32) FileSize);
}