#include <unistd.h>
#include <new>
#include <unique_ptr.h>
+#include <string.h>
+#include <errno.h>
#include <FBaseInteger.h>
#include <FBaseDouble.h>
#include <FBase_StringConverter.h>
#include <FBase_LocalizedNumParser.h>
+#include <FBase_NativeError.h>
#include <FApp_AppInfo.h>
#include "FIo_FileImpl.h"
#include "FIo_NormalRegistry.h"
"[E_PARSING_FAILED] Entry name could not be parsed.");
}
- line.SubString(firstTokenPos + 1, entryVal); // extract entry value
+ if (line.GetLength() > firstTokenPos + 1)
+ {
+ line.SubString(firstTokenPos + 1, entryVal); // extract entry value
+ }
// check if entry value contains invalid chars
pEntryValue.reset(_StringConverter::CopyToCharArrayN(entryVal));
return E_SUCCESS;
}
- result r = E_SUCCESS;
-
- String openMode(L"w+");
- unique_ptr<_FileImpl> pFileImpl(new (std::nothrow) _FileImpl);
- SysTryReturnResult(NID_IO, pFileImpl != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
+ result r = __pFileImpl->Seek(FILESEEKPOSITION_BEGIN, 0);
+ SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
- //TODO: Secure mode is to be handled
- r = pFileImpl->Construct(_regPath, "w+", null);
+ r = __pFileImpl->Truncate(0);
SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
- r = pFileImpl->Write(_pBuffer, _length);
+ r = __pFileImpl->Write(_pBuffer, _length);
SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
- r = pFileImpl->Flush();
+ r = __pFileImpl->Flush();
SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
return r;
if (_sectionList.GetCount() == 0)
{
unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(_regPath));
- truncate(pFilePath.get(), 0);
-
+ int res = truncate(pFilePath.get(), 0);
+ SysTryReturnResult(NID_IO, res == 0, __ConvertNativeErrorToResult(errno),
+ "Failed to truncate. errno: %d (%s)", errno, strerror(errno));
return E_SUCCESS;
}