Subject: Re: behaviour of iconv in NetBSD and pkgsrc libiconv
To: None <uwe@ptc.spbu.ru>
From: Takehiko NOZAKI <th-nozaki@netwrk.co.jp>
List: tech-userlevel
Date: 04/04/2006 22:03:14
--Multipart_Tue_Apr__4_22:03:13_2006-1
Content-Type: text/plain; charset=US-ASCII
hi,
> I wonder if the practical path would be to introduce something like
> __iconv_gnu_bug() function that would turn on glibc compatible
> behaviour, so that glibc-addicted pkgsrc programs can be used w/out
> much vivisection performed on them.
for this purpose, we already have an extension, __iconv(3) interface.
[iconv.h]
size_t __iconv(iconv_t, const char **, size_t *, char **,
size_t *, __uint32_t, size_t *);
#define __ICONV_F_HIDE_INVALID 0x0001
currently this is only used by iconv(1):
1. to handle how many inconvertable chars in outbuf.
2. supress replacement chars(for -c option).
we can easily extends it to emulate glibc/GNU libiconv's behavior.
see attached patch.
of cource i'm not willing to guarantee this interface for the future...
--Multipart_Tue_Apr__4_22:03:13_2006-1
Content-Type: application/octet-stream
Content-Disposition: attachment; filename="patch-iconv"
Content-Transfer-Encoding: 7bit
Index: include/iconv.h
===================================================================
RCS file: /cvsroot/src/include/iconv.h,v
retrieving revision 1.6
diff -u -r1.6 iconv.h
--- include/iconv.h 3 Feb 2005 04:39:32 -0000 1.6
+++ include/iconv.h 4 Apr 2006 04:14:03 -0000
@@ -55,6 +55,7 @@
size_t __iconv(iconv_t, const char **, size_t *, char **,
size_t *, __uint32_t, size_t *);
#define __ICONV_F_HIDE_INVALID 0x0001
+#define __ICONV_F_STOP_NO_CORRESPONDING_CHAR 0x0002
__END_DECLS
#endif /* !_ICONV_H_ */
Index: lib/libc/citrus/citrus_iconv.h
===================================================================
RCS file: /cvsroot/src/lib/libc/citrus/citrus_iconv.h,v
retrieving revision 1.4
diff -u -r1.4 citrus_iconv.h
--- lib/libc/citrus/citrus_iconv.h 12 Mar 2005 04:20:30 -0000 1.4
+++ lib/libc/citrus/citrus_iconv.h 4 Apr 2006 04:14:03 -0000
@@ -44,6 +44,7 @@
#include "citrus_iconv_local.h"
#define _CITRUS_ICONV_F_HIDE_INVALID 0x0001
+#define _CITRUS_ICONV_F_STOP_NO_CORRESPONDING_CHAR 0x0002
/*
* _citrus_iconv_convert:
Index: lib/libc/citrus/modules/citrus_iconv_std.c
===================================================================
RCS file: /cvsroot/src/lib/libc/citrus/modules/citrus_iconv_std.c,v
retrieving revision 1.13
diff -u -r1.13 citrus_iconv_std.c
--- lib/libc/citrus/modules/citrus_iconv_std.c 19 Mar 2006 01:15:06 -0000 1.13
+++ lib/libc/citrus/modules/citrus_iconv_std.c 4 Apr 2006 04:14:04 -0000
@@ -540,6 +540,11 @@
ret = do_conv(is, sc, &csid, &idx);
if (ret) {
if (ret == E_NO_CORRESPONDING_CHAR) {
+ /* for glibc/GNU ibiconv compatibility */
+ if ((flags & _CITRUS_ICONV_F_STOP_NO_CORRESPONDING_CHAR) != 0)
+ ret = EILSEQ;
+ goto err;
+ }
inval++;
szrout = 0;
if ((flags&_CITRUS_ICONV_F_HIDE_INVALID)==0 &&
--Multipart_Tue_Apr__4_22:03:13_2006-1
Content-Type: text/plain; charset=US-ASCII
very truly yours.
--
Takehiko NOZAKI <tnozaki@netbsd.org>
--Multipart_Tue_Apr__4_22:03:13_2006-1--