| 32 |
#include <poll.h> |
#include <poll.h> |
| 33 |
#endif |
#endif |
| 34 |
|
|
| 35 |
|
enum _io_constant_t |
| 36 |
|
{ |
| 37 |
|
OUTPUT_BUF_SIZE = 8192, |
| 38 |
|
}; |
| 39 |
|
|
| 40 |
const char BBS_default_charset[CHARSET_MAX_LEN + 1] = "UTF-8"; |
const char BBS_default_charset[CHARSET_MAX_LEN + 1] = "UTF-8"; |
| 41 |
char stdio_charset[CHARSET_MAX_LEN + 1] = "UTF-8"; |
char stdio_charset[CHARSET_MAX_LEN + 1] = "UTF-8"; |
| 42 |
|
|
| 51 |
|
|
| 52 |
// static input / output buffer |
// static input / output buffer |
| 53 |
static char stdin_buf[LINE_BUFFER_LEN]; |
static char stdin_buf[LINE_BUFFER_LEN]; |
| 54 |
static char stdout_buf[BUFSIZ]; |
static char stdout_buf[OUTPUT_BUF_SIZE]; |
| 55 |
static int stdin_buf_len = 0; |
static int stdin_buf_len = 0; |
| 56 |
static int stdout_buf_len = 0; |
static int stdout_buf_len = 0; |
| 57 |
static int stdin_buf_offset = 0; |
static int stdin_buf_offset = 0; |
| 58 |
static int stdout_buf_offset = 0; |
static int stdout_buf_offset = 0; |
| 59 |
|
|
| 60 |
static char stdin_conv[LINE_BUFFER_LEN * 2]; |
static char stdin_conv[LINE_BUFFER_LEN * 2]; |
| 61 |
static char stdout_conv[BUFSIZ * 2]; |
static char stdout_conv[OUTPUT_BUF_SIZE * 2]; |
| 62 |
static int stdin_conv_len = 0; |
static int stdin_conv_len = 0; |
| 63 |
static int stdout_conv_len = 0; |
static int stdout_conv_len = 0; |
| 64 |
static int stdin_conv_offset = 0; |
static int stdin_conv_offset = 0; |
| 183 |
|
|
| 184 |
int prints(const char *format, ...) |
int prints(const char *format, ...) |
| 185 |
{ |
{ |
| 186 |
char buf[BUFSIZ]; |
char buf[OUTPUT_BUF_SIZE]; |
| 187 |
va_list args; |
va_list args; |
| 188 |
int ret; |
int ret; |
| 189 |
|
|
| 193 |
|
|
| 194 |
if (ret > 0) |
if (ret > 0) |
| 195 |
{ |
{ |
| 196 |
if (stdout_buf_len + ret > BUFSIZ) |
if (stdout_buf_len + ret > OUTPUT_BUF_SIZE) |
| 197 |
{ |
{ |
| 198 |
iflush(); |
iflush(); |
| 199 |
} |
} |
| 200 |
|
|
| 201 |
if (stdout_buf_len + ret <= BUFSIZ) |
if (stdout_buf_len + ret <= OUTPUT_BUF_SIZE) |
| 202 |
{ |
{ |
| 203 |
memcpy(stdout_buf + stdout_buf_len, buf, (size_t)ret); |
memcpy(stdout_buf + stdout_buf_len, buf, (size_t)ret); |
| 204 |
stdout_buf_len += ret; |
stdout_buf_len += ret; |
| 206 |
else |
else |
| 207 |
{ |
{ |
| 208 |
errno = EAGAIN; |
errno = EAGAIN; |
| 209 |
ret = (BUFSIZ - stdout_buf_len - ret); |
ret = (OUTPUT_BUF_SIZE - stdout_buf_len - ret); |
| 210 |
log_error("Output buffer is full, additional %d is required\n", ret); |
log_error("Output buffer is full, additional %d is required\n", ret); |
| 211 |
} |
} |
| 212 |
} |
} |
| 218 |
{ |
{ |
| 219 |
int ret; |
int ret; |
| 220 |
|
|
| 221 |
if (stdout_buf_len + 1 > BUFSIZ) |
if (stdout_buf_len + 1 > OUTPUT_BUF_SIZE) |
| 222 |
{ |
{ |
| 223 |
iflush(); |
iflush(); |
| 224 |
} |
} |
| 225 |
|
|
| 226 |
if (stdout_buf_len + 1 <= BUFSIZ) |
if (stdout_buf_len + 1 <= OUTPUT_BUF_SIZE) |
| 227 |
{ |
{ |
| 228 |
stdout_buf[stdout_buf_len] = c; |
stdout_buf[stdout_buf_len] = c; |
| 229 |
stdout_buf_len++; |
stdout_buf_len++; |