summaryrefslogtreecommitdiffstats
path: root/mbbsd/friend.c
diff options
context:
space:
mode:
authorkcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-09-06 22:49:08 +0800
committerkcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-09-06 22:49:08 +0800
commit471a65e552f18963ef2fa976663bdb61f9c8236c (patch)
treeeafd56689d9da646d682113c6c0f4c6ca302fee6 /mbbsd/friend.c
parente22d3269f7d450ba90e42073943fc16bcc81a568 (diff)
downloadpttbbs-471a65e552f18963ef2fa976663bdb61f9c8236c.tar
pttbbs-471a65e552f18963ef2fa976663bdb61f9c8236c.tar.gz
pttbbs-471a65e552f18963ef2fa976663bdb61f9c8236c.tar.bz2
pttbbs-471a65e552f18963ef2fa976663bdb61f9c8236c.tar.lz
pttbbs-471a65e552f18963ef2fa976663bdb61f9c8236c.tar.xz
pttbbs-471a65e552f18963ef2fa976663bdb61f9c8236c.tar.zst
pttbbs-471a65e552f18963ef2fa976663bdb61f9c8236c.zip
code cleanup
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1162 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/friend.c')
-rw-r--r--mbbsd/friend.c25
1 files changed, 10 insertions, 15 deletions
diff --git a/mbbsd/friend.c b/mbbsd/friend.c
index 39ef2148..16e36c63 100644
--- a/mbbsd/friend.c
+++ b/mbbsd/friend.c
@@ -56,22 +56,15 @@ setfriendfile(char *fpath, int type)
setbfile(fpath, currboard, friend_file[type]);
}
-static unsigned int
+static int
friend_count(char *fname)
{
FILE *fp;
int count = 0;
char buf[200];
-#if 0
- if ((fp = fopen(fname, "r")))
- while (fgets(buf, 200, fp))
- count++;
-#endif
-
- /* rocker.011018: §Ñ°OÃöÀɤF... */
if ((fp = fopen(fname, "r"))) {
- while (fgets(buf, 200, fp))
+ while (fgets(buf, sizeof(buf), fp))
count++;
fclose(fp);
}
@@ -218,7 +211,7 @@ friend_delete(char *uident, int type)
setfriendfile(fn, type);
sprintf(fnnew, "%s-", fn);
- if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) { // XXX fclose(fp) if nfp fail
+ if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) {
int length = strlen(uident);
while (fgets(genbuf, STRLEN, fp))
@@ -235,11 +228,11 @@ friend_delete(char *uident, int type)
static void
friend_editdesc(char *uident, int type)
{
- FILE *fp, *nfp;
- char fnnew[200], genbuf[200], fn[200];
+ FILE *fp=NULL, *nfp=NULL;
+ char fnnew[200], genbuf[STRLEN], fn[200];
setfriendfile(fn, type);
snprintf(fnnew, sizeof(fnnew), "%s-", fn);
- if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) { // XXX fclose(fp) if nfp fail
+ if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) {
int length = strlen(uident);
while (fgets(genbuf, STRLEN, fp)) {
@@ -251,10 +244,12 @@ friend_editdesc(char *uident, int type)
fprintf(nfp, "%-13s%s\n", uident, buf);
}
}
- fclose(fp);
- fclose(nfp);
Rename(fnnew, fn);
}
+ if(fp)
+ fclose(fp);
+ if(nfp)
+ fclose(nfp);
}
/* type == 0 : load all */