diff options
Diffstat (limited to 'src/u8c/vprint.c')
-rw-r--r-- | src/u8c/vprint.c | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/src/u8c/vprint.c b/src/u8c/vprint.c index a86afcf..7555ce1 100644 --- a/src/u8c/vprint.c +++ b/src/u8c/vprint.c @@ -13,6 +13,7 @@ If not, see <https://www.gnu.org/licenses/>. */ +# include "intern.h" # include <assert.h> # include <stdarg.h> # include <stdbool.h> @@ -20,14 +21,14 @@ # include <stdio.h> # include <stdlib.h> # include <u8c/SIZE_C.h> -# include <u8c/errtyp.h> -# include <u8c/seterr.h> -# include <u8c/u32free.h> -# include <u8c/u8enc.h> -# include <u8c/u8free.h> -# include <u8c/vfmt.h> -# include <u8c/vprint.h> +# include <u8c/err.h> +# include <u8c/fmt.h> +# include <u8c/u32.h> +# include <u8c/u8.h> # include <uchar.h> +# if defined(u8c_bethrdsafe) +# include <threads.h> +# endif bool u8c_vprint(FILE * _fp,char32_t const * const _msg,va_list _args) { assert(_msg != NULL); char32_t const * str0 = NULL; @@ -36,9 +37,18 @@ bool u8c_vprint(FILE * _fp,char32_t const * const _msg,va_list _args) { unsigned char const * str1 = NULL; u8c_u8enc(&str1sz,&str1,str0); assert(str1sz > SIZE_C(0x0)); - if(fwrite(str1,sizeof(uint_least8_t),str1sz - SIZE_C(0x1),_fp) < str1sz - SIZE_C(0x1)) { - u8c_seterr(U"u8c_vprint: fwrite: Unable to write to stdout.",u8c_errtyp_badio); - return true; +# if defined(u8c_bethrdsafe) + mtx_lock(&u8c_dat.outlock); +# endif + { + register size_t const val = fwrite(str1,sizeof(uint_least8_t),str1sz - SIZE_C(0x1),_fp); +# if defined(u8c_bethrdsafe) + mtx_unlock(&u8c_dat.outlock); +# endif + if(val < str1sz - SIZE_C(0x1)) { + u8c_seterr(U"u8c_vprint: fwrite: Unable to write to stdout.",u8c_errtyp_badio); + return true; + } } u8c_u32free(&str0); u8c_u8free(&str1); |