#include <limits.h>
#ifndef REGTEST
+#include <_PDCLIB_io.h>
+#include <_PDCLIB_locale.h>
+#include <_PDCLIB_encoding.h>
+
+extern const _PDCLIB_fileops_t _PDCLIB_fileops;
/* In a POSIX system, stdin / stdout / stderr are equivalent to the (int) file
descriptors 0, 1, and 2 respectively.
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 | _PDCLIB_STATIC, 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 | _PDCLIB_STATIC, 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 | _PDCLIB_STATIC, NULL, &_PDCLIB_sout };
-struct _PDCLIB_file_t * stdin = &_PDCLIB_sin;
-struct _PDCLIB_file_t * stdout = &_PDCLIB_sout;
-struct _PDCLIB_file_t * stderr = &_PDCLIB_serr;
+static FILE _PDCLIB_serr = {
+ .ops = &_PDCLIB_fileops,
+ .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,
+ .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,
+ .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;
-/* FIXME: This approach is a possible attack vector. */
-struct _PDCLIB_file_t * _PDCLIB_filelist = &_PDCLIB_sin;
+FILE *_PDCLIB_filelist = &_PDCLIB_sin;
/* "C" locale - defaulting to ASCII-7.
1 kByte (+ 4 byte) of <ctype.h> data.
Each line: flags, lowercase, uppercase, collation.
*/
-static struct _PDCLIB_ctype_t _ctype[] = {
+static const _PDCLIB_ctype_t global_ctype[] = {
{ /* EOF */ 0, 0, 0, 0 },
{ /* NUL */ _PDCLIB_CTYPE_CNTRL, 0x00, 0x00, 0x00 },
{ /* SOH */ _PDCLIB_CTYPE_CNTRL, 0x01, 0x01, 0x01 },
{ 0x00, 0xFF, 0xFF, 0xFF }
};
-struct lconv _PDCLIB_lconv = {
- /* _PDCLIB_ctype */ _ctype + 1,
- /* _PDCLIB_errno_texts */
- {
+extern const struct _PDCLIB_charcodec _PDCLIB_ascii_codec;
+struct _PDCLIB_locale _PDCLIB_global_locale = {
+ ._Codec = &_PDCLIB_ascii_codec,
+ ._Conv = {
+ /* decimal_point */ (char *)".",
+ /* thousands_sep */ (char *)"",
+ /* grouping */ (char *)"",
+ /* mon_decimal_point */ (char *)"",
+ /* mon_thousands_sep */ (char *)"",
+ /* mon_grouping */ (char *)"",
+ /* positive_sign */ (char *)"",
+ /* negative_sign */ (char *)"",
+ /* currency_symbol */ (char *)"",
+ /* int_curr_symbol */ (char *)"",
+ /* frac_digits */ CHAR_MAX,
+ /* p_cs_precedes */ CHAR_MAX,
+ /* n_cs_precedes */ CHAR_MAX,
+ /* p_sep_by_space */ CHAR_MAX,
+ /* n_sep_by_space */ CHAR_MAX,
+ /* p_sign_posn */ CHAR_MAX,
+ /* n_sign_posn */ CHAR_MAX,
+ /* int_frac_digits */ CHAR_MAX,
+ /* int_p_cs_precedes */ CHAR_MAX,
+ /* int_n_cs_precedes */ CHAR_MAX,
+ /* int_p_sep_by_space */ CHAR_MAX,
+ /* int_n_sep_by_space */ CHAR_MAX,
+ /* int_p_sign_posn */ CHAR_MAX,
+ /* int_n_sign_posn */ CHAR_MAX,
+ },
+ ._CType = &global_ctype[1],
+ ._ErrnoStr = {
/* no error */ (char *)"",
/* ERANGE */ (char *)"ERANGE (Range error)",
/* EDOM */ (char *)"EDOM (Domain error)",
/* EILSEQ */ (char *)"EILSEQ (Illegal sequence)"
},
- /* decimal_point */ (char *)".",
- /* thousands_sep */ (char *)"",
- /* grouping */ (char *)"",
- /* mon_decimal_point */ (char *)"",
- /* mon_thousands_sep */ (char *)"",
- /* mon_grouping */ (char *)"",
- /* positive_sign */ (char *)"",
- /* negative_sign */ (char *)"",
- /* currency_symbol */ (char *)"",
- /* int_curr_symbol */ (char *)"",
- /* frac_digits */ CHAR_MAX,
- /* p_cs_precedes */ CHAR_MAX,
- /* n_cs_precedes */ CHAR_MAX,
- /* p_sep_by_space */ CHAR_MAX,
- /* n_sep_by_space */ CHAR_MAX,
- /* p_sign_posn */ CHAR_MAX,
- /* n_sign_posn */ CHAR_MAX,
- /* int_frac_digits */ CHAR_MAX,
- /* int_p_cs_precedes */ CHAR_MAX,
- /* int_n_cs_precedes */ CHAR_MAX,
- /* int_p_sep_by_space */ CHAR_MAX,
- /* int_n_sep_by_space */ CHAR_MAX,
- /* int_p_sign_posn */ CHAR_MAX,
- /* int_n_sign_posn */ CHAR_MAX,
};
#endif
/* compiler manuals. */
#define _PDCLIB_SHRT_BYTES 2
#define _PDCLIB_INT_BYTES 4
-#define _PDCLIB_LONG_BYTES 4
+#if defined(__LP64__) || defined(_LP64)
+# define _PDCLIB_LONG_BYTES 8
+#else
+# define _PDCLIB_LONG_BYTES 4
+#endif
#define _PDCLIB_LLONG_BYTES 8
/* <stdlib.h> defines the div() function family that allows taking quotient */
/* -------------------------------------------------------------------------- */
/* The result type of substracting two pointers */
-#define _PDCLIB_ptrdiff int
-#define _PDCLIB_PTRDIFF INT
+#define _PDCLIB_ptrdiff long
+#define _PDCLIB_PTRDIFF LONG
#define _PDCLIB_PTR_CONV
/* An integer type that can be accessed as atomic entity (think asynchronous
#define _PDCLIB_SIG_ATOMIC INT
/* Result type of the 'sizeof' operator (must be unsigned) */
-#define _PDCLIB_size unsigned int
-#define _PDCLIB_SIZE UINT
+#define _PDCLIB_size unsigned long
+#define _PDCLIB_SIZE ULONG
/* Large enough an integer to hold all character codes of the largest supported
locale.
#define _PDCLIB_wchar unsigned int
#define _PDCLIB_WCHAR UINT
-#define _PDCLIB_intptr int
-#define _PDCLIB_INTPTR INT
+#define _PDCLIB_intptr long
+#define _PDCLIB_INTPTR LONG
/* Largest supported integer type. Implementation note: see _PDCLIB_atomax(). */
#define _PDCLIB_intmax long long int
*/
#define _PDCLIB_DECIMAL_DIG 17
+/* Floating point types
+ *
+ * PDCLib (at present) assumes IEEE 754 floating point formats
+ * The following names are used:
+ * SINGLE: IEEE 754 single precision (32-bit)
+ * DOUBLE: IEEE 754 double precision (64-bit)
+ * EXTENDED: IEEE 754 extended precision (80-bit, as x87)
+ */
+#define _PDCLIB_FLOAT_TYPE SINGLE
+#define _PDCLIB_DOUBLE_TYPE DOUBLE
+#if defined(__i386__) || defined(__amd64__)
+ #define _PDCLIB_LDOUBLE_TYPE EXTENDED
+#else
+ #define _PDCLIB_LDOUBLE_TYPE DOUBLE
+#endif
+
/* -------------------------------------------------------------------------- */
/* Platform-dependent macros defined by the standard headers. */
/* -------------------------------------------------------------------------- */
/* TODO: Better document these */
-/* I/O ---------------------------------------------------------------------- */
+/* Locale --------------------------------------------------------------------*/
-/* The type of the file descriptor returned by _PDCLIB_open(). */
-typedef int _PDCLIB_fd_t;
+/* Locale method. See _PDCLIB_locale.h */
+/* #define _PDCLIB_LOCALE_METHOD _PDCLIB_LOCALE_METHOD_TSS */
-/* The value (of type _PDCLIB_fd_t) returned by _PDCLIB_open() if the operation
- failed.
-*/
-#define _PDCLIB_NOHANDLE ( (_PDCLIB_fd_t) -1 )
+/* wchar_t encoding */
+#define _PDCLIB_WCHAR_ENCODING _PDCLIB_WCHAR_ENCODING_UCS4
+
+/* I/O ---------------------------------------------------------------------- */
/* The default size for file buffers. Must be at least 256. */
#define _PDCLIB_BUFSIZ 1024