X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=charset.c;h=9bf63f8edc30ae1586ccf9f0ba9e61209ce560d0;hp=63bc81c30b6a8e671d6058be567a414b9d8d8e23;hb=b3cb6ed8d36c550a2e589910ce51bbc8352ff57c;hpb=59926571aaec3e38cec09d0d9fa34f4a4b887309 diff --git a/charset.c b/charset.c index 63bc81c..9bf63f8 100644 --- a/charset.c +++ b/charset.c @@ -22,6 +22,8 @@ #include #include +#include + #include "mutt.h" #include "charset.h" #include "ascii.h" @@ -253,27 +255,6 @@ int mutt_chscmp (const char *s, const char *chs) } -#ifndef HAVE_ICONV - -iconv_t iconv_open (const char *tocode, const char *fromcode) -{ - return (iconv_t) (-1); -} - -size_t iconv (iconv_t cd, const char **inbuf, size_t * inbytesleft, - char **outbuf, size_t * outbytesleft) -{ - return 0; -} - -int iconv_close (iconv_t cd) -{ - return 0; -} - -#endif /* !HAVE_ICONV */ - - /* * Like iconv_open, but canonicalises the charsets */ @@ -326,7 +307,7 @@ size_t mutt_iconv (iconv_t cd, const char **inbuf, size_t * inbytesleft, size_t obl = *outbytesleft; for (;;) { - ret1 = iconv (cd, &ib, &ibl, &ob, &obl); + ret1 = my_iconv(cd, &ib, &ibl, &ob, &obl); if (ret1 != (size_t) - 1) ret += ret1; if (ibl && obl && errno == EILSEQ) { @@ -340,7 +321,7 @@ size_t mutt_iconv (iconv_t cd, const char **inbuf, size_t * inbytesleft, char *ob1 = ob; size_t obl1 = obl; - iconv (cd, &ib1, &ibl1, &ob1, &obl1); + my_iconv(cd, &ib1, &ibl1, &ob1, &obl1); if (!ibl1) { ++ib, --ibl; ob = ob1, obl = obl1; @@ -354,7 +335,7 @@ size_t mutt_iconv (iconv_t cd, const char **inbuf, size_t * inbytesleft, /* Replace the output */ if (!outrepl) outrepl = "?"; - iconv (cd, 0, 0, &ob, &obl); + my_iconv(cd, 0, 0, &ob, &obl); if (obl) { int n = str_len (outrepl); @@ -366,7 +347,7 @@ size_t mutt_iconv (iconv_t cd, const char **inbuf, size_t * inbytesleft, ++ib, --ibl; ob += n, obl -= n; ++ret; - iconv (cd, 0, 0, 0, 0); /* for good measure */ + my_iconv(cd, 0, 0, 0, 0); /* for good measure */ continue; } } @@ -410,14 +391,14 @@ int mutt_convert_string (char **ps, const char *from, const char *to, len = str_len (s); ib = s, ibl = len + 1; obl = MB_LEN_MAX * ibl; - ob = buf = mem_malloc (obl + 1); + ob = buf = xmalloc(obl + 1); mutt_iconv (cd, &ib, &ibl, &ob, &obl, inrepls, outrepl); iconv_close (cd); *ob = '\0'; - mem_free (ps); + p_delete(ps); *ps = buf; str_adjust (ps); @@ -461,14 +442,14 @@ FGETCONV *fgetconv_open (FILE * file, const char *from, const char *to, cd = mutt_iconv_open (to, from, flags); if (cd != (iconv_t) - 1) { - fc = mem_malloc (sizeof (struct fgetconv_s)); + fc = p_new(struct fgetconv_s, 1); fc->p = fc->ob = fc->bufo; fc->ib = fc->bufi; fc->ibl = 0; fc->inrepls = mutt_is_utf8 (to) ? repls : repls + 1; } else - fc = mem_malloc (sizeof (struct fgetconv_not)); + fc = p_new(struct fgetconv_not, 1); fc->file = file; fc->cd = cd; return (FGETCONV *) fc; @@ -512,7 +493,7 @@ int fgetconv (FGETCONV * _fc) if (fc->ibl) { size_t obl = sizeof (fc->bufo); - iconv (fc->cd, (const char **) &fc->ib, &fc->ibl, &fc->ob, &obl); + my_iconv(fc->cd, (const char **) &fc->ib, &fc->ibl, &fc->ob, &obl); if (fc->p < fc->ob) return (unsigned char) *(fc->p)++; } @@ -553,7 +534,7 @@ void fgetconv_close (FGETCONV ** _fc) if (fc->cd != (iconv_t) - 1) iconv_close (fc->cd); - mem_free (_fc); + p_delete(_fc); } const char *mutt_get_first_charset (const char *charset) @@ -583,11 +564,11 @@ static size_t convert_string (const char *f, size_t flen, if (cd == (iconv_t) (-1)) return (size_t) (-1); obl = 4 * flen + 1; - ob = buf = mem_malloc (obl); - n = iconv (cd, &f, &flen, &ob, &obl); - if (n == (size_t) (-1) || iconv (cd, 0, 0, &ob, &obl) == (size_t) (-1)) { + ob = buf = xmalloc(obl); + n = my_iconv(cd, &f, &flen, &ob, &obl); + if (n == (size_t) (-1) || my_iconv(cd, 0, 0, &ob, &obl) == (size_t) (-1)) { e = errno; - mem_free (&buf); + p_delete(&buf); iconv_close (cd); errno = e; return (size_t) (-1); @@ -622,12 +603,11 @@ int mutt_convert_nonmime_string (char **ps) n = c1 ? c1 - c : str_len (c); if (!n) continue; - fromcode = mem_malloc (n + 1); - strfcpy (fromcode, c, n + 1); + fromcode = p_dupstr(c, n); m = convert_string (u, ulen, fromcode, Charset, &s, &slen); - mem_free (&fromcode); + p_delete(&fromcode); if (m != (size_t) (-1)) { - mem_free (ps); + p_delete(ps); *ps = s; return 0; }