summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLv Zheng <lv.zheng@intel.com>2016-05-23 23:06:55 +0800
committerLv Zheng <lv.zheng@intel.com>2016-06-06 12:58:30 +0800
commit973f73ca34c168d62bcc84bb71ea3ea194001f0a (patch)
tree243d0d3f0b1a8c56ee65fc47d1626d484db164bf
parent17d2c00994f3e04d0b25dccb00220e69dc8bb443 (diff)
downloadacpica-973f73ca34c168d62bcc84bb71ea3ea194001f0a.tar.gz
Clib/EFI: Add fgetc()/fputc() to improve portability
This patch added two new Clibrary functions: fgetc()/fputc() for EFI environment, they are implemented using fread()/fwrite(). Note in this patch, stdin is simply defined as NULL for EFI environment. Its EFI support should be implemented by further patches. Signed-off-by: Lv Zheng <lv.zheng@intel.com>
-rw-r--r--source/include/acclib.h19
-rw-r--r--source/include/platform/acefi.h1
-rw-r--r--source/include/platform/acenv.h2
-rw-r--r--source/os_specific/service_layers/oseficlib.c70
4 files changed, 92 insertions, 0 deletions
diff --git a/source/include/acclib.h b/source/include/acclib.h
index 9f5853596..deaed5a5e 100644
--- a/source/include/acclib.h
+++ b/source/include/acclib.h
@@ -304,6 +304,10 @@ sprintf (
*/
extern int errno;
+#ifndef EOF
+#define EOF (-1)
+#endif
+
int
vprintf (
const char *Format,
@@ -358,6 +362,21 @@ fseek (
long
ftell (
FILE *File);
+
+int
+fgetc (
+ FILE *File);
+
+int
+fputc (
+ FILE *File,
+ char c);
+
+char *
+fgets (
+ char *s,
+ ACPI_SIZE Size,
+ FILE *File);
#endif
#endif /* _ACCLIB_H */
diff --git a/source/include/platform/acefi.h b/source/include/platform/acefi.h
index b251c1504..172fac47a 100644
--- a/source/include/platform/acefi.h
+++ b/source/include/platform/acefi.h
@@ -327,5 +327,6 @@ extern struct _EFI_BOOT_SERVICES *BS;
#define FILE struct _SIMPLE_TEXT_OUTPUT_INTERFACE
#define stdout ST->ConOut
#define stderr ST->ConOut
+#define stdin NULL
#endif /* __ACEFI_H__ */
diff --git a/source/include/platform/acenv.h b/source/include/platform/acenv.h
index 878be8c12..ead8a9af0 100644
--- a/source/include/platform/acenv.h
+++ b/source/include/platform/acenv.h
@@ -518,10 +518,12 @@ typedef char *va_list;
#define ACPI_FILE FILE *
#define ACPI_FILE_OUT stdout
#define ACPI_FILE_ERR stderr
+#define ACPI_FILE_IN stdin
#else
#define ACPI_FILE void *
#define ACPI_FILE_OUT NULL
#define ACPI_FILE_ERR NULL
+#define ACPI_FILE_IN NULL
#endif /* ACPI_APPLICATION */
#endif /* __ACENV_H__ */
diff --git a/source/os_specific/service_layers/oseficlib.c b/source/os_specific/service_layers/oseficlib.c
index 629e99d00..00b787447 100644
--- a/source/os_specific/service_layers/oseficlib.c
+++ b/source/os_specific/service_layers/oseficlib.c
@@ -335,6 +335,76 @@ fclose (
/*******************************************************************************
*
+ * FUNCTION: fgetc
+ *
+ * PARAMETERS: File - File descriptor
+ *
+ * RETURN: The character read or EOF on the end of the file or error
+ *
+ * DESCRIPTION: Read a character from the file.
+ *
+ ******************************************************************************/
+
+int
+fgetc (
+ FILE *File)
+{
+ UINT8 Byte;
+ int Length;
+
+
+ Length = fread (ACPI_CAST_PTR (void, &Byte), 1, 1, File);
+ if (Length == 0)
+ {
+ Length = EOF;
+ }
+ else if (Length == 1)
+ {
+ Length = (int) Byte;
+ }
+
+ return (Length);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION: fputc
+ *
+ * PARAMETERS: File - File descriptor
+ * c - Character byte
+ *
+ * RETURN: The character written or EOF on the end of the file or error
+ *
+ * DESCRIPTION: Write a character to the file.
+ *
+ ******************************************************************************/
+
+int
+fputc (
+ FILE *File,
+ char c)
+{
+ UINT8 Byte = (UINT8) c;
+ int Length;
+
+
+ Length = fwrite (ACPI_CAST_PTR (void, &Byte), 1, 1, File);
+ if (Length == 0)
+ {
+ Length = EOF;
+ }
+ else if (Length == 1)
+ {
+ Length = (int) Byte;
+ }
+
+ return (Length);
+}
+
+
+/*******************************************************************************
+ *
* FUNCTION: fread
*
* PARAMETERS: Buffer - Data buffer