diff options
author | victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2006-05-17 19:45:14 +0800 |
---|---|---|
committer | victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2006-05-17 19:45:14 +0800 |
commit | 6ace55395308b16ef451d8fc99cc52bdc64fa467 (patch) | |
tree | d6078915af819260ed0550f9dfffe9eb7df04c00 | |
parent | f1a8a8052cf6d266b3a5c50fea8af0a9b4f7df59 (diff) | |
download | pttbbs-6ace55395308b16ef451d8fc99cc52bdc64fa467.tar pttbbs-6ace55395308b16ef451d8fc99cc52bdc64fa467.tar.gz pttbbs-6ace55395308b16ef451d8fc99cc52bdc64fa467.tar.bz2 pttbbs-6ace55395308b16ef451d8fc99cc52bdc64fa467.tar.lz pttbbs-6ace55395308b16ef451d8fc99cc52bdc64fa467.tar.xz pttbbs-6ace55395308b16ef451d8fc99cc52bdc64fa467.tar.zst pttbbs-6ace55395308b16ef451d8fc99cc52bdc64fa467.zip |
fix bug: delete a user called USER from user list also removes others called USERetc
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3356 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | include/proto.h | 1 | ||||
-rw-r--r-- | mbbsd/file.c | 33 | ||||
-rw-r--r-- | mbbsd/friend.c | 32 |
3 files changed, 30 insertions, 36 deletions
diff --git a/include/proto.h b/include/proto.h index 254a77af..92d23207 100644 --- a/include/proto.h +++ b/include/proto.h @@ -271,7 +271,6 @@ void subscribe_newfav(void); /* file */ int file_count_line(const char *file); int file_append_line(const char *file, const char *string); -int file_delete_line(const char *file, const char *string, int case_sensitive); int file_exist_record(const char *file, const char *string); /* friend */ diff --git a/mbbsd/file.c b/mbbsd/file.c index a5937673..343822b7 100644 --- a/mbbsd/file.c +++ b/mbbsd/file.c @@ -45,39 +45,6 @@ int file_append_line(const char *file, const char *string) return 0; } -#ifndef _BBS_UTIL_C_ -/** - * 從檔案 file 中刪除 prefix 為 string 的每一行。(小心 race) - * @param file - * @param string - * @param case_sensitive 字串比對是否 case sensitive - */ -int file_delete_line(const char *file, const char *string, int case_sensitive) -{ - FILE *fp, *nfp = NULL; - char fnew[80]; - char genbuf[STRLEN + 1]; - - sprintf(fnew, "%s.%3.3X", file, (unsigned int)(random() & 0xFFF)); - if ((fp = fopen(file, "r")) && (nfp = fopen(fnew, "w"))) { - int length = strlen(string); - - while (fgets(genbuf, sizeof(genbuf), fp)) - if ((genbuf[0] > ' ')) { - if (((case_sensitive && strncmp(genbuf, string, length)) || - (!case_sensitive && strncasecmp(genbuf, string, length)))) - fputs(genbuf, nfp); - } - Rename(fnew, file); - } - if(fp) - fclose(fp); - if(nfp) - fclose(nfp); - return 0; -} -#endif - /** * 傳回檔案 file 中是否有 string 這個字串。 */ diff --git a/mbbsd/friend.c b/mbbsd/friend.c index 8f62713f..7d7d3720 100644 --- a/mbbsd/friend.c +++ b/mbbsd/friend.c @@ -179,12 +179,40 @@ friend_append(int type, int count) } } +static int +delete_friend_from_file(const char *file, const char *string, int case_sensitive) +{ + FILE *fp, *nfp = NULL; + char fnew[80]; + char genbuf[STRLEN + 1]; + + sprintf(fnew, "%s.%3.3X", file, (unsigned int)(random() & 0xFFF)); + if ((fp = fopen(file, "r")) && (nfp = fopen(fnew, "w"))) { + int length = strlen(string); + + while (fgets(genbuf, sizeof(genbuf), fp)) + if ((genbuf[0] > ' ')) { + char buf[32]; + sscanf(genbuf, " %s", &buf); + if (((case_sensitive && strcmp(buf, string)) || + (!case_sensitive && strcasecmp(buf, string)))) + fputs(genbuf, nfp); + } + Rename(fnew, file); + } + if(fp) + fclose(fp); + if(nfp) + fclose(nfp); + return 0; +} + void friend_delete(const char *uident, int type) { char fn[80]; setfriendfile(fn, type); - file_delete_line(fn, uident, 0); + delete_friend_from_file(fn, uident, 0); } static void @@ -195,7 +223,7 @@ delete_user_friend(const char *uident, const char *thefriend, int type) if (type == FRIEND_ALOHA) { #endif sethomefile(fn, uident, "aloha"); - file_delete_line(fn, thefriend, 0); + delete_friend_from_file(fn, thefriend, 0); #if 0 } else { |