summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-03-30 01:10:13 +0800
committerptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-03-30 01:10:13 +0800
commit1091228603cdb191d3c02e0f22468310140d0f32 (patch)
tree4fb3cc6b1a25796a3870c535b3017ed84de68a39
parent13c558b9e8fd5b10298f3a4afba54ac7111e8519 (diff)
downloadpttbbs-1091228603cdb191d3c02e0f22468310140d0f32.tar
pttbbs-1091228603cdb191d3c02e0f22468310140d0f32.tar.gz
pttbbs-1091228603cdb191d3c02e0f22468310140d0f32.tar.bz2
pttbbs-1091228603cdb191d3c02e0f22468310140d0f32.tar.lz
pttbbs-1091228603cdb191d3c02e0f22468310140d0f32.tar.xz
pttbbs-1091228603cdb191d3c02e0f22468310140d0f32.tar.zst
pttbbs-1091228603cdb191d3c02e0f22468310140d0f32.zip
less file I/O
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1626 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--mbbsd/record.c72
1 files changed, 6 insertions, 66 deletions
diff --git a/mbbsd/record.c b/mbbsd/record.c
index dd543f77..e6d88fda 100644
--- a/mbbsd/record.c
+++ b/mbbsd/record.c
@@ -416,66 +416,6 @@ safe_article_delete_range(char *direct, int from, int to)
return 0;
}
-int
-delete_file(char *dirname, int size, int ent, int (*filecheck) ())
-{
- char abuf[BUFSIZE];
- int fd;
- struct stat st;
- long numents;
-
- if (ent < 1 || (fd = open(dirname, O_RDWR)) == -1)
- return -1;
- flock(fd, LOCK_EX);
- fstat(fd, &st);
- numents = ((long)st.st_size) / size;
- if (((long)st.st_size) % size)
- fprintf(stderr, "align err\n");
- if (lseek(fd, (off_t) size * (ent - 1), SEEK_SET) != -1) {
- if (read(fd, abuf, size) == size) {
- if ((*filecheck) (abuf)) {
- int i;
-
- for (i = ent; i < numents; i++) {
- if (lseek(fd, (off_t) ((i) * size), SEEK_SET) == -1 ||
- read(fd, abuf, size) != size ||
- lseek(fd, (off_t) (i - 1) * size, SEEK_SET) == -1)
- break;
- if (safewrite(fd, abuf, size) != size)
- break;
- }
- ftruncate(fd, (off_t) size * (numents - 1));
- flock(fd, LOCK_UN);
- close(fd);
- return 0;
- }
- }
- }
- lseek(fd, 0, SEEK_SET);
- ent = 1;
- while (read(fd, abuf, size) == size) {
- if ((*filecheck) (abuf)) {
- int i;
-
- for (i = ent; i < numents; i++) {
- if (lseek(fd, (off_t) (i + 1) * size, SEEK_SET) == -1 ||
- read(fd, abuf, size) != size ||
- lseek(fd, (off_t) (i) * size, SEEK_SET) == -1 ||
- safewrite(fd, abuf, size) != size)
- break;
- }
- ftruncate(fd, (off_t) size * (numents - 1));
- flock(fd, LOCK_UN);
- close(fd);
- return 0;
- }
- ent++;
- }
- flock(fd, LOCK_UN);
- close(fd);
- return -1;
-}
-
#endif
#endif /* !defined(_BBS_UTIL_C_) */
@@ -503,19 +443,19 @@ stampfile(char *fpath, fileheader_t * fh)
register char *ip = fpath;
time_t dtime = COMMON_TIME;
struct tm *ptime;
- int fp = 0;
+// int fp = 0; //Ptt: don't need to check
if (access(fpath, X_OK | R_OK | W_OK))
mkdir(fpath, 0755);
while (*(++ip));
*ip++ = '/';
- do {
+// do {
sprintf(ip, "M.%d.A.%3.3X", (int)++dtime, rand() & 0xFFF);
- if (fp == -1 && errno != EEXIST)
- return -1;
- } while ((fp = open(fpath, O_CREAT | O_EXCL | O_WRONLY, 0644)) == -1);
- close(fp);
+// if (fp == -1 && errno != EEXIST)
+// return -1;
+// } while ((fp = open(fpath, O_CREAT | O_EXCL | O_WRONLY, 0644)) == -1);
+// close(fp);
memset(fh, 0, sizeof(fileheader_t));
strlcpy(fh->filename, ip, sizeof(fh->filename));
ptime = localtime(&dtime);