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.
16 /* In a POSIX system, stdin / stdout / stderr are equivalent to the (int) file
17 descriptors 0, 1, and 2 respectively.
19 /* TODO: This is proof-of-concept, requires finetuning. */
20 static char _PDCLIB_sin_buffer[BUFSIZ];
21 static char _PDCLIB_sout_buffer[BUFSIZ];
22 static char _PDCLIB_serr_buffer[BUFSIZ];
24 static unsigned char _PDCLIB_sin_ungetbuf[_PDCLIB_UNGETCBUFSIZE];
25 static unsigned char _PDCLIB_sout_ungetbuf[_PDCLIB_UNGETCBUFSIZE];
26 static unsigned char _PDCLIB_serr_ungetbuf[_PDCLIB_UNGETCBUFSIZE];
28 /* FIXME: serr should handle one character. Buffering on out / in? */
29 static struct _PDCLIB_file_t _PDCLIB_serr = { 2, _PDCLIB_serr_buffer, BUFSIZ, 0, 0, { 0, 0 }, 0, _PDCLIB_serr_ungetbuf, _IONBF | _PDCLIB_FWRITE, NULL, NULL };
30 static struct _PDCLIB_file_t _PDCLIB_sout = { 1, _PDCLIB_sout_buffer, BUFSIZ, 0, 0, { 0, 0 }, 0, _PDCLIB_sout_ungetbuf, _IOLBF | _PDCLIB_FWRITE, NULL, &_PDCLIB_serr };
31 static struct _PDCLIB_file_t _PDCLIB_sin = { 0, _PDCLIB_sin_buffer, BUFSIZ, 0, 0, { 0, 0 }, 0, _PDCLIB_sin_ungetbuf, _IOLBF | _PDCLIB_FREAD, NULL, &_PDCLIB_sout };
33 struct _PDCLIB_file_t * stdin = &_PDCLIB_sin;
34 struct _PDCLIB_file_t * stdout = &_PDCLIB_sout;
35 struct _PDCLIB_file_t * stderr = &_PDCLIB_serr;
37 /* FIXME: This approach is a possible attack vector. */
38 struct _PDCLIB_file_t * _PDCLIB_filelist = &_PDCLIB_sin;
43 #include <_PDCLIB_test.h>
47 /* Testing covered by several other testdrivers using stdin / stdout /