ref: f93ac9891008719a6c58f44a5a2b647d2af03284
parent: dd09461304f7842c56944fa11c3830320283347b
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Dec 8 13:08:35 EST 2017
[lib/c] Add data definition of __iob array
--- a/lib/c/include/stdio.h
+++ b/lib/c/include/stdio.h
@@ -16,9 +16,6 @@
#define SEEK_END 1
#define SEEK_SET 2
-#define _IOFBF 0
-#define _IOLBF 1
-#define _IONBF 2
#define _IOWRITE (1 << 0)
#define _IOREAD (1 << 1)
@@ -27,6 +24,9 @@
#define _IOERR (1 << 4)
#define _IOSTRG (1 << 5)
#define _IOTXT (1 << 6)
+#define _IOFBF (1 << 7)
+#define _IOLBF (1 << 8)
+#define _IONBF (1 << 9)
typedef struct {
int fd; /* file descriptor */
@@ -35,7 +35,6 @@
unsigned char *wp; /* write pointer */
unsigned char *lp; /* write pointer used when line-buffering */
size_t len; /* actual length of buffer */
- unsigned char mode;
unsigned char flags;
unsigned char unbuf[1]; /* tiny buffer for unbuffered io */
} FILE;
--- a/lib/c/src/Makefile
+++ b/lib/c/src/Makefile
@@ -10,6 +10,7 @@
fputs.o puts.o fread.o fwrite.o \
getc.o putc.o __putc.o __getc.o \
rewind.o fseek.o ferror.o feof.o clearerr.o \
+ stdio.o \
realloc.o calloc.o malloc.o \
assert.o strcpy.o strcmp.o strlen.o strchr.o \
strrchr.o strcat.o strncmp.o strncpy.o strncat.o strcoll.o \
--- /dev/null
+++ b/lib/c/src/stdio.c
@@ -1,0 +1,26 @@
+
+#include <stdio.h>
+
+static unsigned char inbuf[BUFSIZ];
+static unsigned char outbuf[BUFSIZ];
+
+FILE __iob[FOPEN_MAX] = {
+ {
+ .fd = 0,
+ .buf = inbuf,
+ .len = BUFSIZ,
+ .flags = _IOREAD
+ },
+ {
+ .fd = 1,
+ .buf = outbuf,
+ .len = BUFSIZ,
+ .flags = _IOWRITE | _IOLBF
+ },
+ {
+ .fd = 2,
+ .buf = stderr->unbuf,
+ .len = sizeof(stderr->unbuf),
+ .flags = _IOWRITE
+ },
+};