b348 iconv EILSEQ error - The FreeBSD Forums
The FreeBSD Forums  

Go Back   The FreeBSD Forums > Ports & Packages > Porting New Software

Porting New Software Having trouble or general questions about porting software to FreeBSD? Ask here.

Reply
 
Thread Tools Display Modes
  #1  
Old January 4th, 2013, 03:44
FestusHagen's Avatar
FestusHagen FestusHagen is offline
Junior Member
 
Join Date: Dec 2008
Posts: 58
Thanks: 8
Thanked 1 Time in 1 Post
Default iconv EILSEQ error

Hi all,

Working on a C project that uses iconv, it works properly on Fedora and Windows yet fails on FreeBSD-8.2.

Hoping someone can point me in the direction of a resolution.

The errno is 86, And is defined in /usr/local/include/iconv.h as:
Code:
EILSEQ        86        /* Illegal byte sequence */
The byte sequence appears correct, See below.

With the following info one would think it would work on FreeBSD and Win32, but not Fedora.

Systems info:
Code:
FreeBSD 8.2
#iconv --version
iconv (GNU libiconv 1.14)
Copyright (C) 2000-2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Bruno Haible.
Code:
WinXPsp3/Win7
C:\>iconv --version
iconv (GNU libiconv 1.14)
Copyright (C) 2000-2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Bruno Haible.
GNU libiconv v1.14
Code:
Fedora v?? (copy and paste from another users email)
#iconv --version
iconv (GNU libc) 2.15
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Ulrich Drepper.
Code frag:
Code:
	char mb[8];
	char *outbuf = mb;
	size_t inlen = sizeof(wchar_t)/sizeof(char);
	size_t outlen = 8
	wchar_t &wc = THIS->operator[](i);
	const char *inbuf = (const char *)&wc;
	codec = iconv_open("UTF-8", "WCHAR_T");
	iconv(codec, NULL, NULL, NULL, NULL);
	if(iconv(codec, &inbuf, &inlen, &outbuf, &outlen) == -1)
FreeBSD gdb shows
Code:
(gdb) x inbuf
0x28ee2d10: 0x00007684
I do believe that to be the correct value ...

Thanks y'all.

-Enjoy
fh : )_~
Reply With Quote
  #2  
Old January 4th, 2013, 09:08
FestusHagen's Avatar
FestusHagen FestusHagen is offline
Junior Member
 
Join Date: Dec 2008
Posts: 58
Thanks: 8
Thanked 1 Time in 1 Post
Default

Simple test program.

Code:
#include <stdio.h>
#include <iconv.h>

// FreeBSD
// g++ -g -o iconv-test -I/usr/local/include -L/usr/local/lib iconv-test.cpp -liconv

// On Win32 I use MinGW32, I use Strawberry Perl so I use it's MinGW ...
// g++ -g -o iconv-test -IC:/Strawberry/c/include -LC:/Strawberry/c/lib iconv-test.cpp -liconv

#if defined(__FreeBSD__)
size_t iconv_wrap(iconv_t cd, char **inbuf, size_t *inbytesleft,
                  char **outbuf, size_t *outbytesleft)
{
  char *in = *inbuf;
  const char *in_c = (const char*)(in);
  return iconv(cd, &in_c, inbytesleft, outbuf, outbytesleft);
}
#else
size_t iconv_wrap(iconv_t cd, char **inbuf, size_t *inbytesleft,
                  char **outbuf, size_t *outbytesleft)
{
  return iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft);
}
#endif /* __FreeBSD__ */

int main(int argc, char* argv[])
{
  iconv_t codec;
  char mb[8];
  char *inbuf, *outbuf;
  size_t inlen, outlen;

  outlen = 8;
  outbuf = mb;
  inlen = sizeof(wchar_t)/sizeof(char);

  const wchar_t &wc = 30340;
  inbuf = (char *)&wc;

  codec = iconv_open("UTF-8", "WCHAR_T");
  if(!codec)
    printf("iconv_open failed.\n");

  iconv(codec, NULL, NULL, NULL, NULL);

  if(iconv_wrap(codec, &inbuf, &inlen, &outbuf, &outlen) == -1) {
    printf("iconv failed.\n");
    iconv_close(codec);
    return -1;
  }
  iconv_close(codec);

  mb[8-outlen] = '\0';
  for(int i = 0; i<8-outlen; i++)
    printf(":%x:", mb[i]);
  return 0;
}
-Enjoy
fh : )_~
Reply With Quote
  #3  
Old January 4th, 2013, 12:59
FestusHagen's Avatar
FestusHagen FestusHagen is offline
Junior Member
 
Join Date: Dec 2008
Posts: 58
Thanks: 8
Thanked 1 Time in 1 Post
Default [solved] iconv EILSEQ error

WCHAR_T is system dependent!
Use the encoding that created the String that the wchar_t &wc came from in the first place ... Duh!

However, I didn't know what that was, this is software written by ???
I do not understand all this utf / Unicode / Code sets / Wide Char / etc ... Just trying to fix something that's broke!
Yup, I know I need to do some serious educating on this topic, I know a bunch more today then I did 5 days ago!

If I would of just kept at it another two hours I wouldn't be wasting y'alls time.

Input is still welcome.

-Enjoy
fh : )_~
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
FreeBSD 9.0 & PHP (5 - 5.5) iconv error andisian Installation and Maintenance of FreeBSD Ports or Packages 14 December 28th, 2012 18:32
Replace unzip with unzip-iconv wasabi Installation and Maintenance of FreeBSD Ports or Packages 1 March 5th, 2012 16:27
[Solved] Iconv with ruby19 migbsd Installation and Maintenance of FreeBSD Ports or Packages 4 June 23rd, 2010 02:07
remove iconv lib dependency from Libxml2 ayeshagutpa Installation and Maintenance of FreeBSD Ports or Packages 0 April 22nd, 2010 09:53
freebsd 7.0- Error Mounting /dev/acd0 on /dist: Input/output error (5) Lego Installing & Upgrading 52 November 30th, 2008 16:31


All times are GMT +1. The time now is 13:35.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
The mark FreeBSD is a registered trademark of The FreeBSD Foundation and is used by The FreeBSD Project with the permission of The FreeBSD Foundation.
Web protection and acceleration provided by CloudFlare
0