Path: blob/master/waterbox/libc/internals/_PDCLIB_config.h
2 views
#ifndef _PDCLIB_CONFIG_H1#define _PDCLIB_CONFIG_H23/* Internal PDCLib configuration <_PDCLIB_config.h>4(Generic Template)56This file is part of the Public Domain C Library (PDCLib).7Permission is granted to use, modify, and / or redistribute at will.8*/910/* -------------------------------------------------------------------------- */11/* Misc */12/* -------------------------------------------------------------------------- */1314/* The character (sequence) your platform uses as newline. */15#define _PDCLIB_endl "\n"1617/* exit() can signal success to the host environment by the value of zero or */18/* the constant EXIT_SUCCESS. Failure is signaled by EXIT_FAILURE. Note that */19/* any other return value is "implementation-defined", i.e. your environment */20/* is not required to handle it gracefully. Set your definitions here. */21#define _PDCLIB_SUCCESS 022#define _PDCLIB_FAILURE -12324/* qsort() in <stdlib.h> requires a function that swaps two memory areas. */25/* Below is a naive implementation that can be improved significantly for */26/* specific platforms, e.g. by swapping int instead of char. */27#define _PDCLIB_memswp( i, j, size ) char tmp; do { tmp = *i; *i++ = *j; *j++ = tmp; } while ( --size );2829/* -------------------------------------------------------------------------- */30/* Integers */31/* -------------------------------------------------------------------------- */32/* Assuming 8-bit char, two's-complement architecture here. 'short' being */33/* 16 bit, 'int' being either 16, 32 or 64 bit, 'long' being either 32 or 64 */34/* bit (but 64 bit only if 'int' is 32 bit), and 'long long' being 64 bit if */35/* 'long' is not, 64 or 128 bit otherwise. */36/* Author is quite willing to support other systems but would like to hear of */37/* interest in such support and details on the to-be-supported architecture */38/* first, before going to lengths about it. */39/* -------------------------------------------------------------------------- */4041/* Comment out (or delete) the line below if your 'char' type is unsigned. */42#define _PDCLIB_CHAR_SIGNED 14344/* Width of the integer types short, int, long, and long long, in bytes. */45/* SHRT == 2, INT >= SHRT, LONG >= INT >= 4, LLONG >= LONG - check your */46/* compiler manuals. */47#define _PDCLIB_SHRT_BYTES 248#define _PDCLIB_INT_BYTES 449#if defined(__LP64__) || defined(_LP64)50# define _PDCLIB_LONG_BYTES 851#else52# define _PDCLIB_LONG_BYTES 453#endif54#define _PDCLIB_LLONG_BYTES 85556/* <stdlib.h> defines the div() function family that allows taking quotient */57/* and remainder of an integer division in one operation. Many platforms */58/* support this in hardware / opcode, and the standard permits ordering of */59/* the return structure in any way to fit the hardware. That is why those */60/* structs can be configured here. */6162struct _PDCLIB_div_t63{64int quot;65int rem;66};6768struct _PDCLIB_ldiv_t69{70long int quot;71long int rem;72};7374struct _PDCLIB_lldiv_t75{76long long int quot;77long long int rem;78};7980/* -------------------------------------------------------------------------- */81/* <stdint.h> defines a set of integer types that are of a minimum width, and */82/* "usually fastest" on the system. (If, for example, accessing a single char */83/* requires the CPU to access a complete int and then mask out the char, the */84/* "usually fastest" type of at least 8 bits would be int, not char.) */85/* If you do not have information on the relative performance of the types, */86/* the standard allows you to define any type that meets minimum width and */87/* signedness requirements. */88/* The defines below are just configuration for the real typedefs and limit */89/* definitions done in <_PDCLIB_int.h>. The uppercase define shall be either */90/* SHRT, INT, LONG, or LLONG (telling which values to use for the *_MIN and */91/* *_MAX limits); the lowercase define either short, int, long, or long long */92/* (telling the actual type to use). */93/* The third define is the length modifier used for the type in printf() and */94/* scanf() functions (used in <inttypes.h>). */95/* If you require a non-standard datatype to define the "usually fastest" */96/* types, PDCLib as-is doesn't support that. Please contact the author with */97/* details on your platform in that case, so support can be added. */98/* -------------------------------------------------------------------------- */99100#define _PDCLIB_FAST8 INT101#define _PDCLIB_fast8 int102#define _PDCLIB_FAST8_CONV103104#define _PDCLIB_FAST16 INT105#define _PDCLIB_fast16 int106#define _PDCLIB_FAST16_CONV107108#define _PDCLIB_FAST32 INT109#define _PDCLIB_fast32 int110#define _PDCLIB_FAST32_CONV111112#define _PDCLIB_FAST64 LLONG113#define _PDCLIB_fast64 long long114#define _PDCLIB_FAST64_CONV ll115116/* -------------------------------------------------------------------------- */117/* What follows are a couple of "special" typedefs and their limits. Again, */118/* the actual definition of the limits is done in <_PDCLIB_int.h>, and the */119/* defines here are merely "configuration". See above for details. */120/* -------------------------------------------------------------------------- */121122/* The result type of substracting two pointers */123#define _PDCLIB_ptrdiff long124#define _PDCLIB_PTRDIFF LONG125#define _PDCLIB_PTR_CONV126127/* An integer type that can be accessed as atomic entity (think asynchronous128interrupts). The type itself is not defined in a freestanding environment,129but its limits are. (Don't ask.)130*/131#define _PDCLIB_sig_atomic int132#define _PDCLIB_SIG_ATOMIC INT133134/* Result type of the 'sizeof' operator (must be unsigned) */135#define _PDCLIB_size unsigned long136#define _PDCLIB_SIZE ULONG137138/* Large enough an integer to hold all character codes of the largest supported139locale.140*/141#define _PDCLIB_wint signed int142#define _PDCLIB_wchar unsigned int143#define _PDCLIB_WCHAR UINT144145#define _PDCLIB_intptr long146#define _PDCLIB_INTPTR LONG147148/* Largest supported integer type. Implementation note: see _PDCLIB_atomax(). */149#define _PDCLIB_intmax long long int150#define _PDCLIB_INTMAX LLONG151#define _PDCLIB_MAX_CONV ll152/* You are also required to state the literal suffix for the intmax type */153#define _PDCLIB_INTMAX_LITERAL ll154155/* <inttypes.h> defines imaxdiv(), which is equivalent to the div() function */156/* family (see further above) with intmax_t as basis. */157158struct _PDCLIB_imaxdiv_t159{160_PDCLIB_intmax quot;161_PDCLIB_intmax rem;162};163164/* <time.h>: time_t165* The C standard doesn't define what representation of time is stored in166* time_t when returned by time() , but POSIX defines it to be seconds since the167* UNIX epoch and most appplications expect that.168*169* time_t is also used as the tv_sec member of struct timespec, which *is*170* defined as a linear count of seconds.171*172* time_t is defined as a "real type", so may be a floating point type, but with173* the presence of the nanosecond accurate struct timespec, and with the lack of174* any functions for manipulating more accurate values of time_t, this is175* probably not useful.176*/177#define _PDCLIB_time unsigned long long178179/* <time.h>: clock_t180*181* A count of "clock ticks", where the length of a clock tick is unspecified by182* the standard. The implementation is required to provide a macro,183* CLOCKS_PER_SEC, which is the number of "clock ticks" which corresponds to one184* second.185*186* clock_t may be any real type (i.e. integral or floating), and its type on187* various systems differs.188*189* On XSI systems, CLOCKS_PER_SEC must be defined to 1000000190*/191#define _PDCLIB_clock double192#define _PDCLIB_CLOCKS_PER_SEC 1000000193194/* <time.h>: TIME_UTC195*196* The TIME_UTC parameter is passed to the timespec_get function in order to get197* the system time in UTC since an implementation defined epoch (not necessarily198* the same as that used for time_t). That said, on POSIX the obvious199* implementation of timespec_get for TIME_UTC is to wrap200* clock_gettime(CLOCK_REALTIME, ...), which is defined as time in UTC since the201* same epoch.202*203* This may be any non-zero integer value.204*/205#define _PDCLIB_TIME_UTC 1206207/* -------------------------------------------------------------------------- */208/* Floating Point */209/* -------------------------------------------------------------------------- */210211/* Whether the implementation rounds toward zero (0), to nearest (1), toward212positive infinity (2), or toward negative infinity (3). (-1) signifies213indeterminable rounding, any other value implementation-specific rounding.214*/215#define _PDCLIB_FLT_ROUNDS -1216217/* Whether the implementation uses exact-width precision (0), promotes float218to double (1), or promotes float and double to long double (2). (-1)219signifies indeterminable behaviour, any other value implementation-specific220behaviour.221*/222#define _PDCLIB_FLT_EVAL_METHOD 0223224/* "Number of the decimal digits (n), such that any floating-point number in the225widest supported floating type with p(max) radix (b) digits can be rounded to226a floating-point number with (n) decimal digits and back again without change227to the value p(max) log(10)b if (b) is a power of 10, [1 + p(max) log(10)b]228otherwise."22964bit IEC 60559 double format (53bit mantissa) is DECIMAL_DIG 17.23080bit IEC 60559 double-extended format (64bit mantissa) is DECIMAL_DIG 21.231*/232#define _PDCLIB_DECIMAL_DIG 17233234/* Floating point types235*236* PDCLib (at present) assumes IEEE 754 floating point formats237* The following names are used:238* SINGLE: IEEE 754 single precision (32-bit)239* DOUBLE: IEEE 754 double precision (64-bit)240* EXTENDED: IEEE 754 extended precision (80-bit, as x87)241*/242#define _PDCLIB_FLOAT_TYPE SINGLE243#define _PDCLIB_DOUBLE_TYPE DOUBLE244#if defined(__i386__) || defined(__amd64__)245#define _PDCLIB_LDOUBLE_TYPE EXTENDED246#else247#define _PDCLIB_LDOUBLE_TYPE DOUBLE248#endif249250/* -------------------------------------------------------------------------- */251/* Platform-dependent macros defined by the standard headers. */252/* -------------------------------------------------------------------------- */253254/* The offsetof macro255Contract: Expand to an integer constant expression of type size_t, which256represents the offset in bytes to the structure member from the beginning257of the structure. If the specified member is a bitfield, behaviour is258undefined.259There is no standard-compliant way to do this.260This implementation casts an integer zero to 'pointer to type', and then261takes the address of member. This is undefined behaviour but should work on262most compilers.263*/264#define _PDCLIB_offsetof( type, member ) ( (size_t) &( ( (type *) 0 )->member ) )265266/* Variable Length Parameter List Handling (<stdarg.h>)267The macros defined by <stdarg.h> are highly dependent on the calling268conventions used, and you probably have to replace them with builtins of269your compiler. The following generic implementation works only for pure270stack-based architectures, and only if arguments are aligned to pointer271type. Credits to Michael Moody, who contributed this to the Public Domain.272*/273274/* Internal helper macro. va_round is not part of <stdarg.h>. */275#define _PDCLIB_va_round( type ) ( (sizeof(type) + sizeof(void *) - 1) & ~(sizeof(void *) - 1) )276277typedef char * _PDCLIB_va_list;278#define _PDCLIB_va_arg( ap, type ) ( (ap) += (_PDCLIB_va_round(type)), ( *(type*) ( (ap) - (_PDCLIB_va_round(type)) ) ) )279#define _PDCLIB_va_copy( dest, src ) ( (dest) = (src), (void)0 )280#define _PDCLIB_va_end( ap ) ( (ap) = (char *)0, (void)0 )281#define _PDCLIB_va_start( ap, parmN ) ( (ap) = (char *) &parmN + ( _PDCLIB_va_round(parmN) ), (void)0 )282283/* -------------------------------------------------------------------------- */284/* OS "glue", part 1 */285/* These are values and data type definitions that you would have to adapt to */286/* the capabilities and requirements of your OS. */287/* The actual *functions* of the OS interface are declared in _PDCLIB_glue.h. */288/* -------------------------------------------------------------------------- */289290/* Memory management -------------------------------------------------------- */291292/* Set this to the page size of your OS. If your OS does not support paging, set293to an appropriate value. (Too small, and malloc() will call the kernel too294often. Too large, and you will waste memory.)295*/296#define _PDCLIB_MALLOC_PAGESIZE 4096297#define _PDCLIB_MALLOC_ALIGN 16298#define _PDCLIB_MALLOC_GRANULARITY 64*1024299#define _PDCLIB_MALLOC_TRIM_THRESHOLD 2*1024*1024300#define _PDCLIB_MALLOC_MMAP_THRESHOLD 256*1024301#define _PDCLIB_MALLOC_RELEASE_CHECK_RATE 4095302303/* TODO: Better document these */304305/* Locale --------------------------------------------------------------------*/306307/* Locale method. See _PDCLIB_locale.h */308#define _PDCLIB_LOCALE_METHOD _PDCLIB_LOCALE_METHOD_FAKE309310/* wchar_t encoding */311#define _PDCLIB_WCHAR_ENCODING _PDCLIB_WCHAR_ENCODING_UCS4312313/* I/O ---------------------------------------------------------------------- */314315/* The default size for file buffers. Must be at least 256. */316#define _PDCLIB_BUFSIZ 1024317318/* The minimum number of files the implementation can open simultaneously. Must319be at least 8. Depends largely on how the bookkeeping is done by fopen() /320freopen() / fclose(). The example implementation limits the number of open321files only by available memory.322*/323#define _PDCLIB_FOPEN_MAX 8324325/* Length of the longest filename the implementation guarantees to support. */326#define _PDCLIB_FILENAME_MAX 128327328/* Maximum length of filenames generated by tmpnam(). (See tmpfile.c.) */329#define _PDCLIB_L_tmpnam 46330331/* Number of distinct file names that can be generated by tmpnam(). */332#define _PDCLIB_TMP_MAX 50333334/* The values of SEEK_SET, SEEK_CUR and SEEK_END, used by fseek().335Since at least one platform (POSIX) uses the same symbols for its own "seek"336function, we use whatever the host defines (if it does define them).337*/338#define _PDCLIB_SEEK_SET 0339#define _PDCLIB_SEEK_CUR 1340#define _PDCLIB_SEEK_END 2341342/* The number of characters that can be buffered with ungetc(). The standard343guarantees only one (1); anything larger would make applications relying on344this capability dependent on implementation-defined behaviour (not good).345*/346#define _PDCLIB_UNGETCBUFSIZE 1347348/* errno -------------------------------------------------------------------- */349350/* These are the values that _PDCLIB_errno can be set to by the library.351352By keeping PDCLib's errno in the _PDCLIB_* namespace, the library is capable353to "translate" between errno values used by the hosting operating system and354those used and passed out by the library.355356Example: In the example platform, the remove() function uses the unlink()357system call as backend. Linux sets its errno to EISDIR if you try to unlink()358a directory, but POSIX demands EPERM. Within the remove() function, you can359catch the 'errno == EISDIR', and set '_PDCLIB_errno = _PDCLIB_EPERM'. Anyone360using PDCLib's <errno.h> will "see" EPERM instead of EISDIR (the _PDCLIB_*361prefix removed by <errno.h> mechanics).362363If you do not want that kind of translation, you might want to "match" the364values used by PDCLib with those used by the host OS, to avoid confusion.365366The C standard only defines three distinct errno values: ERANGE, EDOM, and367EILSEQ. The standard leaves it up to "the implementation" whether there are368any more beyond those three.369370However, C++11 introduced the whole list of POSIX errno values into the371standard, so PDCLib might as well define those as well.372373Sometimes the standard says to set errno to indicate an error, but does not374prescribe a value. We will use a value from the following list. If POSIX375defines a value, we use that; otherwise, we use as seems suitable.376*/377378/* These values were taken from Linux, gcc 4.8. */379#define _PDCLIB_E2BIG 7380#define _PDCLIB_EACCES 13381#define _PDCLIB_EADDRINUSE 98382#define _PDCLIB_EADDRNOTAVAIL 99383#define _PDCLIB_EAFNOSUPPORT 97384#define _PDCLIB_EAGAIN 11385#define _PDCLIB_EALREADY 114386#define _PDCLIB_EBADF 9387#define _PDCLIB_EBADMSG 74388#define _PDCLIB_EBUSY 16389#define _PDCLIB_ECANCELED 125390#define _PDCLIB_ECHILD 10391#define _PDCLIB_ECONNABORTED 103392#define _PDCLIB_ECONNREFUSED 111393#define _PDCLIB_ECONNRESET 104394#define _PDCLIB_EDEADLK 35395#define _PDCLIB_EDESTADDRREQ 89396#define _PDCLIB_EDOM 33397#define _PDCLIB_EEXIST 17398#define _PDCLIB_EFAULT 14399#define _PDCLIB_EFBIG 27400#define _PDCLIB_EHOSTUNREACH 113401#define _PDCLIB_EIDRM 43402#define _PDCLIB_EILSEQ 84403#define _PDCLIB_EINPROGRESS 115404#define _PDCLIB_EINTR 4405#define _PDCLIB_EINVAL 22406#define _PDCLIB_EIO 5407#define _PDCLIB_EISCONN 106408#define _PDCLIB_EISDIR 21409#define _PDCLIB_ELOOP 40410#define _PDCLIB_EMFILE 24411#define _PDCLIB_EMLINK 31412#define _PDCLIB_EMSGSIZE 90413#define _PDCLIB_ENAMETOOLONG 36414#define _PDCLIB_ENETDOWN 100415#define _PDCLIB_ENETRESET 102416#define _PDCLIB_ENETUNREACH 101417#define _PDCLIB_ENFILE 23418#define _PDCLIB_ENOBUFS 105419#define _PDCLIB_ENODATA 61420#define _PDCLIB_ENODEV 19421#define _PDCLIB_ENOENT 2422#define _PDCLIB_ENOEXEC 8423#define _PDCLIB_ENOLCK 37424#define _PDCLIB_ENOLINK 67425#define _PDCLIB_ENOMEM 12426#define _PDCLIB_ENOMSG 42427#define _PDCLIB_ENOPROTOOPT 92428#define _PDCLIB_ENOSPC 28429#define _PDCLIB_ENOSR 63430#define _PDCLIB_ENOSTR 60431#define _PDCLIB_ENOSYS 38432#define _PDCLIB_ENOTCONN 107433#define _PDCLIB_ENOTDIR 20434#define _PDCLIB_ENOTEMPTY 39435#define _PDCLIB_ENOTRECOVERABLE 131436#define _PDCLIB_ENOTSOCK 88437#define _PDCLIB_ENOTSUP 95438#define _PDCLIB_ENOTTY 25439#define _PDCLIB_ENXIO 6440#define _PDCLIB_EOPNOTSUPP 95441#define _PDCLIB_EOVERFLOW 75442#define _PDCLIB_EOWNERDEAD 130443#define _PDCLIB_EPERM 1444#define _PDCLIB_EPIPE 32445#define _PDCLIB_EPROTO 71446#define _PDCLIB_EPROTONOSUPPORT 93447#define _PDCLIB_EPROTOTYPE 91448#define _PDCLIB_ERANGE 34449#define _PDCLIB_EROFS 30450#define _PDCLIB_ESPIPE 29451#define _PDCLIB_ESRCH 3452#define _PDCLIB_ETIME 62453#define _PDCLIB_ETIMEDOUT 110454#define _PDCLIB_ETXTBSY 26455#define _PDCLIB_EWOULDBLOCK 11456#define _PDCLIB_EXDEV 18457458/* This is used to set the size of the array in struct lconv (<locale.h>) */459/* holding the error messages for the strerror() and perror() fuctions. If */460/* you change this value because you are using additional errno values, you */461/* *HAVE* to provide appropriate error messages for *ALL* locales. */462/* Needs to be one higher than the highest errno value above. */463#define _PDCLIB_ERRNO_MAX 132464465#endif466467468