[hackers] [wmii] Use nl_langinfo(3) instead of the unportable "" to specify the default character set for iconv_open(3). Thanks to Alex Plotnick for the patch.

From: sqweek <sqweek_AT_gmail.com>
Date: Thu Dec 27 15:08:23 2007

changeset: 2229:3749896cf02c
tag: tip
user: sqweek <sqweek_AT_gmail.com>
date: Thu Dec 27 23:29:49 2007 +0900
summary: Use nl_langinfo(3) instead of the unportable "" to specify the default character set for iconv_open(3). Thanks to Alex Plotnick for the patch.

diff -r 390ad96fda65 -r 3749896cf02c cmd/wmii/utf.c
--- a/cmd/wmii/utf.c Fri Nov 16 23:15:33 2007 +0900
+++ b/cmd/wmii/utf.c Thu Dec 27 23:29:49 2007 +0900
@@ -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;
Received on Thu Dec 27 2007 - 15:08:23 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:58:58 UTC