summaryrefslogtreecommitdiffstats
path: root/mbbsd/cache.c
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-04-15 20:05:52 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-04-15 20:05:52 +0800
commit1a77a39f25006a3f73b36365220c3168c59f9fd2 (patch)
tree9c4fc1c9715dfeaad11cb8bcc159b6cf23e9c417 /mbbsd/cache.c
parent5894f7afe1f35469e766a3c3fd6f6b0ee806a31a (diff)
downloadpttbbs-1a77a39f25006a3f73b36365220c3168c59f9fd2.tar
pttbbs-1a77a39f25006a3f73b36365220c3168c59f9fd2.tar.gz
pttbbs-1a77a39f25006a3f73b36365220c3168c59f9fd2.tar.bz2
pttbbs-1a77a39f25006a3f73b36365220c3168c59f9fd2.tar.lz
pttbbs-1a77a39f25006a3f73b36365220c3168c59f9fd2.tar.xz
pttbbs-1a77a39f25006a3f73b36365220c3168c59f9fd2.tar.zst
pttbbs-1a77a39f25006a3f73b36365220c3168c59f9fd2.zip
MDCACHE
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@103 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/cache.c')
-rw-r--r--mbbsd/cache.c46
1 files changed, 44 insertions, 2 deletions
diff --git a/mbbsd/cache.c b/mbbsd/cache.c
index daef6628..8fceef65 100644
--- a/mbbsd/cache.c
+++ b/mbbsd/cache.c
@@ -1,4 +1,4 @@
-/* $Id: cache.c,v 1.8 2002/04/09 20:33:52 in2 Exp $ */
+/* $Id: cache.c,v 1.9 2002/04/15 12:05:52 in2 Exp $ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -826,7 +826,8 @@ int haspostperm(char *bname) {
/* cachefor °ÊºA¬Ýª© */
struct pttcache_t *ptt;
-static void reload_pttcache() {
+static void reload_pttcache()
+{
if(ptt->busystate)
safe_sleep(1);
else { /* jochang: temporary workaround */
@@ -895,11 +896,13 @@ static void reload_pttcache() {
}
}
+int *GLOBE;
void resolve_garbage() {
int count=0;
if(ptt == NULL) {
ptt = attach_shm(PTTSHM_KEY, sizeof(*ptt));
+ GLOBE = ptt->GLOBE;
if(ptt->touchtime == 0)
ptt->touchtime = 1;
}
@@ -1021,3 +1024,42 @@ int hbflcheck(int bid, int uid)
}
return 1;
}
+
+#ifdef MDCACHE
+char *cachepath(const char *fpath)
+{
+ static char cpath[128];
+ char *ptr;
+ snprintf(cpath, sizeof(cpath), "cache/%s", fpath);
+ for( ptr = &cpath[6] ; *ptr != 0 ; ++ptr )
+ if( *ptr == '/' )
+ *ptr = '.';
+ return cpath;
+}
+
+int updatemdcache(const char *CPATH, const char *fpath)
+{
+ /* save file to mdcache with *cpath and *fpath,
+ return: -1 if error
+ else the fd
+ */
+ int len, sourcefd, targetfd;
+ char buf[1024], *cpath;
+ cpath = (CPATH == NULL) ? cachepath(fpath) : CPATH;
+ if( (sourcefd = open(fpath, O_RDONLY)) < 0 )
+ return -1;
+ if( (targetfd = open(cpath, O_RDWR | O_CREAT, 0600)) < 0 )
+ /* md is full? */
+ return -1;
+ while( (len = read(sourcefd, buf, sizeof(buf))) > 0 )
+ if( write(targetfd, buf, len) < len ){
+ /* md is full? */
+ close(targetfd);
+ unlink(cpath);
+ return sourcefd;
+ }
+ close(sourcefd);
+ lseek(targetfd, 0, SEEK_SET);
+ return targetfd;
+}
+#endif