summaryrefslogtreecommitdiffstats
path: root/usr/klibc/fgets.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr/klibc/fgets.c')
-rw-r--r--usr/klibc/fgets.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/usr/klibc/fgets.c b/usr/klibc/fgets.c
new file mode 100644
index 0000000..b6e6f3e
--- /dev/null
+++ b/usr/klibc/fgets.c
@@ -0,0 +1,28 @@
+/*
+ * fgets.c
+ */
+
+#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) {
+ s = NULL;
+ break;
+ }
+ *p++ = ch;
+ n--;
+ if (ch == '\n')
+ break;
+ }
+ if (n)
+ *p = '\0';
+
+ return s;
+}
+__ALIAS(char *, fgets_unlocked, (char *, int, FILE *), fgets)