From 4e09bca9e34c226b6d7e34b4fa11248405fd988e Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Sun, 22 Oct 2023 19:50:38 +0200 Subject: Move everything into a new repo. --- userland/libc/include/stdio.h | 116 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 userland/libc/include/stdio.h (limited to 'userland/libc/include/stdio.h') diff --git a/userland/libc/include/stdio.h b/userland/libc/include/stdio.h new file mode 100644 index 0000000..014e2ac --- /dev/null +++ b/userland/libc/include/stdio.h @@ -0,0 +1,116 @@ +#ifndef STDIO_H +#define STDIO_H +#include +#include +#include + +// FIXME: Most of these should probably not be here. But I am too lazy +// to fix it right now. This is futures mees problem to deal wth. + +#define EOF (-1) + +#define SEEK_SET 0 +#define SEEK_CUR 1 +#define SEEK_END 2 + +#define BUFSIZ 4096 + +// https://pubs.opengroup.org/onlinepubs/9699919799/functions/setvbuf.html +#define _IOFBF 1 // shall cause input/output to be fully buffered. +#define _IOLBF 2 // shall cause input/output to be line buffered. +#define _IONBF 3 // shall cause input/output to be unbuffered. + +typedef long fpos_t; + +typedef struct __IO_FILE FILE; +struct __IO_FILE { + size_t (*write)(FILE *, const unsigned char *, size_t); + size_t (*read)(FILE *, unsigned char *, size_t); + int (*seek)(FILE *, long, int); + long offset_in_file; + int buffered_char; + int has_buffered_char; + int fd; + uint8_t is_eof; + uint8_t has_error; + uint64_t file_size; + void *cookie; +}; + +size_t write_fd(FILE *f, const unsigned char *s, size_t l); +size_t read_fd(FILE *f, unsigned char *s, size_t l); +int seek_fd(FILE *stream, long offset, int whence); + +typedef struct { + int fd; +} FILE_FD_COOKIE; + +extern FILE __stdin_FILE; +extern FILE __stdout_FILE; +extern FILE __stderr_FILE; + +#define stdin (&__stdin_FILE) +#define stdout (&__stdout_FILE) +//#define stderr (&__stderr_FILE) +#define stderr (&__stdout_FILE) + +typedef int mode_t; + +void perror(const char *s); + +int putchar(int c); +int puts(const char *s); +int brk(void *addr); +void *sbrk(intptr_t increment); +int write(int fd, const char *buf, size_t count); +int pwrite(int fd, const char *buf, size_t count, size_t offset); +int printf(const char *format, ...); +int pread(int fd, void *buf, size_t count, size_t offset); +int read(int fd, void *buf, size_t count); +int fork(void); +int memcmp(const void *s1, const void *s2, size_t n); +int wait(int *stat_loc); +void exit(int status); +void *memcpy(void *dest, const void *src, uint32_t n); +int shm_open(const char *name, int oflag, mode_t mode); +int dprintf(int fd, const char *format, ...); +int vdprintf(int fd, const char *format, va_list ap); +int vprintf(const char *format, va_list ap); +int snprintf(char *str, size_t size, const char *format, ...); +int vsnprintf(char *str, size_t size, const char *format, va_list ap); +int vfprintf(FILE *f, const char *fmt, va_list ap); +int fgetc(FILE *stream); +int getchar(void); +#define getc(_a) fgetc(_a) +size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream); +size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); +FILE *fopen(const char *pathname, const char *mode); +int fclose(FILE *stream); +int fseek(FILE *stream, long offset, int whence); +int fprintf(FILE *f, const char *fmt, ...); +int atoi(const char *str); +long strtol(const char *nptr, char **endptr, int base); +char *strchr(const char *s, int c); +char *strcat(char *s1, const char *s2); +char *fgets(char *s, int n, FILE *stream); +FILE *tmpfile(void); +int feof(FILE *stream); +int fscanf(FILE *stream, const char *format, ...); +int ungetc(int c, FILE *stream); +long ftell(FILE *stream); +int fputc(int c, FILE *stream); +int remove(const char *path); +int ferror(FILE *stream); +int fputs(const char *s, FILE *stream); +int fflush(FILE *stream); +int setvbuf(FILE *stream, char *restrict buf, int type, size_t size); +int fileno(FILE *stream); +int putc(int c, FILE *stream); +int vsprintf(char *str, const char *format, va_list ap); +int sprintf(char *str, const char *format, ...); +FILE *open_memstream(char **bufp, size_t *sizep); +int fsetpos(FILE *stream, const fpos_t *pos); +int fgetpos(FILE *restrict stream, fpos_t *restrict pos); +char *tmpnam(char *s); +int rename(const char *old, const char *new); +#endif -- cgit v1.2.3