summaryrefslogtreecommitdiffstats
path: root/mbbsd/record.c
diff options
context:
space:
mode:
author(no author) <(no author)@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-09-04 16:13:43 +0800
committer(no author) <(no author)@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-09-04 16:13:43 +0800
commit157642992e5f2d5dc367b6905a7d453a4ea66845 (patch)
treee04f35001131f3a84cbe477d4be908da0063e335 /mbbsd/record.c
parenta81645961f0ab104dc8b09825aa9379083308c14 (diff)
downloadpttbbs-157642992e5f2d5dc367b6905a7d453a4ea66845.tar
pttbbs-157642992e5f2d5dc367b6905a7d453a4ea66845.tar.gz
pttbbs-157642992e5f2d5dc367b6905a7d453a4ea66845.tar.bz2
pttbbs-157642992e5f2d5dc367b6905a7d453a4ea66845.tar.lz
pttbbs-157642992e5f2d5dc367b6905a7d453a4ea66845.tar.xz
pttbbs-157642992e5f2d5dc367b6905a7d453a4ea66845.tar.zst
pttbbs-157642992e5f2d5dc367b6905a7d453a4ea66845.zip
add get_record_keep().
we don't need to open/close the same file every time in title search mode. git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1155 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/record.c')
-rw-r--r--mbbsd/record.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/mbbsd/record.c b/mbbsd/record.c
index 55f78787..491af517 100644
--- a/mbbsd/record.c
+++ b/mbbsd/record.c
@@ -56,11 +56,27 @@ get_sum_records(char *fpath, int size)
}
int
+get_record_keep(char *fpath, void *rptr, int size, int id, int *fd)
+{
+ /* 和 get_record() 一樣. 不過藉由 *fd, 可使同一個檔案不要一直重複開關 */
+ if (id >= 1 &&
+ (*fd > 0 ||
+ ((*fd = open(fpath, O_RDONLY, 0)) > 0))){
+ if (lseek(*fd, (off_t) (size * (id - 1)), SEEK_SET) != -1) {
+ if (read(*fd, rptr, size) == size) {
+ return 0;
+ }
+ }
+ }
+ return -1;
+}
+
+int
get_record(char *fpath, void *rptr, int size, int id)
{
int fd = -1;
- if (id < 1 || (fd = open(fpath, O_RDONLY, 0)) != -1) {
+ if (id >= 1 && (fd = open(fpath, O_RDONLY, 0)) != -1) {
if (lseek(fd, (off_t) (size * (id - 1)), SEEK_SET) != -1) {
if (read(fd, rptr, size) == size) {
close(fd);