pkgsrc-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

porting yasr: non-standard WCHAR_T in iconv_open()



Hi, porting yasr I noticed that it is using WCHAR_T as an encoding
name in iconv_open(), which is non-standard and not supported by
netbsd.

I'm thinking on using something like this:
=========================
#include <stdio.h>
#include <iconv.h>
#include <stdlib.h>

int
main (void)
{
  char* wchar_enc;
  iconv_t ic;
  int i = 1;
  char* utf16str[] = {"UTF-16BE", "UTF-16LE"};
  char* utf32str[] = {"UTF-32BE", "UTF-32LE"};

  /* if LE *((uint8_t *)&i) would be 1, if not 0 */
  /* I'm assuming that sizeof(wchar_t) would be 2 or 4 */
  wchar_enc = (sizeof(wchar_t) == 2)? utf16str[*((uint8_t *)&i)] : utf32str[*((uint8_t *)&i)];

  printf("wchar_enc: %s\n", wchar_enc);

  ic = iconv_open(wchar_enc, "UTF-8");
  if (ic == (iconv_t)-1)
    puts("Oh my...");
  exit(0);
}
=========================

Any advice, is there already a better (and portable) way? I haven't
found any similar patch in pkgsrc.

Regards,
adr.


Home | Main Index | Thread Index | Old Index