aboutsummaryrefslogtreecommitdiff
path: root/8.4/stdio.h
diff options
context:
space:
mode:
authorsinanmohd <sinan@firemail.cc>2023-05-18 12:44:37 +0530
committersinanmohd <sinan@firemail.cc>2023-05-18 22:28:16 +0530
commit68f15b3002235095d9649ba423069b492cf63746 (patch)
tree23a54bab6ba7fac83332dab1bb73e796e6a46435 /8.4/stdio.h
parent4592fa91f80e7c131c63d35fc5e9da0b18bd7911 (diff)
8.4: initial commit
Diffstat (limited to '8.4/stdio.h')
-rw-r--r--8.4/stdio.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/8.4/stdio.h b/8.4/stdio.h
new file mode 100644
index 0000000..37413a2
--- /dev/null
+++ b/8.4/stdio.h
@@ -0,0 +1,50 @@
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stddef.h>
+
+#define EOF (-1)
+#define BUFSIZ 8192
+#define OPN_MAX 20
+
+typedef struct {
+ int cnt;
+ char *ptr;
+ char *base;
+ int flag;
+ int fd;
+} FILE;
+
+extern FILE _iob[OPN_MAX];
+
+#define stdin (_iob+0)
+#define stdout (_iob+1)
+#define stderr (_iob+2)
+
+enum flags {
+ _READ = 1 << 0,
+ _WRITE = 1 << 2,
+ _UNBUF = 1 << 3,
+ _EOF = 1 << 4,
+ _ERR = 1 << 5
+};
+
+int _fillbuf(FILE *);
+int _flushbuf(int, FILE *);
+FILE *fopen(char *name, char *mode);
+int fflush(FILE *fp);
+int fseek(FILE *fp, ssize_t os, int whence);
+int fclose(FILE *fp);
+int puts(const char *);
+
+#define feof(p) ((p)->flag & _EOF)
+#define ferror(p) ((p)->flag & _ERR)
+#define fileno(p) ((p)->fd)
+
+#define getc(p) ((--(p)->cnt >= 0) \
+ ? (unsigned char) *(p)->ptr++ : _fillbuf(p))
+#define putc(x, p) ((--(p)->cnt >= 0) \
+ ? *(p)->ptr++ = (x) : _flushbuf(x, p))
+
+#define getchar() getc(stdin)
+#define putchar(x) putc((x), stdout)