summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLv Zheng <lv.zheng@intel.com>2016-07-12 14:37:53 +0800
committerLv Zheng <lv.zheng@intel.com>2016-12-14 16:33:22 +0800
commit4dbfe66bf1988a513af10dabd7317d8da6ebb036 (patch)
tree5f6d86da4b786fe30d472c3dafc3d88bbec75eef
parentc684c88bd93443142294d016204f6c15e8138ede (diff)
downloadacpica-4dbfe66bf1988a513af10dabd7317d8da6ebb036.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.h13
-rw-r--r--source/os_specific/efi/oseficlib.c70
2 files changed, 83 insertions, 0 deletions
diff --git a/source/include/acclib.h b/source/include/acclib.h
index e917dd88d..9fca11114 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,15 @@ fseek (
long
ftell (
FILE *File);
+
+int
+fgetc (
+ FILE *File);
+
+int
+fputc (
+ FILE *File,
+ char c);
#endif
#endif /* _ACCLIB_H */
diff --git a/source/os_specific/efi/oseficlib.c b/source/os_specific/efi/oseficlib.c
index b0956ce90..91c85a863 100644
--- a/source/os_specific/efi/oseficlib.c
+++ b/source/os_specific/efi/oseficlib.c
@@ -337,6 +337,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