summaryrefslogtreecommitdiffstats
path: root/mbbsd/record.c
diff options
context:
space:
mode:
authorptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-04-30 22:32:22 +0800
committerptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-04-30 22:32:22 +0800
commit1b62cf169aa0a0bcfaf0e22d1088fe59e77b93f9 (patch)
tree68d5dc455498705b7b2b6e5915daa5daa1d0eca7 /mbbsd/record.c
parent413ad044cf6c17af0cc63d5fb80f91b4bfa06713 (diff)
downloadpttbbs-1b62cf169aa0a0bcfaf0e22d1088fe59e77b93f9.tar
pttbbs-1b62cf169aa0a0bcfaf0e22d1088fe59e77b93f9.tar.gz
pttbbs-1b62cf169aa0a0bcfaf0e22d1088fe59e77b93f9.tar.bz2
pttbbs-1b62cf169aa0a0bcfaf0e22d1088fe59e77b93f9.tar.lz
pttbbs-1b62cf169aa0a0bcfaf0e22d1088fe59e77b93f9.tar.xz
pttbbs-1b62cf169aa0a0bcfaf0e22d1088fe59e77b93f9.tar.zst
pttbbs-1b62cf169aa0a0bcfaf0e22d1088fe59e77b93f9.zip
clean up getindex() and substitute record
fix bug of OSONG git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1901 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/record.c')
-rw-r--r--mbbsd/record.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/mbbsd/record.c b/mbbsd/record.c
index efc1089c..e551db61 100644
--- a/mbbsd/record.c
+++ b/mbbsd/record.c
@@ -127,6 +127,53 @@ substitute_record(char *fpath, void *rptr, int size, int id)
return 0;
}
+int
+substitute_ref_record(char *direct, fileheader_t * fhdr, int ent)
+{
+ fileheader_t hdr;
+ char genbuf[256];
+ int num = 0;
+
+ /* rocker.011018: 串接模式用reference增進效率 */
+ if ((fhdr->money & FHR_REFERENCE) &&
+ (num = fhdr->money & ~FHR_REFERENCE)){
+ setdirpath(genbuf, direct, ".DIR");
+ get_record(genbuf, &hdr, sizeof(hdr), num);
+ if (strcmp(hdr.filename, fhdr->filename))
+ {
+ if((num = getindex(genbuf, fhdr->filename, num)))
+ substitute_record(genbuf, fhdr, sizeof(*fhdr), num);
+ fhdr->money = FHR_REFERENCE | num ; // Ptt: update now!
+ }
+ else
+ substitute_record(genbuf, fhdr, sizeof(*fhdr), num);
+ }
+ substitute_record(direct, fhdr, sizeof(*fhdr), ent);
+ return num;
+}
+
+int
+getindex(char *fpath, char *fname, int start)
+{ // Ptt: 從前面找很費力 太暴力
+#define READSIZE 64 // 8192 / sizeof(fileheader_t)
+ int fd, i, len, n = 1; /* n starts from 1 */
+ fileheader_t fhdrs[READSIZE];
+
+ if ((fd = open(fpath, O_RDONLY, 0)) != -1) {
+ while( (len = read(fd, fhdrs, sizeof(fhdrs))) > 0 ){
+ len /= sizeof(fileheader_t);
+ for( i = 0 ; i < len ; ++i, ++n )
+ if (!strcmp(fhdrs[i].filename, fname)) {
+ close(fd);
+ return now;
+ }
+ }
+ close(fd);
+ }
+ return 0;
+}
+
+
/* rocker.011022: 避免lock檔開啟時不正常斷線,造成永久lock */
#ifndef _BBS_UTIL_C_
static int