| 64 |
static int stdin_conv_offset = 0; |
static int stdin_conv_offset = 0; |
| 65 |
static int stdout_conv_offset = 0; |
static int stdout_conv_offset = 0; |
| 66 |
|
|
| 67 |
static iconv_t stdin_cd = NULL; |
static iconv_t stdin_cd = (iconv_t)(-1); |
| 68 |
static iconv_t stdout_cd = NULL; |
static iconv_t stdout_cd = (iconv_t)(-1); |
| 69 |
|
|
| 70 |
int io_init(void) |
int io_init(void) |
| 71 |
{ |
{ |
| 1120 |
if (in_bytes == 0) |
if (in_bytes == 0) |
| 1121 |
{ |
{ |
| 1122 |
in_bytes = (size_t)(*p_buf_len - *p_buf_offset); |
in_bytes = (size_t)(*p_buf_len - *p_buf_offset); |
| 1123 |
|
#ifdef _DEBUG |
| 1124 |
|
log_error("Reset in_bytes from 0 to %d\n", in_bytes); |
| 1125 |
|
#endif |
| 1126 |
} |
} |
| 1127 |
|
|
| 1128 |
*out_buf = *in_buf; |
#ifdef _DEBUG |
| 1129 |
in_buf++; |
log_error("iconv(in_bytes=%d, out_bytes=%d) error: EILSEQ, in_buf[0]=%d\n", |
| 1130 |
out_buf++; |
in_bytes, out_bytes, in_buf[0]); |
| 1131 |
in_bytes--; |
#endif |
| 1132 |
out_bytes--; |
skip_current = 1; |
|
|
|
|
(*p_buf_offset)++; |
|
|
(*p_conv_len)++; |
|
|
|
|
|
continue; |
|
| 1133 |
} |
} |
| 1134 |
else // something strange |
else // something strange |
| 1135 |
{ |
{ |
| 1136 |
#ifdef _DEBUG |
#ifdef _DEBUG |
| 1137 |
log_error("*p_buf_offset += %d, *p_conv_len = %d, in_bytes=%d, out_bytes=%d, in_buf[0]=%d\n", |
log_error("iconv(in_bytes=%d, out_bytes=%d) error: %d, in_buf[0]=%d\n", |
| 1138 |
(int)(in_buf - p_buf), (int)(conv_size - out_bytes), in_bytes, out_bytes, in_buf[0]); |
in_bytes, out_bytes, errno, in_buf[0]); |
| 1139 |
#endif |
#endif |
| 1140 |
|
*p_buf_offset = (int)(in_buf - p_buf); |
|
*p_buf_offset += (int)(in_buf - p_buf); |
|
| 1141 |
*p_conv_len = (int)(conv_size - out_bytes); |
*p_conv_len = (int)(conv_size - out_bytes); |
| 1142 |
skip_current = 1; |
skip_current = 1; |
|
|
|
|
continue; |
|
| 1143 |
} |
} |
| 1144 |
} |
} |
| 1145 |
else |
else |
| 1146 |
{ |
{ |
| 1147 |
*p_buf_len = 0; |
*p_buf_offset = (int)(in_buf - p_buf); |
|
*p_buf_offset = 0; |
|
| 1148 |
*p_conv_len = (int)(conv_size - out_bytes); |
*p_conv_len = (int)(conv_size - out_bytes); |
|
|
|
|
break; |
|
| 1149 |
} |
} |
| 1150 |
} |
} |
| 1151 |
|
|
| 1189 |
{ |
{ |
| 1190 |
log_error("iconv_open(%s->%s) error: %d\n", BBS_default_charset, tocode, errno); |
log_error("iconv_open(%s->%s) error: %d\n", BBS_default_charset, tocode, errno); |
| 1191 |
iconv_close(stdin_cd); |
iconv_close(stdin_cd); |
| 1192 |
|
stdin_cd = (iconv_t)(-1); |
| 1193 |
return -2; |
return -2; |
| 1194 |
} |
} |
| 1195 |
|
|
| 1198 |
|
|
| 1199 |
int io_conv_cleanup(void) |
int io_conv_cleanup(void) |
| 1200 |
{ |
{ |
| 1201 |
if (stdin_cd != NULL) |
if (stdin_cd != (iconv_t)(-1)) |
| 1202 |
{ |
{ |
| 1203 |
iconv_close(stdin_cd); |
iconv_close(stdin_cd); |
| 1204 |
stdin_cd = NULL; |
stdin_cd = (iconv_t)(-1); |
| 1205 |
} |
} |
| 1206 |
if (stdout_cd != NULL) |
if (stdout_cd != (iconv_t)(-1)) |
| 1207 |
{ |
{ |
| 1208 |
iconv_close(stdout_cd); |
iconv_close(stdout_cd); |
| 1209 |
stdout_cd = NULL; |
stdout_cd = (iconv_t)(-1); |
| 1210 |
} |
} |
| 1211 |
|
|
| 1212 |
return 0; |
return 0; |