diff options
Diffstat (limited to 'src/stdlib')
-rw-r--r-- | src/stdlib/abort_handler_s.c | 10 | ||||
-rw-r--r-- | src/stdlib/bsearch_s.c | 49 | ||||
-rw-r--r-- | src/stdlib/constraint_handler_t.c | 5 | ||||
-rw-r--r-- | src/stdlib/getenv_s.c | 27 | ||||
-rw-r--r-- | src/stdlib/ignore_handler_s.c | 24 | ||||
-rw-r--r-- | src/stdlib/mbstowcs_s.c | 26 | ||||
-rw-r--r-- | src/stdlib/qsort_s.c | 29 | ||||
-rw-r--r-- | src/stdlib/set_constraint_handler_s.c | 11 | ||||
-rw-r--r-- | src/stdlib/wcstombs_s.c | 28 | ||||
-rw-r--r-- | src/stdlib/wctomb_s.c | 32 |
10 files changed, 241 insertions, 0 deletions
diff --git a/src/stdlib/abort_handler_s.c b/src/stdlib/abort_handler_s.c new file mode 100644 index 00000000..8f7ef71a --- /dev/null +++ b/src/stdlib/abort_handler_s.c @@ -0,0 +1,10 @@ +#include "stdlib.h" + +void abort_handler_s(const char * restrict msg, void * restrict ptr, errno_t error) +{ + __C_EXT(1, 201112L); +} + +/* +CEXT1(201112) +*/ diff --git a/src/stdlib/bsearch_s.c b/src/stdlib/bsearch_s.c new file mode 100644 index 00000000..12a19c25 --- /dev/null +++ b/src/stdlib/bsearch_s.c @@ -0,0 +1,49 @@ +#include <stddef.h> + +/** binary search **/ +void *bsearch_s(const void * key, const void * base, + rsize_t nmemb, rsize_t size, + int (*compar)(const void *x, const void *y, void * context), + void *context) +{ + __C_EXT(1, 201112L); + /* TODO: testing */ + void *ret = NULL; + size_t i = nmemb / 2; + unsigned int trip = 1; + + while (ret == NULL) { + int comp = compar(key, base+i); + if (comp == 0) { + return (void*)base+i; + } else if (comp > 0) { + i -= (nmemb >> trip); + } else { + i += (nmemb >> trip); + } + } + return NULL; +} + +/*** +The fn(bsearch) function performs a binary search for arg(key) in the array +arg(base), which contains arg(nmemb) members of arg(size) bytes each. + +The search is performed by calling arg(compar) with the first argument of +arg(key), and the second being an element from the array at arg(base). The +function must return less than 0 if arg(key) is less than the other element, +0 if they are equal, and greater than 0 if arg(key) is greater than the other +element. +***/ + +/* UNSPECIFIED: which element is matched if two elements are equal */ +/* UNDEFINED: the array at arg(base) is not sorted */ +/* IMPLEMENTATION: - */ +/* LOCALE: - */ + +/* RETURN(NULL): no match was found */ +/* RETURN: a pointer to the matching element */ + +/* +CEXT1(201112) +*/ diff --git a/src/stdlib/constraint_handler_t.c b/src/stdlib/constraint_handler_t.c new file mode 100644 index 00000000..6c109471 --- /dev/null +++ b/src/stdlib/constraint_handler_t.c @@ -0,0 +1,5 @@ +typedef void (*constraint_handler_t)(const char * restrict msg, void * restrict ptr, errno_t error); + +/* +CEXT1(201112) +*/ diff --git a/src/stdlib/getenv_s.c b/src/stdlib/getenv_s.c new file mode 100644 index 00000000..88156c1e --- /dev/null +++ b/src/stdlib/getenv_s.c @@ -0,0 +1,27 @@ +#include <string.h> +#include "stdlib.h" + +/** get an environment variable **/ +errno_t getenv_s(size_t * restrict len, char * restrict value, rsize_t maxsize, const char * restrict name) +{ + __C_EXT(1, 201112L); + return 0; +} + +/*** +The fn(getenv) function read the environment variable arg(name) from the host +environment. +***/ + +/* UNSPECIFIED: - */ +/* UNDEFINED: modifying the returned string */ +/* IMPLEMENTATION: the set of environment variable names */ +/* IMPLEMENTATION: the method of altering the environment */ +/* LOCALE: - */ + +/* RETURN(NULL): the environment variable could not be found */ +/* RETURN: the value of the requested environment variable */ + +/* +CEXT1(201112) +*/ diff --git a/src/stdlib/ignore_handler_s.c b/src/stdlib/ignore_handler_s.c new file mode 100644 index 00000000..0a4ef62c --- /dev/null +++ b/src/stdlib/ignore_handler_s.c @@ -0,0 +1,24 @@ +#include "stdlib.h" + +/** ignore constraint violations **/ +void ignore_handler_s(const char * restrict msg, void * restrict ptr, errno_t error) +{ + __C_EXT(1, 201112L); + return; +} + +/*** +The fn(ignore_handler_s) function is suitable for use as the system constraint +handler as set by fn(set_constraint_handler_s). + +It simply returns to its caller. +***/ + +/* UNDEFINED: - */ +/* UNSPECIFIED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: - */ + +/* +CEXT1(201112) +*/ diff --git a/src/stdlib/mbstowcs_s.c b/src/stdlib/mbstowcs_s.c new file mode 100644 index 00000000..70ef0433 --- /dev/null +++ b/src/stdlib/mbstowcs_s.c @@ -0,0 +1,26 @@ +#include "stdlib.h" + +/** convert multibyte string to wide character string **/ +errno_t mbstowcs_s(size_t * restrict retval, wchar_t * restrict dst, rsize_t dstmax, const char * restrict src, rsize_t len) +{ + __C_EXT(1, 201112L); +} + +/*** +The fn(mbstowcs) function converts the string of multibyte characters arg(s) +to a string of wide characters, which are stored at arg(pwcs). No more than +arg(n) wide characters are stored at arg(pwcs). No further characters will +be converted after a null character, which is converted. +***/ + +/* UNSPECIFIED: - */ +/* UNDEFINED: the memory regions of arg(s) and arg(pwcs) overlap */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* RETURN(-1): an invalid multibyte character was encountered */ +/* RETURN: the number of wide characters converted, not counting any terminating zero */ + +/* +CEXT1(201112) +*/ diff --git a/src/stdlib/qsort_s.c b/src/stdlib/qsort_s.c new file mode 100644 index 00000000..da12d505 --- /dev/null +++ b/src/stdlib/qsort_s.c @@ -0,0 +1,29 @@ +#include "stdlib.h" + +/** sort an array **/ +errno_t qsort_s(void *base, rsize_t nmemb, rsize_t size, + int (*compar)(const void * x, const void * y, void *context), + void * context) +{ + __C_EXT(1, 201112L); + /* TODO */ +} + +/*** +The fn(qsort) function sorts the array at arg(base), which consists of +arg(nmemb) elements of arg(size) bytes each. + +The sorting is performed by calling arg(compar) with two elements of the array. +The function must return less than 0 if the first argument is less than the +second, 0 if they are equal, and greater than 0 if the first argument is +greater than the second. +***/ + +/* UNSPECIFIED: the order of equal elements */ +/* UNDEFINED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: - */ + +/* +CEXT1(201112) +*/ diff --git a/src/stdlib/set_constraint_handler_s.c b/src/stdlib/set_constraint_handler_s.c new file mode 100644 index 00000000..b32c9860 --- /dev/null +++ b/src/stdlib/set_constraint_handler_s.c @@ -0,0 +1,11 @@ +#include "stdlib.h" + +constraint_handler_t set_constraint_handler_s(constraint_handler_t handler) +{ + __C_EXT(1, 201112L); + return handler; +} + +/* +CEXT1(201112) +*/ diff --git a/src/stdlib/wcstombs_s.c b/src/stdlib/wcstombs_s.c new file mode 100644 index 00000000..b0a8980b --- /dev/null +++ b/src/stdlib/wcstombs_s.c @@ -0,0 +1,28 @@ +#include "stdlib.h" + +/** convert wide character string to multibyte string **/ +errno_t wcstombs_s(size_t * restrict retval, char * restrict dst, rsize_t dstmax, const wchar_t * restrict src, rsize_t len) +{ + __C_EXT(1, 201112L); + /* TODO */ + return 0; +} + +/*** +The fn(wcstombs) function converts the wide character string arg(pwcs) to a +multibyte string, which is stored at arg(s), beginning in the initial shift +state. No more than arg(n) bytes are written to arg(s). Conversion stops +after reaching a null wide character, which is converted and stored. +***/ + +/* UNSPECIFIED: - */ +/* UNDEFINED: the memory regions of arg(s) and arg(pwcs) overlap */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* RETURN(-1): a code was encountered which does not correspond to a valid multibyte character */ +/* RETURN: the number of bytes modified, not counting any terminating null */ + +/* +CEXT1(201112) +*/ diff --git a/src/stdlib/wctomb_s.c b/src/stdlib/wctomb_s.c new file mode 100644 index 00000000..0a3f510e --- /dev/null +++ b/src/stdlib/wctomb_s.c @@ -0,0 +1,32 @@ +#include "stdlib.h" + +/** convert wide character to multibyte character **/ +errno_t wctomb_s(int * restrict status, char * restrict s, rsize_t smax, wchar_t wc) +{ + __C_EXT(1, 201112L); + /* TODO */ + return 0; +} + +/*** +The fn(wctomb) function converts the wide character arg(wchar) to a multibyte +character, which is stored at the address arg(s). At most macro(MB_CUR_MAX) +bytes are stored. + +If arg(s) is macro(NULL), fn(wctomb) tests whether multibyte encodings carry +state dependency. +***/ + +/* UNSPECIFIED: - */ +/* UNDEFINED: - */ +/* IMPLEMENTATION: - */ +/* LOCALE: LC_CTYPE */ + +/* RETURN(0): if arg(s) is macro(NULL), multibyte encodings do not have state dependencies */ +/* RETURN(NZ): if arg(s) is macro(NULL), multibyte encodings do have state dependencies */ +/* RETURN(-1): the value of arg(wchar) does not correspond to a valid multibyte character */ +/* RETURN: the number of bytes contained in the multibyte character corresponding to arg(wchar) */ + +/* +CEXT1(201112) +*/ |