1
0
mirror of https://gitlab.xiph.org/xiph/ezstream.git synced 2024-11-03 04:17:18 -05:00

Less code is always better.

git-svn-id: https://svn.xiph.org/trunk/ezstream@13616 0101bb08-14d6-0310-b084-bc0e0c8e3800
This commit is contained in:
moritz 2007-08-24 17:23:09 +00:00
parent 29fa4f1736
commit 256394e811

View File

@ -58,6 +58,10 @@
extern EZCONFIG *pezConfig;
extern char *__progname;
#ifdef HAVE_ICONV
char * iconvert(const char *, const char *, const char *);
#endif /* HAVE_ICONV */
int
strrcmp(const char *s, const char *sub)
{
@ -226,15 +230,6 @@ char *
char2utf8(const char *in_str)
{
#ifdef HAVE_ICONV
iconv_t cd;
ICONV_CONST char *input, *ip;
size_t input_len;
char *output;
size_t output_size;
char buf[BUFSIZ], *bp;
size_t bufavail;
size_t out_pos;
# ifndef WIN32
char *codeset;
@ -254,56 +249,9 @@ char2utf8(const char *in_str)
if (in_str == NULL || strlen(in_str) == 0)
return (NULL);
if ((cd = iconv_open("UTF-8", codeset)) == (iconv_t)-1 &&
(cd = iconv_open("UTF-8", "")) == (iconv_t)-1) {
printf("iconv_open: %s\n", strerror(errno));
return (NULL);
}
ip = input = (ICONV_CONST char *)in_str;
input_len = strlen(input);
output_size = 1;
output = xcalloc(output_size, sizeof(char));
out_pos = 0;
output[out_pos] = '\0';
while (input_len > 0) {
char *op;
size_t count;
buf[0] = '\0';
bp = buf;
bufavail = sizeof(buf) - 1;
if (iconv(cd, &ip, &input_len, &bp, &bufavail) == (size_t)-1 &&
errno != E2BIG) {
*bp++ = '?';
ip++;
input_len--;
bufavail--;
}
*bp = '\0';
count = sizeof(buf) - bufavail - 1;
output_size += count;
op = output = xrealloc(output, output_size, sizeof(char));
op += out_pos;
memcpy(op, buf, count);
out_pos += count;
op += count;
*op = '\0';
}
if (iconv_close(cd) == -1) {
printf("iconv_close: %s\n", strerror(errno));
xfree(output);
return (NULL);
}
return (output);
return (iconvert(in_str, codeset, "UTF-8"));
#else
char *ret = xstrdup(in_str);
return (ret);
return (xstrdup(in_str));
#endif /* HAVE_ICONV */
}
@ -311,15 +259,6 @@ char *
utf82char(const char *in_str)
{
#ifdef HAVE_ICONV
iconv_t cd;
ICONV_CONST char *input, *ip;
size_t input_len;
char *output;
size_t output_size;
char buf[BUFSIZ], *bp;
size_t bufavail;
size_t out_pos;
# ifndef WIN32
char *codeset;
@ -339,9 +278,28 @@ utf82char(const char *in_str)
if (in_str == NULL || strlen(in_str) == 0)
return (NULL);
if ((cd = iconv_open(codeset, "UTF-8")) == (iconv_t)-1 &&
(cd = iconv_open("", "UTF-8")) == (iconv_t)-1) {
printf("iconv_open: %s\n", strerror(errno));
return (iconvert(in_str, "UTF-8", codeset));
#else
return (xstrdup(in_str));
#endif /* HAVE_ICONV */
}
#ifdef HAVE_ICONV
char *
iconvert(const char *in_str, const char *from, const char *to)
{
iconv_t cd;
ICONV_CONST char *input, *ip;
size_t input_len;
char *output;
size_t output_size;
char buf[BUFSIZ], *bp;
size_t bufavail;
size_t out_pos;
if ((cd = iconv_open(to, from)) == (iconv_t)-1 &&
(cd = iconv_open("", from)) == (iconv_t)-1) {
printf("%s: iconv_open(): %s\n", strerror(errno), __progname);
return (NULL);
}
@ -380,14 +338,11 @@ utf82char(const char *in_str)
}
if (iconv_close(cd) == -1) {
printf("iconv_close: %s\n", strerror(errno));
printf("%s: iconv_close(): %s\n", strerror(errno), __progname);
xfree(output);
return (NULL);
}
return (output);
#else
char *ret = xstrdup(in_str);
return (ret);
#endif /* HAVE_ICONV */
}
#endif /* HAVE_ICONV */