aboutsummaryrefslogtreecommitdiff
path: root/source/tools/acpibin/abcompare.c
diff options
context:
space:
mode:
authorJung-uk Kim <jkim@FreeBSD.org>2013-05-17 23:13:40 +0000
committerJung-uk Kim <jkim@FreeBSD.org>2013-05-17 23:13:40 +0000
commitb7f987c19dad2c6d33c64e7f96a9b4deca9e2650 (patch)
tree740dae2325e162bb086ea6e7e5d481c4b669e232 /source/tools/acpibin/abcompare.c
parentb4a951799e313e9ec15d955b72dd3097e4880724 (diff)
downloadsrc-b7f987c19dad2c6d33c64e7f96a9b4deca9e2650.tar.gz
src-b7f987c19dad2c6d33c64e7f96a9b4deca9e2650.zip
Notes
Diffstat (limited to 'source/tools/acpibin/abcompare.c')
-rw-r--r--source/tools/acpibin/abcompare.c71
1 files changed, 58 insertions, 13 deletions
diff --git a/source/tools/acpibin/abcompare.c b/source/tools/acpibin/abcompare.c
index 59fc9715cc11..dc21a4eaa83c 100644
--- a/source/tools/acpibin/abcompare.c
+++ b/source/tools/acpibin/abcompare.c
@@ -69,6 +69,10 @@ AbGetFile (
char *Filename,
UINT32 *FileSize);
+static UINT32
+AbGetFileSize (
+ FILE *File);
+
static void
AbPrintHeaderInfo (
ACPI_TABLE_HEADER *Header);
@@ -158,7 +162,7 @@ AbValidateHeader (
ACPI_TABLE_HEADER *Header)
{
- if (!AcpiUtValidAcpiName (* (UINT32 *) &Header->Signature))
+ if (!AcpiUtValidAcpiName (Header->Signature))
{
printf ("Header signature is invalid\n");
return (FALSE);
@@ -528,6 +532,42 @@ AbCompareAmlFiles (
/******************************************************************************
*
+ * FUNCTION: AbGetFileSize
+ *
+ * DESCRIPTION: Get the size of an open file
+ *
+ ******************************************************************************/
+
+static UINT32
+AbGetFileSize (
+ FILE *File)
+{
+ UINT32 FileSize;
+ long Offset;
+
+
+ Offset = ftell (File);
+
+ if (fseek (File, 0, SEEK_END))
+ {
+ return (0);
+ }
+
+ FileSize = (UINT32) ftell (File);
+
+ /* Restore file pointer */
+
+ if (fseek (File, Offset, SEEK_SET))
+ {
+ return (0);
+ }
+
+ return (FileSize);
+}
+
+
+/******************************************************************************
+ *
* FUNCTION: AbGetFile
*
* DESCRIPTION: Open a file and read it entirely into a new buffer
@@ -542,8 +582,6 @@ AbGetFile (
FILE *File;
UINT32 Size;
char *Buffer = NULL;
- int Seek1;
- int Seek2;
size_t Actual;
@@ -558,11 +596,8 @@ AbGetFile (
/* Need file size to allocate a buffer */
- Seek1 = fseek (File, 0L, SEEK_END);
- Size = ftell (File);
- Seek2 = fseek (File, 0L, SEEK_SET);
-
- if (Seek1 || Seek2 || (Size == -1))
+ Size = AbGetFileSize (File);
+ if (!Size)
{
printf ("Could not get file size (seek) for %s\n", Filename);
goto ErrorExit;
@@ -610,14 +645,20 @@ AbDumpAmlFile (
char *File2Path)
{
char *FileBuffer;
- UINT32 FileSize = 0;
FILE *FileOutHandle;
+ UINT32 FileSize = 0;
/* Get the entire AML file, validate header */
FileBuffer = AbGetFile (File1Path, &FileSize);
- printf ("File %s contains 0x%X bytes\n\n", File1Path, FileSize);
+ if (!FileBuffer)
+ {
+ return (-1);
+ }
+
+ printf ("Input file: %s contains %u (0x%X) bytes\n",
+ File1Path, FileSize, FileSize);
FileOutHandle = fopen (File2Path, "wb");
if (!FileOutHandle)
@@ -639,9 +680,13 @@ AbDumpAmlFile (
AcpiOsPrintf ("%4.4s @ 0x%8.8X\n",
((ACPI_TABLE_HEADER *) FileBuffer)->Signature, 0);
- AcpiDbgLevel = ACPI_UINT32_MAX;
- AcpiUtDebugDumpBuffer ((UINT8 *) FileBuffer, FileSize,
- DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
+ AcpiUtDumpBuffer ((UINT8 *) FileBuffer, FileSize, DB_BYTE_DISPLAY, 0);
+
+ /* Summary for the output file */
+
+ FileSize = AbGetFileSize (FileOutHandle);
+ printf ("Output file: %s contains %u (0x%X) bytes\n\n",
+ File2Path, FileSize, FileSize);
return (0);
}