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.
This commit is contained in:
Robert Moore 2014-02-14 09:17:16 -08:00
parent 56bcdb6f2b
commit f2ad45360b
3 changed files with 105 additions and 46 deletions

View File

@ -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);

View File

@ -126,6 +126,36 @@ AeAddToErrorLog (
ASL_ERROR_MSG *Enode);
/*******************************************************************************
*
* 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

View File

@ -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);
/*******************************************************************************
@ -211,6 +185,65 @@ 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
@ -219,7 +252,8 @@ FlOpenFile (
*
* 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);
FileSize = UtGetFileSize (Gbl_Files[FileId].Handle);
if (FileSize == -1)
{
AslAbort();
}
fseek (fp, 0, SEEK_END);
FileSize = (UINT32) ftell (fp);
/* Restore file pointer */
fseek (fp, Offset, SEEK_SET);
return (FileSize);
return ((UINT32) FileSize);
}