Changed the way WriteAt() works, and fixed a small bug in SetSize()
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1157 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
bd3f5af3d4
commit
0c444b4265
@ -340,10 +340,17 @@ BMallocIO::WriteAt(off_t pos, const void *buffer, size_t size)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
size_t newSize = max(pos + size, static_cast<off_t>(fLength));
|
||||
status_t error = SetSize(newSize);
|
||||
if (error == B_OK)
|
||||
|
||||
if (newSize > fMallocSize)
|
||||
if (SetSize(newSize) != B_OK)
|
||||
size = 0;
|
||||
|
||||
if (size > 0) {
|
||||
memcpy(fData + pos, buffer, size);
|
||||
return (error != B_OK ? error : size);
|
||||
if (pos + size > fLength)
|
||||
fLength = pos + size;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
@ -396,7 +403,6 @@ BMallocIO::SetSize(off_t size)
|
||||
memset(newData + fMallocSize, 0, newSize - fMallocSize);
|
||||
fData = newData;
|
||||
fMallocSize = newSize;
|
||||
fLength = newSize;
|
||||
} else // couldn't alloc the memory
|
||||
error = B_NO_MEMORY;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user