summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-03-25 06:27:37 +0800
committerptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-03-25 06:27:37 +0800
commit194d19647bc28b9a4299a6c22e1179178ceabff9 (patch)
tree9a997203d5a0b954ada275f502ca7661093da472
parentaf0559d83afbcc141db57d0b0db31d73a96f312d (diff)
downloadpttbbs-194d19647bc28b9a4299a6c22e1179178ceabff9.tar
pttbbs-194d19647bc28b9a4299a6c22e1179178ceabff9.tar.gz
pttbbs-194d19647bc28b9a4299a6c22e1179178ceabff9.tar.bz2
pttbbs-194d19647bc28b9a4299a6c22e1179178ceabff9.tar.lz
pttbbs-194d19647bc28b9a4299a6c22e1179178ceabff9.tar.xz
pttbbs-194d19647bc28b9a4299a6c22e1179178ceabff9.tar.zst
pttbbs-194d19647bc28b9a4299a6c22e1179178ceabff9.zip
simplfy append_record
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1605 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--mbbsd/cal.c3
-rw-r--r--mbbsd/mail.c21
-rw-r--r--mbbsd/record.c15
3 files changed, 19 insertions, 20 deletions
diff --git a/mbbsd/cal.c b/mbbsd/cal.c
index a443291d..d2cec676 100644
--- a/mbbsd/cal.c
+++ b/mbbsd/cal.c
@@ -206,9 +206,8 @@ osong(char *defaultid)
fclose(fp1);
fclose(fp);
- //do_append(OSONGMAIL "/.DIR", &mail2, sizeof(mail2));
- if (do_append(OSONGPATH "/.DIR", &mail, sizeof(mail)) != -1) {
+ if (append_record(OSONGPATH "/.DIR", &mail, sizeof(mail)) != -1) {
cuser.lastsong = now;
/* Jaky 超過 500 首歌就開始砍 */
nsongs = get_num_records(OSONGPATH "/.DIR", sizeof(mail));
diff --git a/mbbsd/mail.c b/mbbsd/mail.c
index a4fa0799..2d21d3ad 100644
--- a/mbbsd/mail.c
+++ b/mbbsd/mail.c
@@ -102,7 +102,7 @@ mail_id(char *id, char *title, char *filename, char *owner)
mhdr.filemode = 0;
Link(filename, genbuf);
sethomedir(genbuf, id);
- append_record(genbuf, &mhdr, sizeof(mhdr));
+ append_record_forward(genbuf, &mhdr, sizeof(mhdr));
mailalert(id);
return 0;
}
@@ -212,8 +212,7 @@ do_hold_mail(char *fpath, char *receiver, char *holder)
unlink(buf);
Link(fpath, buf);
- /* Ptt: append_record->do_append */
- do_append(title, &mymail, sizeof(mymail));
+ append_record_forward(title, &mymail, sizeof(mymail));
}
void
@@ -302,9 +301,9 @@ do_send(char *userid, char *title)
i = belong(fpath, cuser.userid);
sethomefile(fpath, userid, FN_REJECT);
- if (i || !belong(fpath, cuser.userid)) { /* Ptt: 用belong有點討厭 */
+ if (i || !belong(fpath, cuser.userid)) {/* Ptt: 用belong有點討厭 */
sethomedir(fpath, userid);
- if (append_record(fpath, &mhdr, sizeof(mhdr)) == -1)
+ if (append_record_forward(fpath, &mhdr, sizeof(mhdr)) == -1)
return -1;
mailalert(userid);
}
@@ -530,7 +529,7 @@ multi_send(char *title)
strlcpy(mymail.title, save_title, sizeof(mymail.title));
mymail.filemode |= FILE_MULTI; /* multi-send flag */
sethomedir(genbuf, p->word);
- if (append_record(genbuf, &mymail, sizeof(mymail)) == -1)
+ if (append_record_forward(genbuf, &mymail, sizeof(mymail)) == -1)
outs(err_uid);
mailalert(p->word);
}
@@ -614,7 +613,7 @@ mail_all()
strlcpy(mymail.title, save_title, sizeof(mymail.title));
sethomedir(genbuf, cuser.userid);
- if (append_record(genbuf, &mymail, sizeof(mymail)) == -1)
+ if (append_record_forward(genbuf, &mymail, sizeof(mymail)) == -1)
outs(err_uid);
for (unum = SHM->number, i = 0; i < unum; i++) {
@@ -633,7 +632,7 @@ mail_all()
strlcpy(mymail.title, save_title, sizeof(mymail.title));
/* mymail.filemode |= FILE_MARKED; Ptt 公告改成不會mark */
sethomedir(genbuf, userid);
- if (append_record(genbuf, &mymail, sizeof(mymail)) == -1)
+ if (append_record_forward(genbuf, &mymail, sizeof(mymail)) == -1)
outs(err_uid);
snprintf(genbuf, sizeof(genbuf),
"%*s %5d / %5d", IDLEN + 1, userid, i + 1, unum);
@@ -1479,7 +1478,7 @@ send_inner_mail(char *fpath, char *title, char *receiver)
unlink(genbuf);
Link(fpath, genbuf);
sethomedir(genbuf, receiver);
- return do_append(genbuf, &mymail, sizeof(mymail));
+ return append_record_forward(genbuf, &mymail, sizeof(mymail));
}
#include <netdb.h>
@@ -1593,7 +1592,7 @@ bsmtp(char *fpath, char *title, char *rcpt, int method)
strlcpy(mqueue.sender, cuser.userid, sizeof(mqueue.sender));
strlcpy(mqueue.username, cuser.username, sizeof(mqueue.username));
strlcpy(mqueue.rcpt, rcpt, sizeof(mqueue.rcpt));
- if (do_append("out/.DIR", (fileheader_t *) & mqueue, sizeof(mqueue)) < 0)
+ if (append_record("out/.DIR", (fileheader_t *) & mqueue, sizeof(mqueue)) < 0)
return 0;
return chrono;
}
@@ -1779,6 +1778,6 @@ mail_justify(userec_t muser)
} else
Link("etc/bademail", buf1);
sethomedir(title, muser.userid);
- append_record(title, &mhdr, sizeof(mhdr));
+ append_record_forward(title, &mhdr, sizeof(mhdr));
}
#endif /* EMAIL_JUSTIFY */
diff --git a/mbbsd/record.c b/mbbsd/record.c
index 17f8b482..00568f3e 100644
--- a/mbbsd/record.c
+++ b/mbbsd/record.c
@@ -553,9 +553,9 @@ stamplink(char *fpath, fileheader_t * fh)
}
int
-do_append(char *fpath, fileheader_t * record, int size)
+append_record(char *fpath, fileheader_t * record, int size)
{
- int fd, fsize=0;
+ int fd, fsize=0, index;
struct stat st;
if ((fd = open(fpath, O_WRONLY | O_CREAT, 0644)) == -1) {
@@ -567,17 +567,18 @@ do_append(char *fpath, fileheader_t * record, int size)
if(fstat(fd, &st)!=-1)
fsize = st.st_size;
- lseek(fd, (fsize / size) * size, SEEK_SET); // avoid offset
+ index = fsize / size;
+ lseek(fd, index * size, SEEK_SET); // avoid offset
safewrite(fd, record, size);
flock(fd, LOCK_UN);
close(fd);
- return 0;
+ return index + 1;
}
int
-append_record(char *fpath, fileheader_t * record, int size)
+append_record_forward(char *fpath, fileheader_t * record, int size)
{
#if !defined(_BBS_UTIL_C_)
int m, n;
@@ -596,7 +597,7 @@ append_record(char *fpath, fileheader_t * record, int size)
if (buf[0] != 0 && buf[0] != ' ') {
buf[n + 1] = 0;
strcat(buf, record->filename);
- do_append(fpath, record, size);
+ append_record(fpath, record, size);
#ifndef USE_BSMTP
bbs_sendmail(buf, record->title, address);
#else
@@ -608,7 +609,7 @@ append_record(char *fpath, fileheader_t * record, int size)
}
#endif
- do_append(fpath, record, size);
+ append_record(fpath, record, size);
return 0;
}