fix the "extra bytes at the end" bug that happens when the existing file has more bytes than the new file. I chose to SetSize(textLength) after Write instead of SetSize(0) before the Write because there is less of a chance of complete data loss if the Write fails somehow. right? (write?) :-)
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4385 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
d7ef3fc59c
commit
d3fdd732fa
@ -682,10 +682,21 @@ BTranslationUtils::WriteStyledEditFile(BTextView *fromView, BFile *intoFile)
|
||||
if (kpTextData == NULL && textLength != 0)
|
||||
return B_ERROR;
|
||||
|
||||
// move to the start of the file if not already there
|
||||
status_t result = B_OK;
|
||||
result = intoFile->Seek(0,SEEK_SET);
|
||||
if (result != B_OK)
|
||||
return result;
|
||||
|
||||
// Write plain text data to file
|
||||
ssize_t amtWritten = intoFile->Write(kpTextData, textLength);
|
||||
if (amtWritten != textLength)
|
||||
return B_ERROR;
|
||||
|
||||
// truncate any extra text
|
||||
result = intoFile->SetSize(textLength);
|
||||
if (result != B_OK)
|
||||
return result;
|
||||
|
||||
// Write attributes
|
||||
// BEOS:TYPE
|
||||
|
Loading…
Reference in New Issue
Block a user