diff options
author | Darren Tucker <dtucker@zip.com.au> | 2016-07-14 10:59:09 +1000 |
---|---|---|
committer | Darren Tucker <dtucker@zip.com.au> | 2016-07-14 10:59:09 +1000 |
commit | a2333584170a565adf4f209586772ef8053b10b8 (patch) | |
tree | 37e1f144bdabc09b1ce89c2e6fe603bc8845e7c2 /openbsd-compat/bsd-misc.c | |
parent | 8aaec7050614494014c47510b7e94daf6e644c62 (diff) |
Add compat code for missing wcwidth.
If we don't have wcwidth force fallback implementations of nl_langinfo
and mbtowc. Based on advice from Ingo Schwarze.
Diffstat (limited to 'openbsd-compat/bsd-misc.c')
-rw-r--r-- | openbsd-compat/bsd-misc.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 2a788e47..18bf62dd 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -284,3 +284,20 @@ pledge(const char *promises, const char *paths[]) return 0; } #endif + +#ifndef HAVE_MBTOWC +/* a mbtowc that only supports ASCII */ +int +mbtowc(wchar_t *pwc, const char *s, size_t n) +{ + if (s == NULL || *s == '\0') + return 0; /* ASCII is not state-dependent */ + if (*s < 0 || *s > 0x7f || n < 1) { + errno = EOPNOTSUPP; + return -1; + } + if (pwc != NULL) + *pwc = *s; + return 1; +} +#endif |