summaryrefslogtreecommitdiff
path: root/include/libc/stdio.h
blob: 9937d4d0c7280c0cd46c4a185c74abcb3f054b7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#ifndef _STDIO
#define _STDIO

#include "types.h"
#include <stdarg.h>
#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2

#define __ungetc_buffer_size 2

typedef unsigned long __file_handle;
typedef unsigned long fpos_t;
#ifndef __cplusplus
typedef unsigned short wchar_t;
#endif

enum __io_modes {
  __read = 1,
  __write = 2,
  __read_write = 3,
  __append = 4,
};
enum __file_kinds {
  __closed_file,
  __disk_file,
  __console_file,
  __unavailable_file,
};
enum __file_orientation {
  __unoriented,
  __char_oriented,
  __wide_oriented,
};

enum __io_results {
  __no_io_error,
  __io_error,
  __io_EOF,
};

typedef struct {
  unsigned int open_mode : 2;
  unsigned int io_mode : 3;
  unsigned int buffer_mode : 2;
  unsigned int file_kind : 3;
  unsigned int file_orientation : 2;
  unsigned int binary_io : 1;
} __file_modes;

enum __io_states {
  __neutral,
  __writing,
  __reading,
  __rereading,
};

typedef struct {
  unsigned int io_state : 3;
  unsigned int free_buffer : 1;
  unsigned char eof;
  unsigned char error;
} __file_state;

typedef void (*__idle_proc)(void);
typedef int (*__pos_proc)(__file_handle file, fpos_t* position, int mode, __idle_proc idle_proc);
typedef int (*__io_proc)(__file_handle file, unsigned char* buff, size_t* count,
                         __idle_proc idle_proc);
typedef int (*__close_proc)(__file_handle file);

typedef struct _IO_FILE {
  __file_handle handle;
  __file_modes mode;
  __file_state state;
  unsigned char is_dynamically_allocated;
  unsigned char char_buffer;
  unsigned char char_buffer_overflow;
  unsigned char ungetc_buffer[__ungetc_buffer_size];
  wchar_t ungetwc_buffer[__ungetc_buffer_size];
  unsigned long position;
  unsigned char* buffer;
  unsigned long buffer_size;
  unsigned char* buffer_ptr;
  unsigned long buffer_len;
  unsigned long buffer_alignment;
  unsigned long saved_buffer_len;
  unsigned long buffer_pos;
  __pos_proc position_proc;
  __io_proc read_proc;
  __io_proc write_proc;
  __close_proc close_proc;
  __idle_proc idle_proc;
  struct _IO_FILE* next_file_struct;
} FILE;

typedef struct {
  char* CharStr;
  size_t MaxCharCount;
  size_t CharsWritten;
} __OutStrCtrl;

typedef struct {
  char* NextChar;
  int NullCharDetected;
} __InStrCtrl;

#define EOF	-1L

enum __ReadProcActions { __GetChar, __UngetChar, __CheckForError };

#define _IONBF 0
#define _IOLBF 1
#define _IOFBF 2

int puts(const char* s);
int printf(const char*, ...);
int sprintf(char* s, const char* format, ...);
int vprintf(const char* format, va_list arg);
int vsprintf(char* s, const char* format, va_list arg);
size_t fread(const void*, size_t memb_size, size_t num_memb, FILE*);
size_t fwrite(const void*, size_t memb_size, size_t num_memb, FILE*);
int fseek(FILE* file, long offset, int mode);
size_t __fwrite(const void*, size_t, size_t, FILE*);

#ifdef __cplusplus
}
#endif

#endif // _STDIO