[patch] kernel iconv improvements

From: Dmitry Marakasov <amdmi3_at_amdmi3.ru>
Date: Sat, 25 Apr 2009 06:18:54 +0400
Hi!

Here's a little improvement for kernel iconv. It makes kiconv ignore
case of character set names (and also store them in uppercase for
consistency), so

mount_cd9660 -C koi8-r /dev/acd0 /mnt
mount_cd9660 -C KOI8-r /dev/acd0 /mnt
mount_cd9660 -C KOI8-R /dev/acd0 /mnt
mount_cd9660 -C Koi8-r /dev/acd0 /mnt

will no longer lead to loading four similar charset conversion
tables instead of one.

See also ports/sysutils/kiconvtool - can it be integrated into the
base system? The purpose of all this is more convenient and effective
handling of filesystem charset conversion (especially for usermounts).

--- iconv.c.patch begins here ---
Index: sys/libkern/iconv.c
===================================================================
--- sys/libkern/iconv.c	(revision 191469)
+++ sys/libkern/iconv.c	(working copy)
_at__at_ -33,6 +33,7 _at__at_
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
+#include <sys/ctype.h>
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/kernel.h>
_at__at_ -171,8 +172,8 _at__at_
 	struct iconv_cspair *csp;
 
 	TAILQ_FOREACH(csp, &iconv_cslist, cp_link) {
-		if (strcmp(csp->cp_to, to) == 0 &&
-		    strcmp(csp->cp_from, from) == 0) {
+		if (strcasecmp(csp->cp_to, to) == 0 &&
+		    strcasecmp(csp->cp_from, from) == 0) {
 			if (cspp)
 				*cspp = csp;
 			return 0;
_at__at_ -207,12 +208,16 _at__at_
 	if (!ucsto) {
 		strcpy(cp, to);
 		csp->cp_to = cp;
-		cp += strlen(cp) + 1;
+		for (; *cp; cp++)
+			*cp = toupper(*cp);
+		cp++;
 	} else
 		csp->cp_to = iconv_unicode_string;
 	if (!ucsfrom) {
 		strcpy(cp, from);
 		csp->cp_from = cp;
+		for (; *cp; cp++)
+			*cp = toupper(*cp);
 	} else
 		csp->cp_from = iconv_unicode_string;
 	csp->cp_data = data;
--- iconv.c.patch ends here ---

-- 
Dmitry Marakasov   .   55B5 0596 FF1E 8D84 5F56  9510 D35A 80DD F9D2 F77D
amdmi3_at_amdmi3.ru  ..:  jabber: amdmi3_at_jabber.ru    http://www.amdmi3.ru
Received on Sat Apr 25 2009 - 00:19:37 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:46 UTC