summaryrefslogtreecommitdiffstats
path: root/src/bfstd.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2023-10-27 10:58:47 -0400
committerTavian Barnes <tavianator@tavianator.com>2023-10-27 11:15:07 -0400
commit14ef89a442f7a027f52fd688b438c5fa627b6af7 (patch)
treeb28e2f7114b067a26af6fffea044615d57ef10c8 /src/bfstd.c
parent8ced65189cbea5ff0b06482713d647ca57c91f81 (diff)
downloadbfs-14ef89a442f7a027f52fd688b438c5fa627b6af7.tar.xz
bfstd: Expose xmbrtowc() and use it in eval_status()
Diffstat (limited to 'src/bfstd.c')
-rw-r--r--src/bfstd.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/bfstd.c b/src/bfstd.c
index cdc33f1..a5a7e54 100644
--- a/src/bfstd.c
+++ b/src/bfstd.c
@@ -586,18 +586,18 @@ int xstrtofflags(const char **str, unsigned long long *set, unsigned long long *
#endif
}
-/** mbrtowc() wrapper. */
-static int xmbrtowc(wchar_t *wc, size_t *i, const char *str, size_t len, mbstate_t *mb) {
- size_t mblen = mbrtowc(wc, str + *i, len - *i, mb);
+wint_t xmbrtowc(const char *str, size_t *i, size_t len, mbstate_t *mb) {
+ wchar_t wc;
+ size_t mblen = mbrtowc(&wc, str + *i, len - *i, mb);
switch (mblen) {
case -1: // Invalid byte sequence
case -2: // Incomplete byte sequence
*i += 1;
memset(mb, 0, sizeof(*mb));
- return -1;
+ return WEOF;
default:
*i += mblen;
- return 0;
+ return wc;
}
}
@@ -609,12 +609,12 @@ size_t xstrwidth(const char *str) {
memset(&mb, 0, sizeof(mb));
for (size_t i = 0; i < len;) {
- wchar_t wc;
- if (xmbrtowc(&wc, &i, str, len, &mb) == 0) {
- ret += wcwidth(wc);
- } else {
+ wint_t wc = xmbrtowc(str, &i, len, &mb);
+ if (wc == WEOF) {
// Assume a single-width '?'
++ret;
+ } else {
+ ret += wcwidth(wc);
}
}
@@ -729,8 +729,8 @@ multibyte:
memset(&mb, 0, sizeof(mb));
for (size_t j = i; i < len; i = j) {
- wchar_t wc;
- if (xmbrtowc(&wc, &j, str, len, &mb) != 0) {
+ wint_t wc = xmbrtowc(str, &j, len, &mb);
+ if (wc == WEOF) {
break;
}
if (!xiswprint(wc, flags)) {
@@ -781,8 +781,8 @@ static char *dollar_quote(char *dest, char *end, const char *str, size_t len, en
size_t start = i;
bool safe = false;
- wchar_t wc;
- if (xmbrtowc(&wc, &i, str, len, &mb) == 0) {
+ wint_t wc = xmbrtowc(str, &i, len, &mb);
+ if (wc != WEOF) {
safe = xiswprint(wc, flags);
}