Add [f]getc() and fgets()
diff --git a/include/stdio.h b/include/stdio.h
index d51e969..5e621af 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -70,6 +70,10 @@
#define putc(c,f) fputc((c),(f))
#define putchar(c) fputc((c),stdout)
+__extern int fgetc(FILE *);
+__extern char * fgets(char *, int, FILE *);
+#define getc(f) fgetc(f)
+
__extern size_t _fread(void *, size_t, FILE *);
__extern size_t _fwrite(const void *, size_t, FILE *);
diff --git a/klibc/Makefile b/klibc/Makefile
index 81fe510..6f00342 100644
--- a/klibc/Makefile
+++ b/klibc/Makefile
@@ -19,7 +19,8 @@
execl.o execle.o execv.o execvpe.o execvp.o execlp.o execlpe.o \
fork.o wait.o wait3.o waitpid.o setpgrp.o \
printf.o vprintf.o fprintf.o vfprintf.o perror.o \
- fopen.o fread.o fread2.o fwrite.o fwrite2.o fputc.o fputs.o puts.o \
+ fopen.o fread.o fread2.o fgetc.o fgets.o \
+ fwrite.o fwrite2.o fputc.o fputs.o puts.o \
sleep.o usleep.o raise.o abort.o assert.o alarm.o pause.o \
__signal.o signal.o bsd_signal.o siglist.o siglongjmp.o \
sigaction.o sigpending.o sigprocmask.o sigsuspend.o \
diff --git a/klibc/fgetc.c b/klibc/fgetc.c
new file mode 100644
index 0000000..83eee16
--- /dev/null
+++ b/klibc/fgetc.c
@@ -0,0 +1,20 @@
+/*
+ * fgetc.c
+ *
+ * Extremely slow fgetc implementation, using _fread(). If people
+ * actually need character-oriented input to be fast, we may actually
+ * have to implement buffering. Sigh.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+
+int fgetc(FILE *f)
+{
+ unsigned char ch;
+
+ return (_fread(&ch, 1, f) == 1) ? (int)ch : EOF;
+}
+
diff --git a/klibc/fgets.c b/klibc/fgets.c
new file mode 100644
index 0000000..88a145a
--- /dev/null
+++ b/klibc/fgets.c
@@ -0,0 +1,33 @@
+/*
+ * fgets.c
+ *
+ * This will be very slow due to the implementation of getc(),
+ * but we can't afford to drain characters we don't need from
+ * the input.
+ */
+
+#include <stdio.h>
+
+char *fgets(char *s, int n, FILE *f)
+{
+ int ch;
+ char *p = s;
+
+ while ( n > 1 ) {
+ ch = getc(f);
+ if ( ch == EOF ) {
+ *p = '\0';
+ return NULL;
+ }
+ *p++ = ch;
+ if ( ch == '\n' )
+ break;
+ }
+ if ( n )
+ *p = '\0';
+
+ return s;
+}
+
+
+
diff --git a/klibc/include/stdio.h b/klibc/include/stdio.h
index d51e969..5e621af 100644
--- a/klibc/include/stdio.h
+++ b/klibc/include/stdio.h
@@ -70,6 +70,10 @@
#define putc(c,f) fputc((c),(f))
#define putchar(c) fputc((c),stdout)
+__extern int fgetc(FILE *);
+__extern char * fgets(char *, int, FILE *);
+#define getc(f) fgetc(f)
+
__extern size_t _fread(void *, size_t, FILE *);
__extern size_t _fwrite(const void *, size_t, FILE *);