diff options
-rw-r--r-- | pttbbs/mbbsd/angel.c | 8 | ||||
-rw-r--r-- | pttbbs/mbbsd/brc.c | 28 | ||||
-rw-r--r-- | pttbbs/mbbsd/ccw.c | 4 | ||||
-rw-r--r-- | pttbbs/mbbsd/emaildb.c | 15 | ||||
-rw-r--r-- | pttbbs/mbbsd/mbbsd.c | 4 | ||||
-rw-r--r-- | pttbbs/mbbsd/talk.c | 16 |
6 files changed, 36 insertions, 39 deletions
diff --git a/pttbbs/mbbsd/angel.c b/pttbbs/mbbsd/angel.c index d66d3867..846c4f9a 100644 --- a/pttbbs/mbbsd/angel.c +++ b/pttbbs/mbbsd/angel.c @@ -28,8 +28,8 @@ angel_beats_do_request(int op, int master_uid, int angel_uid) { assert(req.operation != ANGELBEATS_REQ_INVALID); - if (towrite(fd, &req, sizeof(req)) < 1 || - toread (fd, &req, sizeof(req)) < 1 || + if (towrite(fd, &req, sizeof(req)) < 0 || + toread (fd, &req, sizeof(req)) < 0 || req.cb != sizeof(req)) { ret = -2; } else { @@ -276,8 +276,8 @@ int a_angelreport() { if (HasUserPerm(PERM_ANGEL)) req.angel_uid = usernum; - if (towrite(fd, &req, sizeof(req)) < 1 || - toread(fd, &rpt, sizeof(rpt)) < 1 || + if (towrite(fd, &req, sizeof(req)) < 0 || + toread(fd, &rpt, sizeof(rpt)) < 0 || rpt.cb != sizeof(rpt)) { outs("抱歉,天使公會連線異常。\n" "請至 " BN_BUGREPORT " 看板通知站方管理人員。\n"); diff --git a/pttbbs/mbbsd/brc.c b/pttbbs/mbbsd/brc.c index 9dd96b3c..5daaf866 100644 --- a/pttbbs/mbbsd/brc.c +++ b/pttbbs/mbbsd/brc.c @@ -278,27 +278,25 @@ brc_update(){ int load_remote_brc() { int fd; - int8_t command = BRCSTORED_REQ_READ; int32_t len; - char uid[PATHLEN]; + char command[PATHLEN]; int err = 1; brc_size = 0; - snprintf(uid, sizeof(uid), "%s#%d\n", cuser.userid, cuser.firstlogin); + snprintf(command, sizeof(command), "%c%s#%d\n", + BRCSTORED_REQ_READ, cuser.userid, cuser.firstlogin); do { if ((fd = toconnectex(BRCSTORED_ADDR, 10)) < 0) break; - if (towrite(fd, &command, 1) != 1) + if (towrite(fd, command, strlen(command)) < 0) break; - if (towrite(fd, uid, strlen(uid)) < 0) - break; - if (toread(fd, &len, sizeof(len)) != sizeof(len)) + if (toread(fd, &len, sizeof(len)) < 0) break; if (len < 0) // not found break; brc_get_buf(len); - if (len && toread(fd, brc_buf, len) != len) + if (len && toread(fd, brc_buf, len) < 0) break; brc_size = len; err = 0; @@ -318,24 +316,22 @@ load_remote_brc() { int save_remote_brc() { int fd; - int8_t command = BRCSTORED_REQ_WRITE; int32_t len; - char uid[PATHLEN]; + char command[PATHLEN]; int err = 1; - snprintf(uid, sizeof(uid), "%s#%d\n", cuser.userid, cuser.firstlogin); + snprintf(command, sizeof(command), "%c%s#%d\n", + BRCSTORED_REQ_WRITE, cuser.userid, cuser.firstlogin); len = brc_size; do { if ((fd = toconnectex(BRCSTORED_ADDR, 10)) < 0) break; - if (towrite(fd, &command, 1) != 1) - break; - if (towrite(fd, uid, strlen(uid)) < 0) + if (towrite(fd, command, strlen(command)) < 0) break; - if (towrite(fd, &len, sizeof(len)) != sizeof(len)) + if (towrite(fd, &len, sizeof(len)) < 0) break; - if (len && towrite(fd, brc_buf ? brc_buf : "", len) != len) + if (len && towrite(fd, brc_buf ? brc_buf : "", len) < 0) break; err = 0; } while (0); diff --git a/pttbbs/mbbsd/ccw.c b/pttbbs/mbbsd/ccw.c index 727a7123..26e9b90d 100644 --- a/pttbbs/mbbsd/ccw.c +++ b/pttbbs/mbbsd/ccw.c @@ -559,9 +559,9 @@ ccw_talk_recv(CCW_CTX *ctx, char *buf, size_t szbuf) char len = 0; buf[0] = 0; // XXX blocking call here... (change to recv?) - if (toread(ctx->fd, &len, sizeof(len)) != sizeof(len)) + if (toread(ctx->fd, &len, sizeof(len)) < 0) return -1; - if (toread(ctx->fd, buf, len)!= len) + if (toread(ctx->fd, buf, len) < 0) return -1; assert(len >= 0 && len < (int)szbuf); buf[(size_t)len] = 0; diff --git a/pttbbs/mbbsd/emaildb.c b/pttbbs/mbbsd/emaildb.c index 931aee66..25d6b458 100644 --- a/pttbbs/mbbsd/emaildb.c +++ b/pttbbs/mbbsd/emaildb.c @@ -23,13 +23,13 @@ int emaildb_check_email(const char * email, int email_len) return -1; } - if (towrite(fd, &req, sizeof(req)) != sizeof(req)) { + if (towrite(fd, &req, sizeof(req)) < 0) { // perror("towrite"); close(fd); return -1; } - if (toread(fd, &count, sizeof(count)) != sizeof(count)) { + if (toread(fd, &count, sizeof(count)) < 0) { // perror("toread"); close(fd); return -1; @@ -38,7 +38,8 @@ int emaildb_check_email(const char * email, int email_len) return count; } -int emaildb_update_email(const char * userid, int userid_len, const char * email, int email_len) +int emaildb_update_email(const char * userid, int userid_len, + const char * email, int email_len) { int result = -1; int fd = -1; @@ -56,13 +57,13 @@ int emaildb_update_email(const char * userid, int userid_len, const char * email return -1; } - if (towrite(fd, &req, sizeof(req)) != sizeof(req)) { + if (towrite(fd, &req, sizeof(req)) < 0) { // perror("towrite"); close(fd); return -1; } - if (toread(fd, &result, sizeof(result)) != sizeof(result)) { + if (toread(fd, &result, sizeof(result)) < 0) { // perror("toread"); close(fd); return -1; @@ -94,13 +95,13 @@ int regcheck_ambiguous_userid_exist(const char *userid) return -1; } - if (towrite(fd, &req, sizeof(req)) != sizeof(req)) { + if (towrite(fd, &req, sizeof(req)) < 0) { // perror("towrite"); close(fd); return -1; } - if (toread(fd, &result, sizeof(result)) != sizeof(result)) { + if (toread(fd, &result, sizeof(result)) < 0) { // perror("toread"); close(fd); return -1; diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 5047d0ac..ff4e9ea4 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1952,8 +1952,8 @@ tunnel_login(char *argv0, struct ProgramOption *option) { return 0; } - if (toread(tunnel, &dat, sizeof(dat)) < (int)sizeof(dat) || - towrite(tunnel, &dat.ack, sizeof(dat.ack)) < (int)sizeof(dat.ack)) + if (toread(tunnel, &dat, sizeof(dat)) < 0 || + towrite(tunnel, &dat.ack, sizeof(dat.ack)) < 0) return 0; assert(dat.cb == sizeof(dat)); diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 4b6e2c53..651a9480 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -235,14 +235,14 @@ int sync_outta_server(int sfd, int do_login) ocfs_t fs[MAX_FRIEND*2]; cmd = -2; - if(towrite(sfd, &cmd, sizeof(cmd)) <= 0 || - towrite(sfd, &offset, sizeof(offset)) <= 0 || - towrite(sfd, &currutmp->uid, sizeof(currutmp->uid)) <= 0 || - towrite(sfd, currutmp->myfriend, sizeof(currutmp->myfriend)) <= 0 || - towrite(sfd, currutmp->reject, sizeof(currutmp->reject)) <= 0) + if(towrite(sfd, &cmd, sizeof(cmd)) < 0 || + towrite(sfd, &offset, sizeof(offset)) < 0 || + towrite(sfd, &currutmp->uid, sizeof(currutmp->uid)) < 0 || + towrite(sfd, currutmp->myfriend, sizeof(currutmp->myfriend)) < 0 || + towrite(sfd, currutmp->reject, sizeof(currutmp->reject)) < 0) return -1; - if(toread(sfd, &res, sizeof(res)) <= 0) + if(toread(sfd, &res, sizeof(res)) < 0) return -1; if(res<0) @@ -267,14 +267,14 @@ int sync_outta_server(int sfd, int do_login) exit(0); } - if(toread(sfd, &nfs, sizeof(nfs)) <= 0) + if(toread(sfd, &nfs, sizeof(nfs)) < 0) return -1; if(nfs<0 || nfs>MAX_FRIEND*2) { fprintf(stderr, "invalid nfs=%d\n",nfs); return -1; } - if(toread(sfd, fs, sizeof(fs[0])*nfs) <= 0) + if(toread(sfd, fs, sizeof(fs[0])*nfs) < 0) return -1; close(sfd); |