Fix for fseek error in auto create when database is too small
This commit is contained in:
parent
b1353db234
commit
81c87eb1d6
@ -230,9 +230,25 @@ int CheckTicGroup(char *Area, int SendUplink, faddr *f)
|
||||
fread(&areahdr, sizeof(areahdr), 1, fp);
|
||||
Syslog('f', "File area is open");
|
||||
|
||||
/*
|
||||
* Verify the file is large enough
|
||||
*/
|
||||
fseek(fp, 0, SEEK_END);
|
||||
offset = areahdr.hdrsize + ((fgroup.StartArea -1) * (areahdr.recsize));
|
||||
Syslog('+', "file end at %ld, offset needed %ld", ftell(fp), offset);
|
||||
|
||||
if (ftell(fp) < offset) {
|
||||
Syslog('f', "Database too small, expanding...");
|
||||
memset(&area, 0, sizeof(area));
|
||||
while (TRUE) {
|
||||
fwrite(&area, sizeof(area), 1, fp);
|
||||
if (ftell(fp) >= areahdr.hdrsize + ((fgroup.StartArea -1) * (areahdr.recsize)))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (fseek(fp, offset, SEEK_SET)) {
|
||||
WriteError("$Can't seek in %s", temp);
|
||||
WriteError("$Can't seek in %s to position %ld", temp, offset);
|
||||
fclose(ap);
|
||||
fclose(mp);
|
||||
fclose(fp);
|
||||
|
@ -140,6 +140,24 @@ int CheckEchoGroup(char *Area, int SendUplink, faddr *f)
|
||||
}
|
||||
fread(&msgshdr, sizeof(msgshdr), 1, mp);
|
||||
offset = msgshdr.hdrsize + ((mgroup.StartArea -1) * (msgshdr.recsize + msgshdr.syssize));
|
||||
Syslog('+', "file end at %ld, offset needed %ld", ftell(mp), offset);
|
||||
|
||||
/*
|
||||
* Verify the file is large enough
|
||||
*/
|
||||
if (ftell(mp) < offset) {
|
||||
Syslog('m', "Database too small, expanding...");
|
||||
memset(&msgs, 0, sizeof(msgs));
|
||||
memset(&System, 0, sizeof(System));
|
||||
while (TRUE) {
|
||||
fwrite(&msgs, sizeof(msgs), 1, mp);
|
||||
for (i = 0; i < (msgshdr.syssize / sizeof(System)); i++)
|
||||
fwrite(&System, sizeof(System), 1, mp);
|
||||
if (ftell(mp) >= msgshdr.hdrsize + ((mgroup.StartArea -1) * (msgshdr.recsize + msgshdr.syssize)))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (fseek(mp, offset, SEEK_SET)) {
|
||||
WriteError("$Can't seek in %s", temp);
|
||||
fclose(ap);
|
||||
|
Reference in New Issue
Block a user