From 0845e12a9362756548d9281ddc1ca295c5f5b92c Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 29 May 2023 01:49:13 +0900 Subject: [PATCH] added hcl_seterrumsg() and hcl_seterrbfmt() in case the caller can't use variadic arguments --- lib/err.c | 11 +++++++++++ lib/hcl.h | 18 ++++++++++++++++-- lib/read.c | 9 +++------ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/lib/err.c b/lib/err.c index d6d4992..bd06b03 100644 --- a/lib/err.c +++ b/lib/err.c @@ -242,6 +242,17 @@ void hcl_seterrnum (hcl_t* hcl, hcl_errnum_t errnum) hcl->errmsg.len = 0; } +void hcl_seterrbmsg (hcl_t* hcl, hcl_errnum_t errnum, const hcl_bch_t* errmsg) +{ + hcl_seterrbfmt(hcl, errnum, "%hs", errmsg); +} + + +void hcl_seterrumsg (hcl_t* hcl, hcl_errnum_t errnum, const hcl_uch_t* errmsg) +{ + hcl_seterrbfmt(hcl, errnum, "%ls", errmsg); +} + static int err_bcs (hcl_fmtout_t* fmtout, const hcl_bch_t* ptr, hcl_oow_t len) { diff --git a/lib/hcl.h b/lib/hcl.h index 6a8b7d8..9509a10 100644 --- a/lib/hcl.h +++ b/lib/hcl.h @@ -2025,13 +2025,25 @@ HCL_EXPORT void hcl_seterrnum ( hcl_errnum_t errnum ); +HCL_EXPORT void hcl_seterrbmsg ( + hcl_t* hcl, + hcl_errnum_t errnum, + const hcl_bch_t* errmsg +); + +HCL_EXPORT void hcl_seterrumsg ( + hcl_t* hcl, + hcl_errnum_t errnum, + const hcl_uch_t* errmsg +); + HCL_EXPORT void hcl_seterrwithsyserr ( hcl_t* hcl, int syserr_type, int syserr_code ); -void hcl_seterrbfmtwithsyserr ( +HCL_EXPORT void hcl_seterrbfmtwithsyserr ( hcl_t* hcl, int syserr_type, int syserr_code, @@ -2039,7 +2051,7 @@ void hcl_seterrbfmtwithsyserr ( ... ); -void hcl_seterrufmtwithsyserr ( +HCL_EXPORT void hcl_seterrufmtwithsyserr ( hcl_t* hcl, int syserr_type, int syserr_code, @@ -2089,8 +2101,10 @@ HCL_EXPORT const hcl_bch_t* hcl_geterrbmsg ( #if defined(HCL_OOCH_IS_UCH) # define hcl_geterrmsg hcl_geterrumsg +# define hcl_seterrmsg hcl_seterrumsg #else # define hcl_geterrmsg hcl_geterrbmsg +# define hcl_seterrmsg hcl_seterrbmsg #endif HCL_EXPORT const hcl_ooch_t* hcl_backuperrmsg ( diff --git a/lib/read.c b/lib/read.c index a386882..472e47b 100644 --- a/lib/read.c +++ b/lib/read.c @@ -4038,13 +4038,10 @@ int hcl_attachio (hcl_t* hcl, hcl_ioimpl_t reader, hcl_ioimpl_t scanner, hcl_ioi hcl_ioinarg_t new_inarg; hcl_iooutarg_t new_outarg; - if (reader) + if (!hcl->c) { - if (!hcl->c) - { - if (init_compiler(hcl) <= -1) return -1; - inited_compiler = 1; - } + if (init_compiler(hcl) <= -1) return -1; + inited_compiler = 1; } if (reader)