diff options
author | kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-02-28 03:18:03 +0800 |
---|---|---|
committer | kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-02-28 03:18:03 +0800 |
commit | 701d7bf89d729a5e0659ae3d6d50493aab7b15fd (patch) | |
tree | 2eac436742327cd7bf20d2082bacb9b030d6174b | |
parent | b3f41894a7bede7d474158daae14560c88b1e3b4 (diff) | |
download | pttbbs-701d7bf89d729a5e0659ae3d6d50493aab7b15fd.tar pttbbs-701d7bf89d729a5e0659ae3d6d50493aab7b15fd.tar.gz pttbbs-701d7bf89d729a5e0659ae3d6d50493aab7b15fd.tar.bz2 pttbbs-701d7bf89d729a5e0659ae3d6d50493aab7b15fd.tar.lz pttbbs-701d7bf89d729a5e0659ae3d6d50493aab7b15fd.tar.xz pttbbs-701d7bf89d729a5e0659ae3d6d50493aab7b15fd.tar.zst pttbbs-701d7bf89d729a5e0659ae3d6d50493aab7b15fd.zip |
reduce system call
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2562 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | mbbsd/fav.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/mbbsd/fav.c b/mbbsd/fav.c index 57292d19..0c627660 100644 --- a/mbbsd/fav.c +++ b/mbbsd/fav.c @@ -426,14 +426,14 @@ void fav_folder_out(void) fav_stack_pop(); } -static void read_favrec(int fd, fav_t *fp) +static void read_favrec(FILE *frp, fav_t *fp) { int i; fav_type_t *ft; - read(fd, &fp->nBoards, sizeof(fp->nBoards)); - read(fd, &fp->nLines, sizeof(fp->nLines)); - read(fd, &fp->nFolders, sizeof(fp->nFolders)); + fread(&fp->nBoards, sizeof(fp->nBoards), 1, frp); + fread(&fp->nLines, sizeof(fp->nLines), 1, frp); + fread(&fp->nFolders, sizeof(fp->nFolders), 1, frp); fp->DataTail = get_data_number(fp); fp->nAllocs = fp->DataTail + FAV_PRE_ALLOC; fp->lineID = fp->folderID = 0; @@ -441,8 +441,8 @@ static void read_favrec(int fd, fav_t *fp) for(i = 0; i < fp->DataTail; i++){ ft = &fp->favh[i]; - read(fd, &ft->type, sizeof(ft->type)); - read(fd, &ft->attr, sizeof(ft->attr)); + fread(&ft->type, sizeof(ft->type), 1, frp); + fread(&ft->attr, sizeof(ft->attr), 1, frp); ft->fp = (void *)fav_malloc(get_type_size(ft->type)); /* TODO A pointer has different size between 32 and 64-bit arch. @@ -451,11 +451,11 @@ static void read_favrec(int fd, fav_t *fp) * here. It should be FIXED in the next version. */ switch (ft->type) { case FAVT_FOLDER: - read(fd, ft->fp, sizeof(fav_folder4_t)); + fread(ft->fp, sizeof(fav_folder4_t), 1, frp); break; case FAVT_BOARD: case FAVT_LINE: - read(fd, ft->fp, get_type_size(ft->type)); + fread(ft->fp, get_type_size(ft->type), 1, frp); break; } } @@ -465,7 +465,7 @@ static void read_favrec(int fd, fav_t *fp) switch (ft->type) { case FAVT_FOLDER: { fav_t *p = (fav_t *)fav_malloc(sizeof(fav_t)); - read_favrec(fd, p); + read_favrec(frp, p); cast_folder(ft)->this_folder = p; cast_folder(ft)->fid = ++(fp->folderID); break; @@ -482,7 +482,7 @@ static void read_favrec(int fd, fav_t *fp) */ int fav_load(void) { - int fd; + FILE *frp; char buf[128]; fav_t *fp; if (fav_stack_num > 0) @@ -498,12 +498,12 @@ int fav_load(void) return 0; } - if ((fd = open(buf, O_RDONLY)) < 0) + if ((frp = fopen(buf, "r")) == NULL) return -1; fp = (fav_t *)fav_malloc(sizeof(fav_t)); - read_favrec(fd, fp); + read_favrec(frp, fp); fav_stack_push_fav(fp); - close(fd); + fclose(frp); #ifdef MEM_CHECK fav_set_memcheck(MEM_CHECK); #endif |