diff options
-rw-r--r-- | mbbsd/cache.c | 10 | ||||
-rw-r--r-- | mbbsd/calendar.c | 14 | ||||
-rw-r--r-- | mbbsd/chat.c | 5 | ||||
-rw-r--r-- | mbbsd/chc.c | 5 | ||||
-rw-r--r-- | mbbsd/chicken.c | 3 | ||||
-rw-r--r-- | mbbsd/file.c | 3 | ||||
-rw-r--r-- | mbbsd/friend.c | 7 | ||||
-rw-r--r-- | mbbsd/gamble.c | 6 | ||||
-rw-r--r-- | mbbsd/mail.c | 19 | ||||
-rw-r--r-- | mbbsd/mbbsd.c | 3 | ||||
-rw-r--r-- | mbbsd/name.c | 5 | ||||
-rw-r--r-- | mbbsd/topsong.c | 3 | ||||
-rw-r--r-- | mbbsd/user.c | 19 | ||||
-rw-r--r-- | mbbsd/vote.c | 4 | ||||
-rw-r--r-- | mbbsd/voteboard.c | 4 |
15 files changed, 70 insertions, 40 deletions
diff --git a/mbbsd/cache.c b/mbbsd/cache.c index 6c961592..f38263e8 100644 --- a/mbbsd/cache.c +++ b/mbbsd/cache.c @@ -805,6 +805,7 @@ void buildBMcache(int bid) /* bid starts from 1 */ { char s[IDLEN * 3 + 3], *ptr; int i, uid; + char *strtok_pos; assert(0<=bid-1 && bid-1<MAX_BOARD); strlcpy(s, getbcache(bid)->BM, sizeof(s)); @@ -812,9 +813,9 @@ void buildBMcache(int bid) /* bid starts from 1 */ if( !isalpha((int)s[i]) && !isdigit((int)s[i]) ) s[i] = ' '; - for( ptr = strtok(s, " "), i = 0 ; + for( ptr = strtok_r(s, " ", &strtok_pos), i = 0 ; i < MAX_BMs && ptr != NULL ; - ptr = strtok(NULL, " "), ++i ) + ptr = strtok_r(NULL, " ", &strtok_pos), ++i ) if( (uid = searchuser(ptr, NULL)) != 0 ) SHM->BMcache[bid-1][i] = uid; for( ; i < MAX_BMs ; ++i ) @@ -940,6 +941,7 @@ reload_fcache(void) bzero(SHM->home_ip, sizeof(SHM->home_ip)); if ((fp = fopen("etc/domain_name_query.cidr", "r"))) { char buf[256], *ip, *mask; + char *strtok_pos; SHM->home_num = 0; while (fgets(buf, sizeof(buf), fp)) { @@ -953,7 +955,7 @@ reload_fcache(void) continue; } - ip = strtok(buf, " \t"); + ip = strtok_r(buf, " \t", &strtok_pos); if ((mask = strchr(ip, '/')) != NULL) { int shift = 32 - atoi(mask + 1); SHM->home_ip[SHM->home_num] = ipstr2int(ip); @@ -963,7 +965,7 @@ reload_fcache(void) SHM->home_ip[SHM->home_num] = ipstr2int(ip); SHM->home_mask[SHM->home_num] = 0xFFFFFFFF; } - ip = strtok(NULL, " \t"); + ip = strtok_r(NULL, " \t", &strtok_pos); if (ip == NULL) { strncpy(SHM->home_desc[SHM->home_num], "雲深不知處", sizeof(SHM->home_desc[SHM->home_num])); diff --git a/mbbsd/calendar.c b/mbbsd/calendar.c index 76c899f7..52a0c111 100644 --- a/mbbsd/calendar.c +++ b/mbbsd/calendar.c @@ -44,11 +44,12 @@ int ParseDate(const char *date, int *year, int *month, int *day) { char *y, *m, *d; char buf[128]; + char *strtok_pos; strlcpy(buf, date, sizeof(buf)); - y = strtok(buf, "/"); - m = strtok(NULL, "/"); - d = strtok(NULL, ""); + y = strtok_r(buf, "/", &strtok_pos); + m = strtok_r(NULL, "/", &strtok_pos); + d = strtok_r(NULL, "", &strtok_pos); if (!y || !m || !d) return 1; @@ -146,13 +147,14 @@ ReadEvent(int today) while (fgets(buf, sizeof(buf), fp)) { char *date, *color, *content; event_t *t; + char *strtok_pos; if (buf[0] == '#') continue; - date = strtok(buf, " \t\n"); - color = strtok(NULL, " \t\n"); - content = strtok(NULL, "\n"); + date = strtok_r(buf, " \t\n", &strtok_pos); + color = strtok_r(NULL, " \t\n", &strtok_pos); + content = strtok_r(NULL, "\n", &strtok_pos); if (!date || !color || !content) continue; diff --git a/mbbsd/chat.c b/mbbsd/chat.c index e165c71a..cb252e15 100644 --- a/mbbsd/chat.c +++ b/mbbsd/chat.c @@ -217,10 +217,11 @@ chat_query(char *arg) char *uid; int tuid; userec_t xuser; + char *strtok_pos; printchatline(""); - strtok(arg, str_space); - if ((uid = strtok(NULL, str_space)) && (tuid = getuser(uid, &xuser))) { + strtok_r(arg, str_space, &strtok_pos); + if ((uid = strtok_r(NULL, str_space, &strtok_pos)) && (tuid = getuser(uid, &xuser))) { char buf[128], *ptr; FILE *fp; diff --git a/mbbsd/chc.c b/mbbsd/chc.c index a4d3eeeb..82087703 100644 --- a/mbbsd/chc.c +++ b/mbbsd/chc.c @@ -949,11 +949,12 @@ chc_replay(FILE* fp) /* /\[(Red|Black) "([a-zA-Z0-9]+)"\]/; $2 */ userec_t rec; char *userid; + char *strtok_pos; ChessUser *user = (buf[1] == 'R' ? &info->user1 : &info->user2); - strtok(buf, "\""); - userid = strtok(NULL, "\""); + strtok_r(buf, "\"", &strtok_pos); + userid = strtok_r(NULL, "\"", &strtok_pos); if (userid != NULL && getuser(userid, &rec)) chc_init_user_userec(&rec, user); } diff --git a/mbbsd/chicken.c b/mbbsd/chicken.c index e7527e7b..d57a3bfe 100644 --- a/mbbsd/chicken.c +++ b/mbbsd/chicken.c @@ -987,7 +987,8 @@ chickenpk(int fd) break; } if (deadtype(ochicken)) { - strtok(data, "\n"); + char *p = strchr(data, '\n'); + if(p) *p = '\0'; strlcpy(buf, data, sizeof(buf)); snprintf(data, sizeof(data), "d%s , %s 被 %s 打死了\n", buf + 1, ochicken->name, mychicken->name); diff --git a/mbbsd/file.c b/mbbsd/file.c index 343822b7..34af866a 100644 --- a/mbbsd/file.c +++ b/mbbsd/file.c @@ -57,7 +57,8 @@ int file_exist_record(const char *file, const char *string) return 0; while (fgets(buf, STRLEN, fp)) { - if ((ptr = strtok(buf, str_space)) && !strcasecmp(ptr, string)) { + char *strtok_pos; + if ((ptr = strtok_r(buf, str_space, &strtok_pos)) && !strcasecmp(ptr, string)) { fclose(fp); return 1; } diff --git a/mbbsd/friend.c b/mbbsd/friend.c index c73932af..50f00887 100644 --- a/mbbsd/friend.c +++ b/mbbsd/friend.c @@ -291,10 +291,11 @@ inline void friend_load_real(int tosort, int maxf, *destn = 0; } else{ + char *strtok_pos; tarray = (int *)malloc(sizeof(int) * maxf); --maxf; /* 因為最後一個要填 0, 所以先扣一個回來 */ while( fgets(genbuf, STRLEN, fp) && nFriends < maxf ) - if( (p = strtok(genbuf, str_space)) && + if( (p = strtok_r(genbuf, str_space, &strtok_pos)) && (uid = searchuser(p, NULL)) ) tarray[nFriends++] = uid; fclose(fp); @@ -379,9 +380,11 @@ friend_edit(int type) move(3, 0); column = 0; while (fgets(genbuf, STRLEN, fp)) { + char *space; if (genbuf[0] <= ' ') continue; - strtok(genbuf, str_space); + space = strpbrk(genbuf, str_space); + if (space) *space = '\0'; AddNameList(genbuf); prints("%-13s", genbuf); count++; diff --git a/mbbsd/gamble.c b/mbbsd/gamble.c index 69c93d6d..79cb5be8 100644 --- a/mbbsd/gamble.c +++ b/mbbsd/gamble.c @@ -49,8 +49,10 @@ show_ticket_data(char betname[MAX_ITEM][MAX_ITEM_LEN],const char *direct, int *p } fgets(genbuf, MAX_ITEM_LEN, fp); *price = atoi(genbuf); - for (count = 0; fgets(betname[count], MAX_ITEM_LEN, fp) && count < MAX_ITEM; count++) - strtok(betname[count], "\r\n"); + for (count = 0; fgets(betname[count], MAX_ITEM_LEN, fp) && count < MAX_ITEM; count++) { + char *newline = strpbrk(betname[count], "\r\n"); + if (newline) *newline = '\0'; + } fclose(fp); prints(ANSI_COLOR(32) "站規:" ANSI_RESET " 1.可購買以下不同類型的彩票。每張要花 " ANSI_COLOR(32) "%d" ANSI_RESET " 元。\n" diff --git a/mbbsd/mail.c b/mbbsd/mail.c index 9f731530..2cc3e886 100644 --- a/mbbsd/mail.c +++ b/mbbsd/mail.c @@ -535,14 +535,17 @@ multi_send(char *title) break; } else { if (listing) { - strtok(ptr = genbuf + 3, " \n\r"); - do { + char *strtok_pos; + ptr = genbuf + 3; + for (ptr = strtok_r(ptr, " \n\r", &strtok_pos); + ptr; + ptr = strtok_r(NULL, " \n\r", &strtok_pos)) { if (searchuser(ptr, ptr) && !InNameList(ptr) && strcmp(cuser.userid, ptr)) { AddNameList(ptr); reciper++; } - } while ((ptr = (char *)strtok(NULL, " \n\r"))); + } } else if (!strncmp(genbuf + 3, "[通告]", 6)) listing = 1; } @@ -1121,7 +1124,6 @@ int mail_reply(int ent, fileheader_t * fhdr, const char *direct) { char uid[STRLEN]; - char *t; FILE *fp; char genbuf[512]; int oent = ent; @@ -1137,14 +1139,17 @@ mail_reply(int ent, fileheader_t * fhdr, const char *direct) /* find the author */ strlcpy(quote_user, fhdr->owner, sizeof(quote_user)); if (strchr(quote_user, '.')) { + char *t; + char *strtok_pos; genbuf[0] = '\0'; if ((fp = fopen(quote_file, "r"))) { fgets(genbuf, sizeof(genbuf), fp); fclose(fp); } - t = strtok(genbuf, str_space); - if (t && (!strcmp(t, str_author1) || !strcmp(t, str_author2))) - strlcpy(uid, strtok(NULL, str_space), sizeof(uid)); // XXX if strtok return NULL + t = strtok_r(genbuf, str_space, &strtok_pos); + if (t && (strcmp(t, str_author1)==0 || strcmp(t, str_author2)==0) + && (t=strtok_r(NULL, str_space, &strtok_pos)) != NULL) + strlcpy(uid, t, sizeof(uid)); else { vmsg("錯誤: 找不到作者。"); quote_user[0]='\0'; diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index 4b48afa4..c2f7d48b 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -1779,8 +1779,9 @@ static int check_banip(char *host) { unsigned int thisip = 0; char *ptr, *myhost = strdup(host); + char *strtok_pos; - for( ptr = strtok(myhost, ".") ; ptr != NULL ; ptr = strtok(NULL, ".") ) + for( ptr = strtok_r(myhost, ".", &strtok_pos) ; ptr != NULL ; ptr = strtok_r(NULL, ".", &strtok_pos) ) thisip = thisip * 256 + atoi(ptr); free(myhost); diff --git a/mbbsd/name.c b/mbbsd/name.c index 4457abae..c136e9a0 100644 --- a/mbbsd/name.c +++ b/mbbsd/name.c @@ -298,7 +298,10 @@ ToggleNameList(int *reciper, const char *listfile, const char *msg) if ((fp = fopen(listfile, "r"))) { while (fgets(genbuf, STRLEN, fp)) { - strtok(genbuf, str_space); + char *space = strpbrk(genbuf, str_space); + if (space) *space = '\0'; + if (!genbuf[0]) + continue; if (!InNameList(genbuf)) { AddNameList(genbuf); (*reciper)++; diff --git a/mbbsd/topsong.c b/mbbsd/topsong.c index 72e3d3d5..01163f24 100644 --- a/mbbsd/topsong.c +++ b/mbbsd/topsong.c @@ -53,7 +53,8 @@ sortsong(void) totalcount = 0; /* XXX: 除了前 MAX_SONGS 首, 剩下不會排序 */ while (fgets(buf, 200, fp)) { - strtok(buf, "\n\r"); + char *newline = strpbrk(buf, "\n\r"); + if (newline) *newline = '\0'; strip_blank(cbuf, buf); if (!cbuf[0] || !isprint2((int)cbuf[0])) continue; diff --git a/mbbsd/user.c b/mbbsd/user.c index b9b15e3f..4abc44ca 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -847,15 +847,16 @@ uinfo_query(userec_t *u, int adminmode, int unum) if (getdata_str(i++, 0, "五子棋戰績 勝/敗/和:", buf, 16, DOECHO, genbuf)) while (1) { - p = strtok(buf, "/\r\n"); + char *strtok_pos; + p = strtok_r(buf, "/\r\n", &strtok_pos); if (!p) break; x.five_win = atoi(p); - p = strtok(NULL, "/\r\n"); + p = strtok_r(NULL, "/\r\n", &strtok_pos); if (!p) break; x.five_lose = atoi(p); - p = strtok(NULL, "/\r\n"); + p = strtok_r(NULL, "/\r\n", &strtok_pos); if (!p) break; x.five_tie = atoi(p); @@ -866,15 +867,16 @@ uinfo_query(userec_t *u, int adminmode, int unum) if (getdata_str(i++, 0, "象棋戰績 勝/敗/和:", buf, 16, DOECHO, genbuf)) while (1) { - p = strtok(buf, "/\r\n"); + char *strtok_pos; + p = strtok_r(buf, "/\r\n", &strtok_pos); if (!p) break; x.chc_win = atoi(p); - p = strtok(NULL, "/\r\n"); + p = strtok_r(NULL, "/\r\n", &strtok_pos); if (!p) break; x.chc_lose = atoi(p); - p = strtok(NULL, "/\r\n"); + p = strtok_r(NULL, "/\r\n", &strtok_pos); if (!p) break; x.chc_tie = atoi(p); @@ -1037,12 +1039,13 @@ uinfo_query(userec_t *u, int adminmode, int unum) if (mail_changed) { char justify_tmp[REGLEN + 1]; char *phone, *career; + char *strtok_pos; strlcpy(justify_tmp, u->justify, sizeof(justify_tmp)); x.userlevel &= ~(PERM_LOGINOK | PERM_POST); - phone = strtok(justify_tmp, ":"); - career = strtok(NULL, ":"); + phone = strtok_r(justify_tmp, ":", &strtok_pos); + career = strtok_r(NULL, ":", &strtok_pos); if (phone == NULL) phone = ""; if (career == NULL) career = ""; diff --git a/mbbsd/vote.c b/mbbsd/vote.c index 5aa6fda6..917865e8 100644 --- a/mbbsd/vote.c +++ b/mbbsd/vote.c @@ -966,9 +966,11 @@ user_vote_one(vote_buffer_t *vbuf, const char *bname, int ind) count = 0; for (i = 0; i < ITEM_PER_PAGE && fgets(inbuf, sizeof(inbuf), cfp); i++) { + char *newline = strpbrk(inbuf, "\r\n"); + if (newline) *newline = '\0'; move((count % 15) + 5, (count / 15) * 40); prints("%c%s", chosen[curr_page * ITEM_PER_PAGE + i] ? '*' : ' ', - strtok(inbuf, "\n\0")); + inbuf); choices[count % ITEM_PER_PAGE] = inbuf[0]; count++; } diff --git a/mbbsd/voteboard.c b/mbbsd/voteboard.c index c228abfb..0b644a60 100644 --- a/mbbsd/voteboard.c +++ b/mbbsd/voteboard.c @@ -44,6 +44,7 @@ do_voteboardreply(const fileheader_t * fhdr) assert(fi); while (fgets(genbuf, sizeof(genbuf), fi)) { + char *newline; if (yes>=0) { @@ -66,7 +67,8 @@ do_voteboardreply(const fileheader_t * fhdr) } if(yes>=0) continue; - strtok(genbuf+4," \n"); + newline = strpbrk(genbuf+4, " \n"); + if(newline) *newline='\0'; if (!strncmp(genbuf + 4, cuser.userid, IDLEN)) { move(5, 10); outs("您已經連署過本篇了"); |