Close file handle when done.
This also brings the arena to a single-return standard.
This commit is contained in:
parent
b1bbaebdac
commit
0a661a7d70
|
@ -127,26 +127,25 @@ Arena::Open(const char *path)
|
||||||
int
|
int
|
||||||
Arena::Create(const char *path, size_t fileSize)
|
Arena::Create(const char *path, size_t fileSize)
|
||||||
{
|
{
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
if (this->size > 0) {
|
if (this->size > 0) {
|
||||||
this->Destroy();
|
this->Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
auto *fHandle = fopen(path, "w");
|
auto *fHandle = fopen(path, "w");
|
||||||
if (fHandle == nullptr) {
|
if (fHandle != nullptr) {
|
||||||
return -1;
|
auto newFileDes = fileno(fHandle);
|
||||||
}
|
if (ftruncate(newFileDes, static_cast<off_t>(fileSize)) == 0) {
|
||||||
|
ret = this->Open(path);
|
||||||
|
}
|
||||||
|
|
||||||
auto newFileDes = fileno(fHandle);
|
|
||||||
|
|
||||||
if (ftruncate(newFileDes, static_cast<off_t>(fileSize)) == -1) {
|
|
||||||
close(newFileDes);
|
close(newFileDes);
|
||||||
fclose(fHandle);
|
fclose(fHandle);
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
close(newFileDes);
|
return ret;
|
||||||
return this->Open(path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue