X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=platform%2Fgandr%2Ffunctions%2F_PDCLIB%2F_PDCLIB_stdinit.c;h=1fa71f0c0ac8dc6f3315a6ccebcde70408a03e10;hp=b6b378e3957c1891443c032c2f2be6be496fb18f;hb=da0f3f353d417fed71f358a48d5d5394145e460d;hpb=c83b63d8752d32b5fe82aa2b1c3b570eef531436 diff --git a/platform/gandr/functions/_PDCLIB/_PDCLIB_stdinit.c b/platform/gandr/functions/_PDCLIB/_PDCLIB_stdinit.c index b6b378e..1fa71f0 100644 --- a/platform/gandr/functions/_PDCLIB/_PDCLIB_stdinit.c +++ b/platform/gandr/functions/_PDCLIB/_PDCLIB_stdinit.c @@ -9,71 +9,12 @@ #include #ifndef REGTEST -#include <_PDCLIB_io.h> -#include <_PDCLIB_locale.h> -#include <_PDCLIB_clocale.h> +#include "_PDCLIB_locale.h" +#include "_PDCLIB_clocale.h" #include -/* 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]; - -extern _PDCLIB_fileops_t _PDCLIB_fileops; - -static FILE _PDCLIB_serr = { - .ops = &_PDCLIB_fileops, - .handle = { .pointer = NULL }, - .buffer = _PDCLIB_serr_buffer, - .bufsize = BUFSIZ, - .bufidx = 0, - .bufend = 0, - .ungetidx = 0, - .ungetbuf = _PDCLIB_serr_ungetbuf, - .status = _IONBF | _PDCLIB_FWRITE | _PDCLIB_STATIC, - .filename = NULL, - .next = NULL, -}; -static FILE _PDCLIB_sout = { - .ops = &_PDCLIB_fileops, - .handle = { .pointer = NULL }, - .buffer = _PDCLIB_sout_buffer, - .bufsize = BUFSIZ, - .bufidx = 0, - .bufend = 0, - .ungetidx = 0, - .ungetbuf = _PDCLIB_sout_ungetbuf, - .status = _IOLBF | _PDCLIB_FWRITE | _PDCLIB_STATIC, - .filename = NULL, - .next = &_PDCLIB_serr -}; -static FILE _PDCLIB_sin = { - .ops = &_PDCLIB_fileops, - .handle = { .pointer = NULL }, - .buffer = _PDCLIB_sin_buffer, - .bufsize = BUFSIZ, - .bufidx = 0, - .bufend = 0, - .ungetidx = 0, - .ungetbuf = _PDCLIB_sin_ungetbuf, - .status = _IOLBF | _PDCLIB_FREAD | _PDCLIB_STATIC, - .filename = NULL, - .next = &_PDCLIB_sout -}; - -FILE * stdin = &_PDCLIB_sin; -FILE * stdout = &_PDCLIB_sout; -FILE * stderr = &_PDCLIB_serr; - tss_t _PDCLIB_locale_tss; -/* FIXME: This approach is a possible attack vector. */ -FILE * _PDCLIB_filelist = &_PDCLIB_sin; - /* "C" locale - defaulting to ASCII-7. 1 kByte (+ 4 byte) of data. Each line: flags, lowercase, uppercase, collation. @@ -338,10 +279,10 @@ static const _PDCLIB_ctype_t global_ctype[] = { { 0x00, 0xFF, 0xFF, 0xFF } }; -extern const struct _PDCLIB_charcodec _PDCLIB_ascii_codec; +extern const struct _PDCLIB_charcodec_t _PDCLIB_ascii_codec; struct _PDCLIB_locale _PDCLIB_global_locale = { ._Codec = &_PDCLIB_ascii_codec, - ._Conv = { + ._Conv = { /* decimal_point */ (char *)".", /* thousands_sep */ (char *)"", /* grouping */ (char *)"", @@ -369,30 +310,95 @@ struct _PDCLIB_locale _PDCLIB_global_locale = { }, ._CType = &global_ctype[1], ._ErrnoStr = { - /* no error */ (char *)"", - /* ERANGE */ (char *)"ERANGE (Range error)", - /* EDOM */ (char *)"EDOM (Domain error)", - /* EILSEQ */ (char *)"EILSEQ (Illegal sequence)" + "Success", + "ERANGE (result out of range)", + "EDOM (argument out of domain)", + "EILSEQ (illegal byte sequence)", + "E2BIG (argument list too long)", + "ECONNRESET (connection reset)", + "EISCONN (already connected)", + "ENOENT (no such file or directory)", + "ENOTRECOVERABLE (state not recoverable)", + "EROFS (read only file system)", + "EACCES (permission denied)", + "EDEADLK (resource deadlock would occur)", + "EISDIR (is a directory)", + "ENOEXEC (executable format error)", + "ENOTSOCK (not a socket)", + "ESPIPE (invalid seek)", + "EADDRINUSE (address in use)", + "EDESTADDRREQ (destination address required)", + "ELOOP (too many symbolic link levels)", + "ENOLCK (no lock available)", + "ENOTSUP (not supported)", + "ESRCH (no such process)", + "EADDRNOTAVAIL (address not available)", + "EMFILE (too many files open)", + "ENOLINK (no link)", + "ENOTTY (inappropriate io control operation)", + "ETIME (stream timeout)", + "EAFNOSUPPORT (address family not supported)", + "EEXIST (file exists)", + "EMLINK (too many links)", + "ENOMEM (not enough memory)", + "ENXIO (no such device or address)", + "ETIMEDOUT (timed out)", + "EAGAIN (resource unavailable try again)", + "EFAULT (bad address)", + "EMSGSIZE (message size)", + "ENOMSG (no message)", + "EOPNOTSUPP (operation not supported)", + "ETXTBSY (text file busy)", + "EALREADY (connection already in progress)", + "EFBIG (file too large)", + "ENAMETOOLONG (filename too long)", + "ENOPROTOOPT (no protocol option)", + "EOVERFLOW (value too large)", + "EBADF (bad file descriptor)", + "EHOSTUNREACH (host unreachable)", + "ENETDOWN (network down)", + "ENOSPC (no space on device)", + "EOWNERDEAD (owner dead)", + "EXDEV (cross device link)", + "EBADMSG (bad message)", + "EIDRM (identifier removed)", + "ENETRESET (network reset)", + "ENOSR (no stream resources)", + "EPERM (operation not permitted)", + "EBUSY (device or resource busy)", + "ENETUNREACH (network unreachable)", + "ENOSTR (not a stream)", + "EPIPE (broken pipe)", + "ECANCELED (operation canceled)", + "EINPROGRESS (operation in progress)", + "ENFILE (too many files open in system)", + "ENOSYS (function not supported)", + "EPROTO (protocol error)", + "ECHILD (no child process)", + "EINTR (interrupted)", + "ENOBUFS (no buffer space)", + "ENOTCONN (not connected)", + "EPROTONOSUPPORT (protocol not supported)", + "ECONNABORTED (connection aborted)", + "EINVAL (invalid argument)", + "ENODATA (no message available)", + "ENOTDIR (not a directory)", + "EPROTOTYPE (wrong protocol type)", + "EIO (io error)", + "ECONNREFUSED (connection refused)", + "ENODEV (no such device)", + "ENOTEMPTY (directory not empty)", }, }; -/* Todo: Better solution than this! */ -__attribute__((constructor)) void init_stdio(void) -{ - _PDCLIB_initclocale( &_PDCLIB_global_locale ); - mtx_init(&stdin->lock, mtx_recursive); - mtx_init(&stdout->lock, mtx_recursive); - mtx_init(&stderr->lock, mtx_recursive); -} - #endif #ifdef TEST -#include <_PDCLIB_test.h> +#include "_PDCLIB_test.h" int main( void ) { - /* Testing covered by several other testdrivers using stdin / stdout / + /* Testing covered by several other testdrivers using stdin / stdout / stderr. */ return TEST_RESULTS;