1219020Sgabor/*- 2219020Sgabor * Copyright (C) 2010 Gabor Kovesdan <gabor@FreeBSD.org> 3219020Sgabor * All rights reserved. 4219020Sgabor * 5219020Sgabor * Redistribution and use in source and binary forms, with or without 6219020Sgabor * modification, are permitted provided that the following conditions 7219020Sgabor * are met: 8219020Sgabor * 1. Redistributions of source code must retain the above copyright 9219020Sgabor * notice, this list of conditions and the following disclaimer. 10219020Sgabor * 2. Redistributions in binary form must reproduce the above copyright 11219020Sgabor * notice, this list of conditions and the following disclaimer in the 12219020Sgabor * documentation and/or other materials provided with the distribution. 13219020Sgabor * 14219020Sgabor * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15219020Sgabor * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16219020Sgabor * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17219020Sgabor * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18219020Sgabor * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19219020Sgabor * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20219020Sgabor * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21219020Sgabor * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22219020Sgabor * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23219020Sgabor * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24219020Sgabor * SUCH DAMAGE. 25219020Sgabor */ 26219020Sgabor 27219020Sgabor#include <sys/cdefs.h> 28219020Sgabor__FBSDID("$FreeBSD$"); 29219020Sgabor 30219020Sgabor#include <sys/types.h> 31219020Sgabor 32219020Sgabor#include <err.h> 33219020Sgabor#include <iconv.h> 34219020Sgabor#include <stdlib.h> 35219020Sgabor#include <string.h> 36219020Sgabor 37219020Sgaborint 38219020Sgabormain(void) 39219020Sgabor{ 40219020Sgabor iconv_t cd; 41219020Sgabor size_t inbytes, outbytes; 42219020Sgabor char *str1 = "FOOBAR"; 43219020Sgabor const char *str2 = "FOOBAR"; 44219020Sgabor char ** in1; 45219020Sgabor const char ** in2 = &str2; 46219020Sgabor char *out1, *out2; 47219020Sgabor 48219020Sgabor inbytes = outbytes = strlen("FOOBAR"); 49219020Sgabor 50219020Sgabor if ((cd = iconv_open("UTF-8", "ASCII")) == (iconv_t)-1) 51219020Sgabor err(1, NULL); 52219020Sgabor 53219020Sgabor if ((out2 = malloc(inbytes)) == NULL) 54219020Sgabor err(1, NULL); 55219020Sgabor 56219020Sgabor if (iconv(cd, in2, &inbytes, &out2, &outbytes) == -1) 57219020Sgabor err(1, NULL); 58219020Sgabor 59219020Sgabor in1 = &str1; 60219020Sgabor inbytes = outbytes = strlen("FOOBAR"); 61219020Sgabor 62219020Sgabor if ((out1 = malloc(inbytes)) == NULL) 63219020Sgabor err(1, NULL); 64219020Sgabor 65219020Sgabor if (iconv(cd, in1, &inbytes, &out1, &outbytes) == -1) 66219020Sgabor err(1, NULL); 67219020Sgabor 68219020Sgabor return (EXIT_SUCCESS); 69219020Sgabor 70219020Sgabor} 71