]> pd.if.org Git - pdclib/blobdiff - platform/example/functions/_PDCLIB/stdinit.c
Ad-hoc solutions for perror() and strerror().
[pdclib] / platform / example / functions / _PDCLIB / stdinit.c
index c8122c5d44070d9169a2e75d28cd146d1ecee0ec..78c76e259e45ab1ae62a0f310dcb8806d0e30cba 100644 (file)
 
 #ifndef REGTEST
 
-/* TODO: Initialize stdin, stdout, stderr */
+/* In a POSIX system, stdin / stdout / stderr are equivalent to the (int) file
+   descriptors 0, 1, and 2 respectively.
+*/
+/* TODO: This is proof-of-concept, requires finetuning. */
+static char _PDCLIB_sin_buffer[BUFSIZ];
+static char _PDCLIB_sout_buffer[BUFSIZ];
+static char _PDCLIB_serr_buffer[BUFSIZ];
+
+static unsigned char _PDCLIB_sin_ungetbuf[_PDCLIB_UNGETCBUFSIZE];
+static unsigned char _PDCLIB_sout_ungetbuf[_PDCLIB_UNGETCBUFSIZE];
+static unsigned char _PDCLIB_serr_ungetbuf[_PDCLIB_UNGETCBUFSIZE];
+
+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 };
+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 };
+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 };
+
+struct _PDCLIB_file_t * stdin  = &_PDCLIB_sin;
+struct _PDCLIB_file_t * stdout = &_PDCLIB_sout;
+struct _PDCLIB_file_t * stderr = &_PDCLIB_serr;
+
+/* FIXME: This approach is a possible attack vector. */
+struct _PDCLIB_file_t * _PDCLIB_filelist = &_PDCLIB_sin;
 
 #endif
 
 #ifdef TEST
-/* TODO: Necessity of this undef should probably be circumvented. */
-#undef SEEK_SET
 #include <_PDCLIB_test.h>
 
 int main( void )
 {
-    TESTCASE( NO_TESTDRIVER );
+    /* Testing covered by several other testdrivers using stdin / stdout / 
+       stderr.
+    */
     return TEST_RESULTS;
 }