diff options
| author | Anders Betts <anders.betts@gmail.com> | 2026-09-23 11:51:44 +0200 |
|---|---|---|
| committer | Anders Betts <anders.betts@gmail.com> | 2026-09-23 11:51:44 +0200 |
| commit | 8dc2e7d2f11aee4e70c3675e4ba6dd255a47e0e4 (patch) | |
| tree | bc1b0fe58a991d26499386f17e3c4c72b69eea1d /clients/bokfweb.c | |
| parent | 09a5832797073b5926e533defff1be289d29d351 (diff) | |
| download | bokf-8dc2e7d2f11aee4e70c3675e4ba6dd255a47e0e4.tar.gz bokf-8dc2e7d2f11aee4e70c3675e4ba6dd255a47e0e4.zip | |
web: ship glibc C.utf8 so the web TUI shows åäö
The cross-built bokftui is static glibc; in the Alpine web image it found
no locale data, setlocale() failed and åäö were invalid bytes. The cross
build now copies Debian's C.utf8 into the image and the image build runs
bokfweb --check-locale, so a TUI without UTF-8 fails the build.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'clients/bokfweb.c')
| -rw-r--r-- | clients/bokfweb.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/clients/bokfweb.c b/clients/bokfweb.c index d04e2d6..cc19826 100644 --- a/clients/bokfweb.c +++ b/clients/bokfweb.c @@ -15,6 +15,7 @@ directly: only Caddy and the wrapper in the same container talk to it. */ #include <arpa/inet.h> #include <errno.h> +#include <locale.h> #include <netinet/in.h> #include <signal.h> #include <stdio.h> @@ -23,6 +24,7 @@ #include <sys/socket.h> #include <sys/time.h> #include <unistd.h> +#include <wchar.h> #include "client.h" #include "log.h" @@ -446,8 +448,30 @@ static void serve(int cfd, struct gate *g) memset(buf, 0, n); /* the body may hold a password */ } -int main(void) +/* `bokfweb --check-locale`, run while the web image is built: bokftui in + the same image needs a UTF-8 locale for åäö, and a statically linked + glibc finds none unless its locale data is installed. Exits 1 without. */ +static int check_locale(void) { + const char *l = setlocale(LC_ALL, ""); + wchar_t w = 0; + mbstate_t st; + memset(&st, 0, sizeof st); + size_t n = mbrtowc(&w, "\xc3\xa5", 2, &st); /* å */ + if (!l || n != 2 || w != 0xE5) { + fprintf(stderr, "bokfweb: no UTF-8 locale (setlocale: %s); bokftui " + "would show no åäö\n", + l ? l : "failed"); + return 1; + } + printf("locale ok: %s\n", l); + return 0; +} + +int main(int argc, char **argv) +{ + if (argc > 1 && strcmp(argv[1], "--check-locale") == 0) + return check_locale(); signal(SIGPIPE, SIG_IGN); const char *lvl = getenv("BOKFWEB_LOG_LEVEL"); log_set_level(lvl ? log_level_from_name(lvl) : LOG_INFO); |
