Browse code

Beef up iconv_open error messages to show the source encoding and strerror.

Steven Morgan authored on 2015/06/18 00:59:35
Showing 2 changed files
... ...
@@ -123,7 +123,9 @@ ole2_convert_utf(summary_ctx_t *sctx, char *begin, size_t sz, const char *encodi
123 123
 
124 124
     cd = iconv_open("UTF-8", encoding);
125 125
     if (cd == (iconv_t)(-1)) {
126
-        cli_errmsg("ole2_convert_utf: could not initialize iconv\n");
126
+        char errbuf[128];
127
+        cli_strerror(errno, errbuf, sizeof(errbuf)); 
128
+        cli_errmsg("ole2_convert_utf: could not initialize iconv for encoding %s: %s\n", encoding, errbuf);
127 129
         sctx->flags |= OLE2_CODEPAGE_ERROR_UNINITED;
128 130
     }
129 131
     else {
... ...
@@ -107,7 +107,9 @@ char *pdf_convert_utf(char *begin, size_t sz)
107 107
 
108 108
         cd = iconv_open("UTF-8", encodings[i]);
109 109
         if (cd == (iconv_t)(-1)) {
110
-            cli_errmsg("Could not initialize iconv\n");
110
+            char errbuf[128];
111
+            cli_strerror(errno, errbuf, sizeof(errbuf)); 
112
+            cli_errmsg("pdf_convert_utf: could not initialize iconv for encoding %s: %s\n", encodings[i], errbuf);
111 113
             continue;
112 114
         }
113 115