3 This file is part of the Public Domain C Library (PDCLib).
4 Permission is granted to use, modify, and / or redistribute at will.
7 /* This is an example initialization of stdin, stdout and stderr to the integer
8 file descriptors 0, 1, and 2, respectively. This applies for a great variety
9 of operating systems, including POSIX compliant ones.
17 #include <_PDCLIB_io.h>
18 #include <_PDCLIB_locale.h>
19 #include <_PDCLIB_clocale.h>
22 /* In a POSIX system, stdin / stdout / stderr are equivalent to the (int) file
23 descriptors 0, 1, and 2 respectively.
25 /* TODO: This is proof-of-concept, requires finetuning. */
26 static char _PDCLIB_sin_buffer[BUFSIZ];
27 static char _PDCLIB_sout_buffer[BUFSIZ];
28 static char _PDCLIB_serr_buffer[BUFSIZ];
30 static unsigned char _PDCLIB_sin_ungetbuf[_PDCLIB_UNGETCBUFSIZE];
31 static unsigned char _PDCLIB_sout_ungetbuf[_PDCLIB_UNGETCBUFSIZE];
32 static unsigned char _PDCLIB_serr_ungetbuf[_PDCLIB_UNGETCBUFSIZE];
34 extern _PDCLIB_fileops_t _PDCLIB_fileops;
36 static FILE _PDCLIB_serr = {
37 .ops = &_PDCLIB_fileops,
38 .handle = { .sval = 2 },
39 .buffer = _PDCLIB_serr_buffer,
44 .ungetbuf = _PDCLIB_serr_ungetbuf,
45 .status = _IONBF | _PDCLIB_FWRITE | _PDCLIB_STATIC,
49 static FILE _PDCLIB_sout = {
50 .ops = &_PDCLIB_fileops,
51 .handle = { .sval = 1 },
52 .buffer = _PDCLIB_sout_buffer,
57 .ungetbuf = _PDCLIB_sout_ungetbuf,
58 .status = _IOLBF | _PDCLIB_FWRITE | _PDCLIB_STATIC,
62 static FILE _PDCLIB_sin = {
63 .ops = &_PDCLIB_fileops,
64 .handle = { .sval = 0 },
65 .buffer = _PDCLIB_sin_buffer,
70 .ungetbuf = _PDCLIB_sin_ungetbuf,
71 .status = _IOLBF | _PDCLIB_FREAD | _PDCLIB_STATIC,
76 FILE * stdin = &_PDCLIB_sin;
77 FILE * stdout = &_PDCLIB_sout;
78 FILE * stderr = &_PDCLIB_serr;
80 tss_t _PDCLIB_locale_tss;
82 /* FIXME: This approach is a possible attack vector. */
83 FILE * _PDCLIB_filelist = &_PDCLIB_sin;
85 /* "C" locale - defaulting to ASCII-7.
86 1 kByte (+ 4 byte) of <ctype.h> data.
87 Each line: flags, lowercase, uppercase, collation.
89 static const _PDCLIB_ctype_t global_ctype[] = {
90 { /* EOF */ 0, 0, 0, 0 },
91 { /* NUL */ _PDCLIB_CTYPE_CNTRL, 0x00, 0x00, 0x00 },
92 { /* SOH */ _PDCLIB_CTYPE_CNTRL, 0x01, 0x01, 0x01 },
93 { /* STX */ _PDCLIB_CTYPE_CNTRL, 0x02, 0x02, 0x02 },
94 { /* ETX */ _PDCLIB_CTYPE_CNTRL, 0x03, 0x03, 0x03 },
95 { /* EOT */ _PDCLIB_CTYPE_CNTRL, 0x04, 0x04, 0x04 },
96 { /* ENQ */ _PDCLIB_CTYPE_CNTRL, 0x05, 0x05, 0x05 },
97 { /* ACK */ _PDCLIB_CTYPE_CNTRL, 0x06, 0x06, 0x06 },
98 { /* BEL */ _PDCLIB_CTYPE_CNTRL, 0x07, 0x07, 0x07 },
99 { /* BS */ _PDCLIB_CTYPE_CNTRL, 0x08, 0x08, 0x08 },
100 { /* HT */ _PDCLIB_CTYPE_CNTRL | _PDCLIB_CTYPE_BLANK | _PDCLIB_CTYPE_SPACE, 0x09, 0x09, 0x09 },
101 { /* LF */ _PDCLIB_CTYPE_CNTRL | _PDCLIB_CTYPE_SPACE, 0x0A, 0x0A, 0x0A },
102 { /* VT */ _PDCLIB_CTYPE_CNTRL | _PDCLIB_CTYPE_SPACE, 0x0B, 0x0B, 0x0B },
103 { /* FF */ _PDCLIB_CTYPE_CNTRL | _PDCLIB_CTYPE_SPACE, 0x0C, 0x0C, 0x0C },
104 { /* CR */ _PDCLIB_CTYPE_CNTRL | _PDCLIB_CTYPE_SPACE, 0x0D, 0x0D, 0x0D },
105 { /* SO */ _PDCLIB_CTYPE_CNTRL, 0x0E, 0x0E, 0x0E },
106 { /* SI */ _PDCLIB_CTYPE_CNTRL, 0x0F, 0x0F, 0x0F },
107 { /* DLE */ _PDCLIB_CTYPE_CNTRL, 0x10, 0x10, 0x10 },
108 { /* DC1 */ _PDCLIB_CTYPE_CNTRL, 0x11, 0x11, 0x11 },
109 { /* DC2 */ _PDCLIB_CTYPE_CNTRL, 0x12, 0x12, 0x12 },
110 { /* DC3 */ _PDCLIB_CTYPE_CNTRL, 0x13, 0x13, 0x13 },
111 { /* DC4 */ _PDCLIB_CTYPE_CNTRL, 0x14, 0x14, 0x14 },
112 { /* NAK */ _PDCLIB_CTYPE_CNTRL, 0x15, 0x15, 0x15 },
113 { /* SYN */ _PDCLIB_CTYPE_CNTRL, 0x16, 0x16, 0x16 },
114 { /* ETB */ _PDCLIB_CTYPE_CNTRL, 0x17, 0x17, 0x17 },
115 { /* CAN */ _PDCLIB_CTYPE_CNTRL, 0x18, 0x18, 0x18 },
116 { /* EM */ _PDCLIB_CTYPE_CNTRL, 0x19, 0x19, 0x19 },
117 { /* SUB */ _PDCLIB_CTYPE_CNTRL, 0x1A, 0x1A, 0x1A },
118 { /* ESC */ _PDCLIB_CTYPE_CNTRL, 0x1B, 0x1B, 0x1B },
119 { /* FS */ _PDCLIB_CTYPE_CNTRL, 0x1C, 0x1C, 0x1C },
120 { /* GS */ _PDCLIB_CTYPE_CNTRL, 0x1D, 0x1D, 0x1D },
121 { /* RS */ _PDCLIB_CTYPE_CNTRL, 0x1E, 0x1E, 0x1E },
122 { /* US */ _PDCLIB_CTYPE_CNTRL, 0x1F, 0x1F, 0x1F },
123 { /* SP */ _PDCLIB_CTYPE_BLANK | _PDCLIB_CTYPE_SPACE, 0x20, 0x20, 0x20 },
124 { /* '!' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x21, 0x21, 0x21 },
125 { /* '"' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x22, 0x22, 0x22 },
126 { /* '#' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x23, 0x23, 0x23 },
127 { /* '$' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x24, 0x24, 0x24 },
128 { /* '%' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x25, 0x25, 0x25 },
129 { /* '&' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x26, 0x26, 0x26 },
130 { /* ''' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x27, 0x27, 0x27 },
131 { /* '(' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x28, 0x28, 0x28 },
132 { /* ')' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x29, 0x29, 0x29 },
133 { /* '*' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x2A, 0x2A, 0x2A },
134 { /* '+' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x2B, 0x2B, 0x2B },
135 { /* ',' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x2C, 0x2C, 0x2C },
136 { /* '-' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x2D, 0x2D, 0x2D },
137 { /* '.' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x2E, 0x2E, 0x2E },
138 { /* '/' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x2F, 0x2F, 0x2F },
139 { /* '0' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x30, 0x30, 0x30 },
140 { /* '1' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x31, 0x31, 0x31 },
141 { /* '2' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x32, 0x32, 0x32 },
142 { /* '3' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x33, 0x33, 0x33 },
143 { /* '4' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x34, 0x34, 0x34 },
144 { /* '5' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x35, 0x35, 0x35 },
145 { /* '6' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x36, 0x36, 0x36 },
146 { /* '7' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x37, 0x37, 0x37 },
147 { /* '8' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x38, 0x38, 0x38 },
148 { /* '9' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x39, 0x39, 0x39 },
149 { /* ':' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x3A, 0x3A, 0x3A },
150 { /* ';' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x3B, 0x3B, 0x3B },
151 { /* '<' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x3C, 0x3C, 0x3C },
152 { /* '=' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x3D, 0x3D, 0x3D },
153 { /* '>' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x3E, 0x3E, 0x3E },
154 { /* '?' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x3F, 0x3F, 0x3F },
155 { /* '@' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x40, 0x40, 0x40 },
156 { /* 'A' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER | _PDCLIB_CTYPE_XDIGT, 0x41, 0x61, 0x41 },
157 { /* 'B' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER | _PDCLIB_CTYPE_XDIGT, 0x42, 0x62, 0x42 },
158 { /* 'C' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER | _PDCLIB_CTYPE_XDIGT, 0x43, 0x63, 0x43 },
159 { /* 'D' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER | _PDCLIB_CTYPE_XDIGT, 0x44, 0x64, 0x44 },
160 { /* 'E' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER | _PDCLIB_CTYPE_XDIGT, 0x45, 0x65, 0x45 },
161 { /* 'F' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER | _PDCLIB_CTYPE_XDIGT, 0x46, 0x66, 0x46 },
162 { /* 'G' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x47, 0x67, 0x47 },
163 { /* 'H' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x48, 0x68, 0x48 },
164 { /* 'I' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x49, 0x69, 0x49 },
165 { /* 'J' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x4A, 0x6A, 0x4A },
166 { /* 'K' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x4B, 0x6B, 0x4B },
167 { /* 'L' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x4C, 0x6C, 0x4C },
168 { /* 'M' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x4D, 0x6D, 0x4D },
169 { /* 'N' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x4E, 0x6E, 0x4E },
170 { /* 'O' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x4F, 0x6F, 0x4F },
171 { /* 'P' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x50, 0x70, 0x50 },
172 { /* 'Q' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x51, 0x71, 0x51 },
173 { /* 'R' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x52, 0x72, 0x52 },
174 { /* 'S' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x53, 0x73, 0x53 },
175 { /* 'T' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x54, 0x74, 0x54 },
176 { /* 'U' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x55, 0x75, 0x55 },
177 { /* 'V' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x56, 0x76, 0x56 },
178 { /* 'W' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x57, 0x77, 0x57 },
179 { /* 'X' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x58, 0x78, 0x58 },
180 { /* 'Y' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x59, 0x79, 0x59 },
181 { /* 'Z' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x5A, 0x7A, 0x5A },
182 { /* '[' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x5B, 0x5B, 0x5B },
183 { /* '\' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x5C, 0x5C, 0x5C },
184 { /* ']' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x5D, 0x5D, 0x5D },
185 { /* '^' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x5E, 0x5E, 0x5E },
186 { /* '_' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x5F, 0x5F, 0x5F },
187 { /* '`' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x60, 0x60, 0x60 },
188 { /* 'a' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER | _PDCLIB_CTYPE_XDIGT, 0x41, 0x61, 0x61 },
189 { /* 'b' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER | _PDCLIB_CTYPE_XDIGT, 0x42, 0x62, 0x62 },
190 { /* 'c' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER | _PDCLIB_CTYPE_XDIGT, 0x43, 0x63, 0x63 },
191 { /* 'd' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER | _PDCLIB_CTYPE_XDIGT, 0x44, 0x64, 0x64 },
192 { /* 'e' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER | _PDCLIB_CTYPE_XDIGT, 0x45, 0x65, 0x65 },
193 { /* 'f' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER | _PDCLIB_CTYPE_XDIGT, 0x46, 0x66, 0x66 },
194 { /* 'g' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x47, 0x67, 0x67 },
195 { /* 'h' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x48, 0x68, 0x68 },
196 { /* 'i' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x49, 0x69, 0x69 },
197 { /* 'j' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x4A, 0x6A, 0x6A },
198 { /* 'k' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x4B, 0x6B, 0x6B },
199 { /* 'l' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x4C, 0x6C, 0x6C },
200 { /* 'm' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x4D, 0x6D, 0x6D },
201 { /* 'n' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x4E, 0x6E, 0x6E },
202 { /* 'o' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x4F, 0x6F, 0x6F },
203 { /* 'p' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x50, 0x70, 0x70 },
204 { /* 'q' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x51, 0x71, 0x71 },
205 { /* 'r' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x52, 0x72, 0x72 },
206 { /* 's' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x53, 0x73, 0x73 },
207 { /* 't' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x54, 0x74, 0x74 },
208 { /* 'u' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x55, 0x75, 0x75 },
209 { /* 'v' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x56, 0x76, 0x76 },
210 { /* 'w' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x57, 0x77, 0x77 },
211 { /* 'x' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x58, 0x78, 0x78 },
212 { /* 'y' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x59, 0x79, 0x79 },
213 { /* 'z' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x5A, 0x7A, 0x7A },
214 { /* '{' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x7B, 0x7B, 0x7B },
215 { /* '|' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x7C, 0x7C, 0x7C },
216 { /* '}' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x7D, 0x7D, 0x7D },
217 { /* '~' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x7E, 0x7E, 0x7E },
218 { /* DEL */ _PDCLIB_CTYPE_CNTRL, 0x7F, 0x7F, 0x7F },
219 { 0x00, 0x80, 0x80, 0x80 },
220 { 0x00, 0x81, 0x81, 0x81 },
221 { 0x00, 0x82, 0x82, 0x82 },
222 { 0x00, 0x83, 0x83, 0x83 },
223 { 0x00, 0x84, 0x84, 0x84 },
224 { 0x00, 0x85, 0x85, 0x85 },
225 { 0x00, 0x86, 0x86, 0x86 },
226 { 0x00, 0x87, 0x87, 0x87 },
227 { 0x00, 0x88, 0x88, 0x88 },
228 { 0x00, 0x89, 0x89, 0x89 },
229 { 0x00, 0x8A, 0x8A, 0x8A },
230 { 0x00, 0x8B, 0x8B, 0x8B },
231 { 0x00, 0x8C, 0x8C, 0x8C },
232 { 0x00, 0x8D, 0x8D, 0x8D },
233 { 0x00, 0x8E, 0x8E, 0x8E },
234 { 0x00, 0x8F, 0x8F, 0x8F },
235 { 0x00, 0x90, 0x90, 0x90 },
236 { 0x00, 0x91, 0x91, 0x91 },
237 { 0x00, 0x92, 0x92, 0x92 },
238 { 0x00, 0x93, 0x93, 0x93 },
239 { 0x00, 0x94, 0x94, 0x94 },
240 { 0x00, 0x95, 0x95, 0x95 },
241 { 0x00, 0x96, 0x96, 0x96 },
242 { 0x00, 0x97, 0x97, 0x97 },
243 { 0x00, 0x98, 0x98, 0x98 },
244 { 0x00, 0x99, 0x99, 0x99 },
245 { 0x00, 0x9A, 0x9A, 0x9A },
246 { 0x00, 0x9B, 0x9B, 0x9B },
247 { 0x00, 0x9C, 0x9C, 0x9C },
248 { 0x00, 0x9D, 0x9D, 0x9D },
249 { 0x00, 0x9E, 0x9E, 0x9E },
250 { 0x00, 0x9F, 0x9F, 0x9F },
251 { 0x00, 0xA0, 0xA0, 0xA0 },
252 { 0x00, 0xA1, 0xA1, 0xA1 },
253 { 0x00, 0xA2, 0xA2, 0xA2 },
254 { 0x00, 0xA3, 0xA3, 0xA3 },
255 { 0x00, 0xA4, 0xA4, 0xA4 },
256 { 0x00, 0xA5, 0xA5, 0xA5 },
257 { 0x00, 0xA6, 0xA6, 0xA6 },
258 { 0x00, 0xA7, 0xA7, 0xA7 },
259 { 0x00, 0xA8, 0xA8, 0xA8 },
260 { 0x00, 0xA9, 0xA9, 0xA9 },
261 { 0x00, 0xAA, 0xAA, 0xAA },
262 { 0x00, 0xAB, 0xAB, 0xAB },
263 { 0x00, 0xAC, 0xAC, 0xAC },
264 { 0x00, 0xAD, 0xAD, 0xAD },
265 { 0x00, 0xAE, 0xAE, 0xAE },
266 { 0x00, 0xAF, 0xAF, 0xAF },
267 { 0x00, 0xB0, 0xB0, 0xB0 },
268 { 0x00, 0xB1, 0xB1, 0xB1 },
269 { 0x00, 0xB2, 0xB2, 0xB2 },
270 { 0x00, 0xB3, 0xB3, 0xB3 },
271 { 0x00, 0xB4, 0xB4, 0xB4 },
272 { 0x00, 0xB5, 0xB5, 0xB5 },
273 { 0x00, 0xB6, 0xB6, 0xB6 },
274 { 0x00, 0xB7, 0xB7, 0xB7 },
275 { 0x00, 0xB8, 0xB8, 0xB8 },
276 { 0x00, 0xB9, 0xB9, 0xB9 },
277 { 0x00, 0xBA, 0xBA, 0xBA },
278 { 0x00, 0xBB, 0xBB, 0xBB },
279 { 0x00, 0xBC, 0xBC, 0xBC },
280 { 0x00, 0xBD, 0xBD, 0xBD },
281 { 0x00, 0xBE, 0xBE, 0xBE },
282 { 0x00, 0xBF, 0xBF, 0xBF },
283 { 0x00, 0xC0, 0xC0, 0xC0 },
284 { 0x00, 0xC1, 0xC1, 0xC1 },
285 { 0x00, 0xC2, 0xC2, 0xC2 },
286 { 0x00, 0xC3, 0xC3, 0xC3 },
287 { 0x00, 0xC4, 0xC4, 0xC4 },
288 { 0x00, 0xC5, 0xC5, 0xC5 },
289 { 0x00, 0xC6, 0xC6, 0xC6 },
290 { 0x00, 0xC7, 0xC7, 0xC7 },
291 { 0x00, 0xC8, 0xC8, 0xC8 },
292 { 0x00, 0xC9, 0xC9, 0xC9 },
293 { 0x00, 0xCA, 0xCA, 0xCA },
294 { 0x00, 0xCB, 0xCB, 0xCB },
295 { 0x00, 0xCC, 0xCC, 0xCC },
296 { 0x00, 0xCD, 0xCD, 0xCD },
297 { 0x00, 0xCE, 0xCE, 0xCE },
298 { 0x00, 0xCF, 0xCF, 0xCF },
299 { 0x00, 0xD0, 0xD0, 0xD0 },
300 { 0x00, 0xD1, 0xD1, 0xD1 },
301 { 0x00, 0xD2, 0xD2, 0xD2 },
302 { 0x00, 0xD3, 0xD3, 0xD3 },
303 { 0x00, 0xD4, 0xD4, 0xD4 },
304 { 0x00, 0xD5, 0xD5, 0xD5 },
305 { 0x00, 0xD6, 0xD6, 0xD6 },
306 { 0x00, 0xD7, 0xD7, 0xD7 },
307 { 0x00, 0xD8, 0xD8, 0xD8 },
308 { 0x00, 0xD9, 0xD9, 0xD9 },
309 { 0x00, 0xDA, 0xDA, 0xDA },
310 { 0x00, 0xDB, 0xDB, 0xDB },
311 { 0x00, 0xDC, 0xDC, 0xDC },
312 { 0x00, 0xDD, 0xDD, 0xDD },
313 { 0x00, 0xDE, 0xDE, 0xDE },
314 { 0x00, 0xDF, 0xDF, 0xDF },
315 { 0x00, 0xE0, 0xE0, 0xE0 },
316 { 0x00, 0xE1, 0xE1, 0xE1 },
317 { 0x00, 0xE2, 0xE2, 0xE2 },
318 { 0x00, 0xE3, 0xE3, 0xE3 },
319 { 0x00, 0xE4, 0xE4, 0xE4 },
320 { 0x00, 0xE5, 0xE5, 0xE5 },
321 { 0x00, 0xE6, 0xE6, 0xE6 },
322 { 0x00, 0xE7, 0xE7, 0xE7 },
323 { 0x00, 0xE8, 0xE8, 0xE8 },
324 { 0x00, 0xE9, 0xE9, 0xE9 },
325 { 0x00, 0xEA, 0xEA, 0xEA },
326 { 0x00, 0xEB, 0xEB, 0xEB },
327 { 0x00, 0xEC, 0xEC, 0xEC },
328 { 0x00, 0xED, 0xED, 0xED },
329 { 0x00, 0xEE, 0xEE, 0xEE },
330 { 0x00, 0xEF, 0xEF, 0xEF },
331 { 0x00, 0xF0, 0xF0, 0xF0 },
332 { 0x00, 0xF1, 0xF1, 0xF1 },
333 { 0x00, 0xF2, 0xF2, 0xF2 },
334 { 0x00, 0xF3, 0xF3, 0xF3 },
335 { 0x00, 0xF4, 0xF4, 0xF4 },
336 { 0x00, 0xF5, 0xF5, 0xF5 },
337 { 0x00, 0xF6, 0xF6, 0xF6 },
338 { 0x00, 0xF7, 0xF7, 0xF7 },
339 { 0x00, 0xF8, 0xF8, 0xF8 },
340 { 0x00, 0xF9, 0xF9, 0xF9 },
341 { 0x00, 0xFA, 0xFA, 0xFA },
342 { 0x00, 0xFB, 0xFB, 0xFB },
343 { 0x00, 0xFC, 0xFC, 0xFC },
344 { 0x00, 0xFD, 0xFD, 0xFD },
345 { 0x00, 0xFE, 0xFE, 0xFE },
346 { 0x00, 0xFF, 0xFF, 0xFF }
349 extern const struct _PDCLIB_charcodec_t _PDCLIB_ascii_codec;
350 struct _PDCLIB_locale _PDCLIB_global_locale = {
351 ._Codec = &_PDCLIB_ascii_codec,
353 /* decimal_point */ (char *)".",
354 /* thousands_sep */ (char *)"",
355 /* grouping */ (char *)"",
356 /* mon_decimal_point */ (char *)"",
357 /* mon_thousands_sep */ (char *)"",
358 /* mon_grouping */ (char *)"",
359 /* positive_sign */ (char *)"",
360 /* negative_sign */ (char *)"",
361 /* currency_symbol */ (char *)"",
362 /* int_curr_symbol */ (char *)"",
363 /* frac_digits */ CHAR_MAX,
364 /* p_cs_precedes */ CHAR_MAX,
365 /* n_cs_precedes */ CHAR_MAX,
366 /* p_sep_by_space */ CHAR_MAX,
367 /* n_sep_by_space */ CHAR_MAX,
368 /* p_sign_posn */ CHAR_MAX,
369 /* n_sign_posn */ CHAR_MAX,
370 /* int_frac_digits */ CHAR_MAX,
371 /* int_p_cs_precedes */ CHAR_MAX,
372 /* int_n_cs_precedes */ CHAR_MAX,
373 /* int_p_sep_by_space */ CHAR_MAX,
374 /* int_n_sep_by_space */ CHAR_MAX,
375 /* int_p_sign_posn */ CHAR_MAX,
376 /* int_n_sign_posn */ CHAR_MAX,
378 ._CType = &global_ctype[1],
381 "EPERM (operation not permitted)",
382 "ENOENT (no such file or directory)",
383 "ESRCH (no such process)",
384 "EINTR (interrupted)",
386 "ENXIO (no such device or address)",
387 "E2BIG (argument list too long)",
388 "ENOEXEC (executable format error)",
389 "EBADF (bad file descriptor)",
390 "ECHILD (no child process)",
391 "EAGAIN (resource unavailable try again)",
392 "ENOMEM (not enough memory)",
393 "EACCES (permission denied)",
394 "EFAULT (bad address)",
396 "EBUSY (device or resource busy)",
397 "EEXIST (file exists)",
398 "EXDEV (cross device link)",
399 "ENODEV (no such device)",
400 "ENOTDIR (not a directory)",
401 "EISDIR (is a directory)",
402 "EINVAL (invalid argument)",
403 "ENFILE (too many files open in system)",
404 "EMFILE (too many files open)",
405 "ENOTTY (inappropriate io control operation)",
406 "ETXTBSY (text file busy)",
407 "EFBIG (file too large)",
408 "ENOSPC (no space on device)",
409 "ESPIPE (invalid seek)",
410 "EROFS (read only file system)",
411 "EMLINK (too many links)",
412 "EPIPE (broken pipe)",
413 "EDOM (argument out of domain)",
414 "ERANGE (result out of range)",
415 "EDEADLK (resource deadlock would occur)",
416 "ENAMETOOLONG (filename too long)",
417 "ENOLCK (no lock available)",
418 "ENOSYS (function not supported)",
419 "ENOTEMPTY (directory not empty)",
420 "ELOOP (too many symbolic link levels)",
422 "ENOMSG (no message)",
423 "EIDRM (identifier removed)",
440 "ENOSTR (not a stream)",
441 "ENODATA (no message available)",
442 "ETIME (stream timeout)",
443 "ENOSR (no stream resources)",
451 "EPROTO (protocol error)",
454 "EBADMSG (bad message)",
455 "EOVERFLOW (value too large)",
464 "EILSEQ (illegal byte sequence)",
468 "ENOTSOCK (not a socket)",
469 "EDESTADDRREQ (destination address required)",
470 "EMSGSIZE (message size)",
471 "EPROTOTYPE (wrong protocol type)",
472 "ENOPROTOOPT (no protocol option)",
473 "EPROTONOSUPPORT (protocol not supported)",
475 "ENOTSUP (not supported)",
477 "EAFNOSUPPORT (address family not supported)",
478 "EADDRINUSE (address in use)",
479 "EADDRNOTAVAIL (address not available)",
480 "ENETDOWN (network down)",
481 "ENETUNREACH (network unreachable)",
482 "ENETRESET (network reset)",
483 "ECONNABORTED (connection aborted)",
484 "ECONNRESET (connection reset)",
485 "ENOBUFS (no buffer space)",
486 "EISCONN (already connected)",
487 "ENOTCONN (not connected)",
490 "ETIMEDOUT (timed out)",
491 "ECONNREFUSED (connection refused)",
493 "EHOSTUNREACH (host unreachable)",
494 "EALREADY (connection already in progress)",
495 "EINPROGRESS (operation in progress)",
505 "ECANCELED (operation canceled)",
510 "EOWNERDEAD (owner dead)",
511 "ENOTRECOVERABLE (state not recoverable)",
515 /* Todo: Better solution than this! */
516 __attribute__((constructor)) static void init_stdio(void)
518 _PDCLIB_initclocale( &_PDCLIB_global_locale );
519 tss_create(&_PDCLIB_locale_tss, (tss_dtor_t) freelocale);
520 mtx_init(&stdin->lock, mtx_recursive);
521 mtx_init(&stdout->lock, mtx_recursive);
522 mtx_init(&stderr->lock, mtx_recursive);
528 #include <_PDCLIB_test.h>
532 /* Testing covered by several other testdrivers using stdin / stdout /