summaryrefslogtreecommitdiffstats
path: root/usr/klibc/stdio/fgetc.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr/klibc/stdio/fgetc.c')
-rw-r--r--usr/klibc/stdio/fgetc.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/usr/klibc/stdio/fgetc.c b/usr/klibc/stdio/fgetc.c
new file mode 100644
index 0000000..5d1fc06
--- /dev/null
+++ b/usr/klibc/stdio/fgetc.c
@@ -0,0 +1,19 @@
+/*
+ * fgetc.c
+ */
+
+#include "stdioint.h"
+
+int fgetc(FILE *file)
+{
+ struct _IO_file_pvt *f = stdio_pvt(file);
+ unsigned char ch;
+
+ if (__likely(f->ibytes)) {
+ f->ibytes--;
+ return (unsigned char) *f->data++;
+ } else {
+ return _fread(&ch, 1, file) == 1 ? ch : EOF;
+ }
+}
+__ALIAS(int, fgetc_unlocked, (FILE *), fgetc)