From d3fdd732faa5e3af2d0029ec5b385399d62f4b3e Mon Sep 17 00:00:00 2001 From: shatty Date: Wed, 27 Aug 2003 01:33:17 +0000 Subject: [PATCH] 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 --- src/kits/translation/TranslationUtils.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/kits/translation/TranslationUtils.cpp b/src/kits/translation/TranslationUtils.cpp index 06a92f805f..3418c8d5b7 100644 --- a/src/kits/translation/TranslationUtils.cpp +++ b/src/kits/translation/TranslationUtils.cpp @@ -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