1 /*
2  * Copyright (c) 2008-2015 Travis Geiselbrecht
3  *
4  * Use of this source code is governed by a MIT-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/MIT
7  */
8 #pragma once
9 
10 #include <lk/compiler.h>
11 #include <printf.h>
12 #include <sys/types.h>
13 #include <lib/io.h>
14 
15 __BEGIN_CDECLS
16 
17 typedef struct FILE {
18     io_handle_t *io;
19 } FILE;
20 
21 extern FILE __stdio_FILEs[];
22 
23 #define stdin  (&__stdio_FILEs[0])
24 #define stdout (&__stdio_FILEs[1])
25 #define stderr (&__stdio_FILEs[2])
26 
27 FILE *fopen(const char *filename, const char *mode);
28 int fclose(FILE *stream);
29 size_t fread(void *ptr, size_t size, size_t count, FILE *stream);
30 size_t fwrite(const void *ptr, size_t size, size_t count, FILE *stream);
31 int fflush(FILE *stream);
32 int feof(FILE *stream);
33 
34 #define SEEK_SET 0
35 #define SEEK_CUR 1
36 #define SEEK_END 2
37 
38 int fseek(FILE *stream, long offset, int whence);
39 long ftell(FILE *stream);
40 
41 int fputc(int c, FILE *fp);
42 #define putc(c, fp) fputc(c, fp)
43 int putchar(int c);
44 
45 int fputs(const char *s, FILE *fp);
46 int puts(const char *str);
47 
48 int getc(FILE *fp);
49 int getchar(void);
50 
51 #if !DISABLE_DEBUG_OUTPUT
52 int printf(const char *fmt, ...) __PRINTFLIKE(1, 2);
53 int vprintf(const char *fmt, va_list ap);
54 #else
printf(const char * fmt,...)55 static inline int __PRINTFLIKE(1, 2) printf(const char *fmt, ...) { return 0; }
vprintf(const char * fmt,va_list ap)56 static inline int vprintf(const char *fmt, va_list ap) { return 0; }
57 #endif
58 
59 int fprintf(FILE *fp, const char *fmt, ...) __PRINTFLIKE(2, 3);
60 int vfprintf(FILE *fp, const char *fmt, va_list ap);
61 int _fprintf_output_func(const char *str, size_t len, void *state);
62 
63 int sprintf(char *str, const char *fmt, ...) __PRINTFLIKE(2, 3);
64 int snprintf(char *str, size_t len, const char *fmt, ...) __PRINTFLIKE(3, 4);
65 int vsprintf(char *str, const char *fmt, va_list ap);
66 int vsnprintf(char *str, size_t len, const char *fmt, va_list ap);
67 
68 
69 __END_CDECLS
70 
71