Greetings,
As had been noticed back in January, wmii no longer works on NetBSD (cf.
thread with subject `Snapshot release of 3.5 - Does not work!'). The
breakage was caused by the introduction of the native codeset -> UTF-8
translation. Specifically, the version of iconv_open(3) that ships with
NetBSD does not support the use of the empty string to denote the default
codeset[1]; it simply fails with an "unsupported codeset" error. However,
the return value of iconv_open wasn't being checked, and so iconv(3) was
subsequently being used with an invalid conversion descriptor. The effect
of this was random memory curruption, leading to unpredictable errors.
I've attached a patch that uses nl_langinfo(3) to obtain the current codeset.
This patch has been tested under Debian GNU/Linux 4.0 and NetBSD 4.0 running
on AMD-64 hardware.
Cheers,
-- Alex Plotnick
[1] The SUSv3 says:
Settings of fromcode and tocode and their permitted combinations are
implementation-dependent.
(http://www.opengroup.org/onlinepubs/009695399/functions/iconv_open.html)
So, NetBSD is perfectly within its right to not support a codeset called "".
Also, the man page for iconv_open(3) on Max OS X 10.4 says that it supports
"" as a designator for the default codeset, but I haven't tested it. Thus,
this patch may or may not solve the problems some people have experienced
recently running wmii on Mac OS X.
diff -r 390ad96fda65 cmd/wmii/utf.c
--- a/cmd/wmii/utf.c Fri Nov 16 23:15:33 2007 +0900
+++ b/cmd/wmii/utf.c Thu Dec 20 09:32:09 2007 -0500
@@ -2,6 +2,7 @@
#include "dat.h"
#include <errno.h>
#include <iconv.h>
+#include <langinfo.h>
#include <string.h>
#include "fns.h"
@@ -11,8 +12,11 @@ toutf8n(char *str, size_t nstr) {
char *buf, *pos;
size_t nbuf, bsize;
- if(cd == nil)
- cd = iconv_open("UTF-8", "");
+ if(cd == nil) {
+ cd = iconv_open("UTF-8", nl_langinfo(CODESET));
+ if(cd == (iconv_t)-1)
+ fatal("Can't convert from native codeset to UTF-8");
+ }
iconv(cd, nil, nil, nil, nil);
bsize = nstr * 1.25 + 4;