diff options
author | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2002-12-29 16:04:18 +0800 |
---|---|---|
committer | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2002-12-29 16:04:18 +0800 |
commit | f5f4a61b8ac36ad6d74f4dac22b1a06ca11bc554 (patch) | |
tree | 8fa888619f4ceb4975159f928ebfa41ea906bea1 | |
parent | 7218fa87823fdf5fc3ee6b23b883dc2ddaa083b8 (diff) | |
download | pttbbs-f5f4a61b8ac36ad6d74f4dac22b1a06ca11bc554.tar pttbbs-f5f4a61b8ac36ad6d74f4dac22b1a06ca11bc554.tar.gz pttbbs-f5f4a61b8ac36ad6d74f4dac22b1a06ca11bc554.tar.bz2 pttbbs-f5f4a61b8ac36ad6d74f4dac22b1a06ca11bc554.tar.lz pttbbs-f5f4a61b8ac36ad6d74f4dac22b1a06ca11bc554.tar.xz pttbbs-f5f4a61b8ac36ad6d74f4dac22b1a06ca11bc554.tar.zst pttbbs-f5f4a61b8ac36ad6d74f4dac22b1a06ca11bc554.zip |
store favbuf[] by char array instand of int array.
save 24KB memory (in 8192 boards environment) for each user.
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@590 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | pttbbs/mbbsd/board.c | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 57a521cc..c7543ef2 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.63 2002/12/26 06:16:13 kcwu Exp $ */ +/* $Id: board.c,v 1.64 2002/12/29 08:04:18 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -219,35 +219,41 @@ typedef struct { unsigned int myattr; } boardstat_t; -static int *zapbuf = NULL, *favbuf; +static int *zapbuf = NULL; +static char *favbuf = NULL; static boardstat_t *nbrd = NULL; char zapchange = 0, favchange = 0; #define STR_BBSRC ".bbsrc" #define STR_FAV ".fav" +#define STR_FAV2 ".fav2" void load_brdbuf(void) { static char firsttime = 1; - int fd, size, i; + int fd, size, favsize, i; char fname[80]; size = (numboards + 32) * sizeof(int); + favsize = (numboards + 32) * sizeof(char); #ifdef MEM_CHECK size += sizeof(int); + favsize += sizeof(int); #endif zapbuf = (int *)malloc(size); - favbuf = (int *)malloc(size); + favbuf = (char *)malloc(favsize); #ifdef MEM_CHECK - zapbuf[0] = favbuf[0] = MEM_CHECK; + zapbuf[0] = MEM_CHECK; zapbuf = &zapbuf[1]; - favbuf = &favbuf[1]; + ((int *)favbuf)[0] = MEM_CHECK; + favbuf = &favbuf[ sizeof(int) ]; size -= sizeof(int); + favsize -= sizeof(int); #endif zapchange = favchange = 0; if( firsttime ){ - memset(favbuf, 0, size); + memset(favbuf, 0, favsize); for( i = (numboards + 32) - 1 ; i >= 0 ; --i ) zapbuf[i] = login_start_time; } @@ -257,11 +263,25 @@ void load_brdbuf(void) read(fd, zapbuf, size); close(fd); } - setuserfile(fname, STR_FAV); + setuserfile(fname, STR_FAV2); if ((fd = open(fname, O_RDONLY, 0600)) != -1) { - read(fd, favbuf, size); + read(fd, favbuf, favsize); close(fd); } + else{ + setuserfile(fname, STR_FAV); + if( (fd = open(fname, O_RDONLY, 0600)) != -1 ){ + int *oldfav = (int *)malloc(size); + read(fd, oldfav, size); + close(fd); + unlink(fname); + + for( i = (numboards + 32) - 1 ; i >= 0 ; --i ) + favbuf[i] = oldfav[i]; + free(oldfav); + favchange = 1; + } + } if( firsttime ){ for (i = 0; i < numboards; i++) @@ -307,15 +327,15 @@ save_brdbuf() zapbuf = NULL; } - setuserfile(fname, STR_FAV); + setuserfile(fname, STR_FAV2); if ( favbuf != NULL ){ if( ( #ifdef MEM_CHECK - favbuf[-1] == MEM_CHECK && + ((int*)favbuf)[-1] == MEM_CHECK && #endif favchange && (fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) ){ - size = numboards * sizeof(int); + size = numboards * sizeof(char); write(fd, favbuf, size); close(fd); } |