]> pd.if.org Git - pdclib/blob - _PDCLIB_stdstreams.c
9ce11152bf09a189330ef56644c81158925fd05b
[pdclib] / _PDCLIB_stdstreams.c
1 /* _PDCLIB_stdstream
2
3    This file is part of the Public Domain C Library (PDCLib).
4    Permission is granted to use, modify, and / or redistribute at will.
5 */
6
7 #include <stdio.h>
8 #include <locale.h>
9 #include <limits.h>
10
11 #ifndef REGTEST
12 #include <_PDCLIB_io.h>
13 #include <threads.h>
14
15 static char _PDCLIB_sin_buffer[BUFSIZ];
16 static char _PDCLIB_sout_buffer[BUFSIZ];
17 static char _PDCLIB_serr_buffer[BUFSIZ];
18
19 static unsigned char _PDCLIB_sin_ungetbuf[_PDCLIB_UNGETCBUFSIZE];
20 static unsigned char _PDCLIB_sout_ungetbuf[_PDCLIB_UNGETCBUFSIZE];
21 static unsigned char _PDCLIB_serr_ungetbuf[_PDCLIB_UNGETCBUFSIZE];
22
23 extern _PDCLIB_fileops_t _PDCLIB_fileops;
24
25 static FILE _PDCLIB_serr = {
26     .ops        = &_PDCLIB_fileops,
27     .handle     = { .pointer = NULL },
28     .buffer     = _PDCLIB_serr_buffer,
29     .bufsize    = BUFSIZ,
30     .bufidx     = 0,
31     .bufend     = 0,
32     .ungetidx   = 0,
33     .ungetbuf   = _PDCLIB_serr_ungetbuf,
34     .status     = _IONBF | _PDCLIB_FWRITE | _PDCLIB_STATIC,
35     .filename   = NULL,
36     .next       = NULL,
37 };
38 static FILE _PDCLIB_sout = {
39     .ops        = &_PDCLIB_fileops,
40     .handle     = { .pointer = NULL },
41     .buffer     = _PDCLIB_sout_buffer,
42     .bufsize    = BUFSIZ,
43     .bufidx     = 0,
44     .bufend     = 0,
45     .ungetidx   = 0,
46     .ungetbuf   = _PDCLIB_sout_ungetbuf,
47     .status     = _IOLBF | _PDCLIB_FWRITE | _PDCLIB_STATIC,
48     .filename   = NULL,
49     .next       = &_PDCLIB_serr
50 };
51 static FILE _PDCLIB_sin  = {
52     .ops        = &_PDCLIB_fileops,
53     .handle     = { .pointer = NULL },
54     .buffer     = _PDCLIB_sin_buffer,
55     .bufsize    = BUFSIZ,
56     .bufidx     = 0,
57     .bufend     = 0,
58     .ungetidx   = 0,
59     .ungetbuf   = _PDCLIB_sin_ungetbuf,
60     .status     = _IOLBF | _PDCLIB_FREAD | _PDCLIB_STATIC,
61     .filename   = NULL,
62     .next       = &_PDCLIB_sout
63 };
64
65 FILE * stdin  = &_PDCLIB_sin;
66 FILE * stdout = &_PDCLIB_sout;
67 FILE * stderr = &_PDCLIB_serr;
68
69 FILE * _PDCLIB_filelist = &_PDCLIB_sin;
70
71 /* Todo: Better solution than this! */
72 __attribute__((constructor)) static void init_stdio(void)
73 {
74     _PDCLIB_initclocale( &_PDCLIB_global_locale );
75     mtx_init(&stdin->lock,  mtx_recursive);
76     mtx_init(&stdout->lock, mtx_recursive);
77     mtx_init(&stderr->lock, mtx_recursive);
78 }
79
80 #endif
81
82 #ifdef TEST
83 #include <_PDCLIB_test.h>
84
85 int main( void )
86 {
87     /* Testing covered by several other testdrivers using stdin / stdout /
88        stderr.
89     */
90     return TEST_RESULTS;
91 }
92
93 #endif