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>
This commit is contained in:
Lv Zheng 2016-07-12 14:37:53 +08:00
parent c684c88bd9
commit 4dbfe66bf1
2 changed files with 83 additions and 0 deletions

View File

@ -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 */

View File

@ -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