| 85 | } |
| 86 | |
| 87 | void setup_iconv(void) |
| 88 | { |
| 89 | const char *defset = default_charset(); |
| 90 | # ifdef ICONV_OPTION |
| 91 | const char *charset; |
| 92 | char *cp; |
| 93 | # endif |
| 94 | |
| 95 | if (!am_server && !allow_8bit_chars) { |
| 96 | /* It's OK if this fails... */ |
| 97 | ic_chck = iconv_open(defset, defset); |
| 98 | |
| 99 | if (DEBUG_GTE(ICONV, 2)) { |
| 100 | if (ic_chck == (iconv_t)-1) { |
| 101 | rprintf(FINFO, |
| 102 | "msg checking via isprint()" |
| 103 | " (iconv_open(\"%s\", \"%s\") errno: %d)\n", |
| 104 | defset, defset, errno); |
| 105 | } else { |
| 106 | rprintf(FINFO, |
| 107 | "msg checking charset: %s\n", |
| 108 | defset); |
| 109 | } |
| 110 | } |
| 111 | } else |
| 112 | ic_chck = (iconv_t)-1; |
| 113 | |
| 114 | # ifdef ICONV_OPTION |
| 115 | if (!iconv_opt) |
| 116 | return; |
| 117 | |
| 118 | if ((cp = strchr(iconv_opt, ',')) != NULL) { |
| 119 | if (am_server) /* A local transfer needs this. */ |
| 120 | iconv_opt = cp + 1; |
| 121 | else |
| 122 | *cp = '\0'; |
| 123 | } |
| 124 | |
| 125 | if (!*iconv_opt || (*iconv_opt == '.' && iconv_opt[1] == '\0')) |
| 126 | charset = defset; |
| 127 | else |
| 128 | charset = iconv_opt; |
| 129 | |
| 130 | if ((ic_send = iconv_open(UTF8_CHARSET, charset)) == (iconv_t)-1) { |
| 131 | rprintf(FERROR, "iconv_open(\"%s\", \"%s\") failed\n", |
| 132 | UTF8_CHARSET, charset); |
| 133 | exit_cleanup(RERR_UNSUPPORTED); |
| 134 | } |
| 135 | |
| 136 | if ((ic_recv = iconv_open(charset, UTF8_CHARSET)) == (iconv_t)-1) { |
| 137 | rprintf(FERROR, "iconv_open(\"%s\", \"%s\") failed\n", |
| 138 | charset, UTF8_CHARSET); |
| 139 | exit_cleanup(RERR_UNSUPPORTED); |
| 140 | } |
| 141 | |
| 142 | if (DEBUG_GTE(ICONV, 1)) { |
| 143 | rprintf(FINFO, "[%s] charset: %s\n", |
| 144 | who_am_i(), *charset ? charset : "[LOCALE]"); |
no test coverage detected