Fix for FreeBSD LastRead pointers

This commit is contained in:
Michiel Broek 2002-05-26 13:34:47 +00:00
parent a1ae304588
commit 0a70980608

View File

@ -591,7 +591,7 @@ int JAM_Open(char *Msgbase)
void JAM_Pack(void)
{
int fdnHdr, fdnJdx, fdnJdt, fdnJlr;
int ToRead, Readed;
int ToRead, Readed, i, count;
char *File, *New, *Subfield, *Temp;
JAMIDXREC jamIdx;
unsigned long NewNumber = 0, RefNumber = 0, Written = 0;
@ -608,6 +608,12 @@ void JAM_Pack(void)
sprintf(File, "%s%s", BaseName, ".$lr");
fdnJlr = open(File, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
/*
* Get the number of LastRead records, this number is needed to prevent
* that FreeBSD makes garbage of the LastRead pointers for some reason.
*/
count = lseek(fdJlr, 0, SEEK_END) / sizeof(lastread);
if (fdnHdr != -1 && fdnJdt != -1 && fdnJdx != -1 && fdnJlr != -1) {
lseek(fdHdr, 0L, SEEK_SET);
if (read(fdHdr, &jamHdrInfo, sizeof(JAMHDRINFO)) == sizeof(JAMHDRINFO)) {
@ -642,7 +648,8 @@ void JAM_Pack(void)
Written++;
lseek(fdJlr, 0, SEEK_SET);
while ((read(fdJlr, &LR, sizeof(lastread)) == sizeof(lastread))) {
for (i = 0; i < count; i++) {
if ((read(fdJlr, &LR, sizeof(lastread)) == sizeof(lastread))) {
/*
* Test if one of the lastread pointer is the current
* old message number.
@ -659,6 +666,7 @@ void JAM_Pack(void)
write(fdJlr, &LR, sizeof(lastread));
}
}
}
jamHdr.MsgNum = NewNumber;
write(fdnHdr, &jamHdr, sizeof(JAMHDR));
@ -704,9 +712,11 @@ void JAM_Pack(void)
* Now copy the lastread file
*/
lseek(fdJlr, 0, SEEK_SET);
while (read(fdJlr, &LR, sizeof(lastread)) == sizeof(lastread)) {
for (i = 0; i < count; i++) {
if (read(fdJlr, &LR, sizeof(lastread)) == sizeof(lastread)) {
write(fdnJlr, &LR, sizeof(lastread));
}
}
/*
* Close all files