Blame src/functional/iconv_open.c
|
Szabolcs Nagy |
fd74aa |
#include <string.h>
|
|
Szabolcs Nagy |
fd74aa |
#include <errno.h>
|
|
Szabolcs Nagy |
fd74aa |
#include <iconv.h>
|
|
Szabolcs Nagy |
fd74aa |
#include "test.h"
|
|
Szabolcs Nagy |
fd74aa |
|
|
Szabolcs Nagy |
fd74aa |
int main(void)
|
|
Szabolcs Nagy |
fd74aa |
{
|
|
Szabolcs Nagy |
fd74aa |
iconv_t cd;
|
|
Szabolcs Nagy |
fd74aa |
char buf[100];
|
|
Szabolcs Nagy |
fd74aa |
char *inbuf = "test";
|
|
Szabolcs Nagy |
fd74aa |
char *outbuf = buf;
|
|
Szabolcs Nagy |
fd74aa |
size_t inlen = strlen(inbuf);
|
|
Szabolcs Nagy |
fd74aa |
size_t outlen;
|
|
Szabolcs Nagy |
fd74aa |
size_t r;
|
|
Szabolcs Nagy |
4125f7 |
char *bad = "bad-codeset";
|
|
Szabolcs Nagy |
fd74aa |
|
|
Szabolcs Nagy |
4125f7 |
cd = iconv_open(bad, bad);
|
|
Szabolcs Nagy |
fd74aa |
if (cd != (iconv_t)-1)
|
|
Szabolcs Nagy |
4125f7 |
t_error("iconv_open(\"%s\",\"%s\") didn't fail\n", bad, bad);
|
|
Szabolcs Nagy |
fd74aa |
if (errno != EINVAL)
|
|
Szabolcs Nagy |
4125f7 |
t_error("iconv_open(\"%s\",\"%s\") did not fail with EINVAL, got %s\n", bad, bad, strerror(errno));
|
|
Szabolcs Nagy |
fd74aa |
|
|
Szabolcs Nagy |
fd74aa |
errno = 0;
|
|
Szabolcs Nagy |
fd74aa |
cd = iconv_open("UTF-8", "UTF-8");
|
|
Szabolcs Nagy |
fd74aa |
if (cd == (iconv_t)-1)
|
|
Szabolcs Nagy |
fd74aa |
t_error("iconv_open(\"\",\"\") failed: %s\n", strerror(errno));
|
|
Szabolcs Nagy |
fd74aa |
|
|
Szabolcs Nagy |
fd74aa |
errno = 0;
|
|
Szabolcs Nagy |
fd74aa |
outlen = 0;
|
|
Szabolcs Nagy |
fd74aa |
r = iconv(cd, &inbuf, &inlen, &outbuf, &outlen);
|
|
Szabolcs Nagy |
fd74aa |
if (r != -1)
|
|
Szabolcs Nagy |
fd74aa |
t_error("iconv() did not fail with 0 output length\n");
|
|
Szabolcs Nagy |
fd74aa |
if (errno != E2BIG)
|
|
Szabolcs Nagy |
fd74aa |
t_error("iconv() did not fail with E2BIG, got %s\n", strerror(errno));
|
|
Szabolcs Nagy |
fd74aa |
|
|
Szabolcs Nagy |
fd74aa |
errno = 0;
|
|
Szabolcs Nagy |
fd74aa |
outlen = sizeof buf;
|
|
Szabolcs Nagy |
fd74aa |
r = iconv(cd, &inbuf, &inlen, &outbuf, &outlen);
|
|
Szabolcs Nagy |
fd74aa |
if (r)
|
|
Szabolcs Nagy |
fd74aa |
t_error("iconv() did not return 0 when converting utf8 to utf8, got %d\n", r);
|
|
Szabolcs Nagy |
fd74aa |
if (errno)
|
|
Szabolcs Nagy |
fd74aa |
t_error("iconv() failed: %s\n", strerror(errno));
|
|
Szabolcs Nagy |
fd74aa |
|
|
Szabolcs Nagy |
fd74aa |
r = iconv_close(cd);
|
|
Szabolcs Nagy |
fd74aa |
if (r == -1)
|
|
Szabolcs Nagy |
fd74aa |
t_error("iconv_close failed: %s\n", strerror(errno));
|
|
Szabolcs Nagy |
fd74aa |
|
|
Szabolcs Nagy |
fd74aa |
return t_status;
|
|
Szabolcs Nagy |
fd74aa |
}
|