summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLv Zheng <lv.zheng@intel.com>2016-07-12 14:37:54 +0800
committerLv Zheng <lv.zheng@intel.com>2016-12-14 16:33:22 +0800
commit30495a682e335ce08da696e45e4f00a1d7ecc026 (patch)
tree81b0020d5d99bd56c90a6fb9c02e1ddf20b8524f
parentcc6947172dcced4f7909eb351981b3413bb9a27a (diff)
downloadacpica-30495a682e335ce08da696e45e4f00a1d7ecc026.tar.gz
Clib/EFI: Add fgets() to improve portability
This patch adds fgets(). Lv Zheng. Signed-off-by: Lv Zheng <lv.zheng@intel.com>
-rw-r--r--source/include/acclib.h6
-rw-r--r--source/os_specific/efi/oseficlib.c59
2 files changed, 65 insertions, 0 deletions
diff --git a/source/include/acclib.h b/source/include/acclib.h
index 9fca11114..10667216a 100644
--- a/source/include/acclib.h
+++ b/source/include/acclib.h
@@ -371,6 +371,12 @@ int
fputc (
FILE *File,
char c);
+
+char *
+fgets (
+ char *s,
+ ACPI_SIZE Size,
+ FILE *File);
#endif
#endif /* _ACCLIB_H */
diff --git a/source/os_specific/efi/oseficlib.c b/source/os_specific/efi/oseficlib.c
index 333031801..75d81b797 100644
--- a/source/os_specific/efi/oseficlib.c
+++ b/source/os_specific/efi/oseficlib.c
@@ -426,6 +426,65 @@ fputc (
/*******************************************************************************
*
+ * FUNCTION: fgets
+ *
+ * PARAMETERS: File - File descriptor
+ *
+ * RETURN: The string read
+ *
+ * DESCRIPTION: Read a string from the file.
+ *
+ ******************************************************************************/
+
+char *
+fgets (
+ char *s,
+ ACPI_SIZE Size,
+ FILE *File)
+{
+ ACPI_SIZE ReadBytes = 0;
+ int Ret;
+
+
+ if (Size <= 1)
+ {
+ errno = EINVAL;
+ return (NULL);
+ }
+ while (ReadBytes < (Size - 1))
+ {
+ Ret = fgetc (File);
+ if (Ret == EOF)
+ {
+ if (ReadBytes == 0)
+ {
+ return (NULL);
+ }
+ break;
+ }
+ else if (Ret < 0)
+ {
+ errno = EIO;
+ return (NULL);
+ }
+ else if (Ret == '\n')
+ {
+ s[ReadBytes++] = (char) Ret;
+ break;
+ }
+ else
+ {
+ s[ReadBytes++] = (char) Ret;
+ }
+ }
+
+ s[ReadBytes] = '\0';
+ return (s);
+}
+
+
+/*******************************************************************************
+ *
* FUNCTION: fread
*
* PARAMETERS: Buffer - Data buffer