From fb44227179cd8d0dbaaf694fba2d4861106add75 Mon Sep 17 00:00:00 2001 From: Owen Shepherd Date: Mon, 31 Dec 2012 20:34:22 +0000 Subject: [PATCH] PDCLIB-2 PDCLIB-9: MB_CUR_MAX macro and implementation --- functions/locale/_PDCLIB_mb_cur_max.c | 27 +++++++++++++++++++++++++++ includes/stdlib.h | 5 +++++ internals/_PDCLIB_encoding.h | 2 ++ internals/_PDCLIB_int.h | 2 ++ opt/basecodecs/_PDCLIB_ascii.c | 1 + opt/basecodecs/_PDCLIB_latin1.c | 1 + opt/basecodecs/_PDCLIB_utf8.c | 1 + 7 files changed, 39 insertions(+) create mode 100644 functions/locale/_PDCLIB_mb_cur_max.c diff --git a/functions/locale/_PDCLIB_mb_cur_max.c b/functions/locale/_PDCLIB_mb_cur_max.c new file mode 100644 index 0000000..a5f459d --- /dev/null +++ b/functions/locale/_PDCLIB_mb_cur_max.c @@ -0,0 +1,27 @@ +/* _PDCLIB_mb_cur_max( void ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include +#ifndef REGTEST +#include <_PDCLIB_locale.h> +#include <_PDCLIB_encoding.h> + +size_t _PDCLIB_mb_cur_max( void ) +{ + return _PDCLIB_threadlocale()->_Codec->__mb_max; +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + TESTCASE( NO_TESTDRIVER ); + return TEST_RESULTS; +} +#endif diff --git a/includes/stdlib.h b/includes/stdlib.h index 22cc80c..1151d1a 100644 --- a/includes/stdlib.h +++ b/includes/stdlib.h @@ -21,6 +21,11 @@ typedef _PDCLIB_size_t size_t; #define NULL _PDCLIB_NULL #endif +#ifndef _PDCLIB_MB_CUR_MAX_DEFINED +#define _PDCLIB_MB_CUR_MAX_DEFINED +#define MB_CUR_MAX (_PDCLIB_mb_cur_max()) +#endif + /* Numeric conversion functions */ /* TODO: atof(), strtof(), strtod(), strtold() */ diff --git a/internals/_PDCLIB_encoding.h b/internals/_PDCLIB_encoding.h index f53d77a..9b31735 100644 --- a/internals/_PDCLIB_encoding.h +++ b/internals/_PDCLIB_encoding.h @@ -138,6 +138,8 @@ struct _PDCLIB_charcodec { _PDCLIB_size_t *_PDCLIB_restrict _P_insz, _PDCLIB_mbstate_t *_PDCLIB_restrict _P_ps ); + + size_t __mb_max; }; #endif diff --git a/internals/_PDCLIB_int.h b/internals/_PDCLIB_int.h index c9988a9..52ba8b3 100644 --- a/internals/_PDCLIB_int.h +++ b/internals/_PDCLIB_int.h @@ -364,6 +364,8 @@ typedef struct _PDCLIB_charcodec *_PDCLIB_charcodec_t; typedef struct _PDCLIB_locale *_PDCLIB_locale_t; typedef struct lconv _PDCLIB_lconv_t; +_PDCLIB_size_t _PDCLIB_mb_cur_max( void ); + /* -------------------------------------------------------------------------- */ /* stdio */ /* -------------------------------------------------------------------------- */ diff --git a/opt/basecodecs/_PDCLIB_ascii.c b/opt/basecodecs/_PDCLIB_ascii.c index 86001af..e07e2ba 100644 --- a/opt/basecodecs/_PDCLIB_ascii.c +++ b/opt/basecodecs/_PDCLIB_ascii.c @@ -62,6 +62,7 @@ static bool c32toascii( struct _PDCLIB_charcodec _PDCLIB_ascii_codec = { .__mbstoc32s = asciitoc32, .__c32stombs = c32toascii, + .__mb_max = 1, }; #endif diff --git a/opt/basecodecs/_PDCLIB_latin1.c b/opt/basecodecs/_PDCLIB_latin1.c index b397001..72a3446 100644 --- a/opt/basecodecs/_PDCLIB_latin1.c +++ b/opt/basecodecs/_PDCLIB_latin1.c @@ -60,6 +60,7 @@ static bool c32tolatin1( struct _PDCLIB_charcodec _PDCLIB_latin1_codec = { .__mbstoc32s = latin1toc32, .__c32stombs = c32tolatin1, + .__mb_max = 1, }; #endif diff --git a/opt/basecodecs/_PDCLIB_utf8.c b/opt/basecodecs/_PDCLIB_utf8.c index 2b3f4f6..bac0e82 100644 --- a/opt/basecodecs/_PDCLIB_utf8.c +++ b/opt/basecodecs/_PDCLIB_utf8.c @@ -231,6 +231,7 @@ static bool c32toutf8( struct _PDCLIB_charcodec _PDCLIB_utf8_codec = { .__mbstoc32s = utf8toc32, .__c32stombs = c32toutf8, + .__mb_max = 4, }; #endif -- 2.40.0