]> pd.if.org Git - pdclib/blob - platform/example/functions/_PDCLIB/stdinit.c
Yet closer to functional output.
[pdclib] / platform / example / functions / _PDCLIB / stdinit.c
1 /* $Id$ */
2
3 /* _PDCLIB_stdinit
4
5    This file is part of the Public Domain C Library (PDCLib).
6    Permission is granted to use, modify, and / or redistribute at will.
7 */
8
9 /* This is an example initialization of stdin, stdout and stderr to the integer
10    file descriptors 0, 1, and 2, respectively. This applies for a great variety
11    of operating systems, including POSIX compliant ones.
12 */
13
14 #include <stdio.h>
15
16 #ifndef REGTEST
17
18 /* In a POSIX system, stdin / stdout / stderr are equivalent to the (int) file
19    descriptors 0, 1, and 2 respectively.
20 */
21 /* TODO: This is proof-of-concept, requires finetuning. */
22 static char _PDCLIB_sin_buffer[BUFSIZ];
23 static char _PDCLIB_sout_buffer[BUFSIZ];
24 static char _PDCLIB_serr_buffer[BUFSIZ];
25
26 /* FIXME: serr should handle one character. Buffering on out / in? */
27 static struct _PDCLIB_file_t _PDCLIB_serr = { 2, { 0 }, _PDCLIB_serr_buffer, BUFSIZ, 0, _IONBF, /* mbstate, */ NULL };
28 static struct _PDCLIB_file_t _PDCLIB_sout = { 1, { 0 }, _PDCLIB_sout_buffer, BUFSIZ, 0, _IOLBF, /* mbstate, */ &_PDCLIB_serr };
29 static struct _PDCLIB_file_t _PDCLIB_sin  = { 0, { 0 }, _PDCLIB_sin_buffer, BUFSIZ, 0, _IOLBF, /* mbstate, */ &_PDCLIB_sout };
30
31 struct _PDCLIB_file_t * stdin  = &_PDCLIB_sin;
32 struct _PDCLIB_file_t * stdout = &_PDCLIB_sout;
33 struct _PDCLIB_file_t * stderr = &_PDCLIB_serr;
34
35 #endif
36
37 #ifdef TEST
38 /* TODO: Necessity of this undef should probably be circumvented. */
39 #undef SEEK_SET
40 #include <_PDCLIB_test.h>
41
42 int main( void )
43 {
44     TESTCASE( NO_TESTDRIVER );
45     return TEST_RESULTS;
46 }
47
48 #endif