summaryrefslogtreecommitdiff
path: root/source/tools/acpidump/apfiles.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/tools/acpidump/apfiles.c')
-rw-r--r--source/tools/acpidump/apfiles.c89
1 files changed, 57 insertions, 32 deletions
diff --git a/source/tools/acpidump/apfiles.c b/source/tools/acpidump/apfiles.c
index 1588f2ef74ca..6633ce904002 100644
--- a/source/tools/acpidump/apfiles.c
+++ b/source/tools/acpidump/apfiles.c
@@ -45,6 +45,36 @@
#include "acapps.h"
+/* Local prototypes */
+
+static int
+ApIsExistingFile (
+ char *Pathname);
+
+
+static int
+ApIsExistingFile (
+ char *Pathname)
+{
+#ifndef _GNU_EFI
+ struct stat StatInfo;
+
+
+ if (!stat (Pathname, &StatInfo))
+ {
+ AcpiLogError ("Target path already exists, overwrite? [y|n] ");
+
+ if (getchar () != 'y')
+ {
+ return (-1);
+ }
+ }
+#endif
+
+ return 0;
+}
+
+
/******************************************************************************
*
* FUNCTION: ApOpenOutputFile
@@ -62,28 +92,22 @@ int
ApOpenOutputFile (
char *Pathname)
{
- struct stat StatInfo;
- FILE *File;
+ ACPI_FILE File;
/* If file exists, prompt for overwrite */
- if (!stat (Pathname, &StatInfo))
+ if (ApIsExistingFile (Pathname) != 0)
{
- fprintf (stderr, "Target path already exists, overwrite? [y|n] ");
-
- if (getchar () != 'y')
- {
- return (-1);
- }
+ return (-1);
}
/* Point stdout to the file */
- File = freopen (Pathname, "w", stdout);
+ File = AcpiOsOpenFile (Pathname, ACPI_FILE_WRITING);
if (!File)
{
- perror ("Could not open output file");
+ AcpiLogError ("Could not open output file: %s\n", Pathname);
return (-1);
}
@@ -116,7 +140,7 @@ ApWriteToBinaryFile (
{
char Filename[ACPI_NAME_SIZE + 16];
char InstanceStr [16];
- FILE *File;
+ ACPI_FILE File;
size_t Actual;
UINT32 TableLength;
@@ -145,37 +169,38 @@ ApWriteToBinaryFile (
if (Instance > 0)
{
- sprintf (InstanceStr, "%u", Instance);
- strcat (Filename, InstanceStr);
+ AcpiUtSnprintf (InstanceStr, sizeof (InstanceStr), "%u", Instance);
+ ACPI_STRCAT (Filename, InstanceStr);
}
- strcat (Filename, ACPI_TABLE_FILE_SUFFIX);
+ ACPI_STRCAT (Filename, ACPI_TABLE_FILE_SUFFIX);
if (Gbl_VerboseMode)
{
- fprintf (stderr,
+ AcpiLogError (
"Writing [%4.4s] to binary file: %s 0x%X (%u) bytes\n",
Table->Signature, Filename, Table->Length, Table->Length);
}
/* Open the file and dump the entire table in binary mode */
- File = fopen (Filename, "wb");
+ File = AcpiOsOpenFile (Filename,
+ ACPI_FILE_WRITING | ACPI_FILE_BINARY);
if (!File)
{
- perror ("Could not open output file");
+ AcpiLogError ("Could not open output file: %s\n", Filename);
return (-1);
}
- Actual = fwrite (Table, 1, TableLength, File);
+ Actual = AcpiOsWriteFile (File, Table, 1, TableLength);
if (Actual != TableLength)
{
- perror ("Error writing binary output file");
- fclose (File);
+ AcpiLogError ("Error writing binary output file: %s\n", Filename);
+ AcpiOsCloseFile (File);
return (-1);
}
- fclose (File);
+ AcpiOsCloseFile (File);
return (0);
}
@@ -199,17 +224,17 @@ ApGetTableFromFile (
UINT32 *OutFileSize)
{
ACPI_TABLE_HEADER *Buffer = NULL;
- FILE *File;
+ ACPI_FILE File;
UINT32 FileSize;
size_t Actual;
/* Must use binary mode */
- File = fopen (Pathname, "rb");
+ File = AcpiOsOpenFile (Pathname, ACPI_FILE_READING | ACPI_FILE_BINARY);
if (!File)
{
- perror ("Could not open input file");
+ AcpiLogError ("Could not open input file: %s\n", Pathname);
return (NULL);
}
@@ -218,29 +243,29 @@ ApGetTableFromFile (
FileSize = CmGetFileSize (File);
if (FileSize == ACPI_UINT32_MAX)
{
- fprintf (stderr,
+ AcpiLogError (
"Could not get input file size: %s\n", Pathname);
goto Cleanup;
}
/* Allocate a buffer for the entire file */
- Buffer = calloc (1, FileSize);
+ Buffer = ACPI_ALLOCATE_ZEROED (FileSize);
if (!Buffer)
{
- fprintf (stderr,
+ AcpiLogError (
"Could not allocate file buffer of size: %u\n", FileSize);
goto Cleanup;
}
/* Read the entire file */
- Actual = fread (Buffer, 1, FileSize, File);
+ Actual = AcpiOsReadFile (File, Buffer, 1, FileSize);
if (Actual != FileSize)
{
- fprintf (stderr,
+ AcpiLogError (
"Could not read input file: %s\n", Pathname);
- free (Buffer);
+ ACPI_FREE (Buffer);
Buffer = NULL;
goto Cleanup;
}
@@ -248,6 +273,6 @@ ApGetTableFromFile (
*OutFileSize = FileSize;
Cleanup:
- fclose (File);
+ AcpiOsCloseFile (File);
return (Buffer);
}