summaryrefslogtreecommitdiffstats
path: root/mbbsd/io.c
diff options
context:
space:
mode:
authorvictor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-11-28 12:01:10 +0800
committervictor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-11-28 12:01:10 +0800
commit30edc2d47868e24f54a9505f7eb66c0a42c64b4d (patch)
treea6f58e9065121bf8b7f5451f8816dc3038ad46f2 /mbbsd/io.c
parent93e11784d623e3d0e178f13bfe560ebad6ffbaf9 (diff)
downloadpttbbs-30edc2d47868e24f54a9505f7eb66c0a42c64b4d.tar
pttbbs-30edc2d47868e24f54a9505f7eb66c0a42c64b4d.tar.gz
pttbbs-30edc2d47868e24f54a9505f7eb66c0a42c64b4d.tar.bz2
pttbbs-30edc2d47868e24f54a9505f7eb66c0a42c64b4d.tar.lz
pttbbs-30edc2d47868e24f54a9505f7eb66c0a42c64b4d.tar.xz
pttbbs-30edc2d47868e24f54a9505f7eb66c0a42c64b4d.tar.zst
pttbbs-30edc2d47868e24f54a9505f7eb66c0a42c64b4d.zip
merge gb branch back
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1379 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/io.c')
-rw-r--r--mbbsd/io.c49
1 files changed, 45 insertions, 4 deletions
diff --git a/mbbsd/io.c b/mbbsd/io.c
index ef5d76da..273017b8 100644
--- a/mbbsd/io.c
+++ b/mbbsd/io.c
@@ -15,14 +15,54 @@ static int obufsize = 0, ibufsize = 0;
static int icurrchar = 0;
/* ----------------------------------------------------- */
-/* output routines */
+/* convert routines */
/* ----------------------------------------------------- */
+typedef int (* read_write_type)(int, void *, size_t);
+static read_write_type write_type = (read_write_type)write;
+static read_write_type read_type = read;
+
+int converting_read(int fd, void *buf, size_t count)
+{
+ int len = read(fd, buf, count);
+ if (len >= 0)
+ gb2big(buf, len);
+ return len;
+}
+int converting_write(int fd, void *buf, size_t count)
+{
+ big2gb(buf, count);
+ return write(fd, buf, count);
+}
+
+void set_converting_type(int which)
+{
+ if (which == 0) {
+ read_type = read;
+ write_type = (read_write_type)write;
+ }
+ else if (which == 1) {
+ read_type = converting_read;
+ write_type = converting_write;
+ }
+}
+
+inline static int read_wrapper(int fd, void *buf, size_t count) {
+ return (*read_type)(fd, buf, count);
+}
+
+inline static int write_wrapper(int fd, void *buf, size_t count) {
+ return (*write_type)(fd, buf, count);
+}
+
+/* ----------------------------------------------------- */
+/* output routines */
+/* ----------------------------------------------------- */
void
oflush()
{
if (obufsize) {
- write(1, outbuf, obufsize);
+ write_wrapper(1, outbuf, obufsize);
obufsize = 0;
}
}
@@ -40,7 +80,7 @@ output(char *s, int len)
assert(len<OBUFSIZE);
if (obufsize + len > OBUFSIZE) {
- write(1, outbuf, obufsize);
+ write_wrapper(1, outbuf, obufsize);
obufsize = 0;
}
memcpy(outbuf + obufsize, s, len);
@@ -51,6 +91,7 @@ int
ochar(int c)
{
if (obufsize > OBUFSIZE - 1) {
+ /* suppose one byte data doesn't need to be converted. */
write(1, outbuf, obufsize);
obufsize = 0;
}
@@ -134,7 +175,7 @@ dogetch()
#ifdef SKIP_TELNET_CONTROL_SIGNAL
do{
#endif
- while ((len = read(0, inbuf, IBUFSIZE)) <= 0) {
+ while ((len = read_wrapper(0, inbuf, IBUFSIZE)) <= 0) {
if (len == 0 || errno != EINTR)
abort_bbs(0);
/* raise(SIGHUP); */