Есть давнишняя процедура - запись строки в лог-файл
Понадобилось добавить контроль размера файла что-бы не рос безгранично.
Почему то ReadData() выдает всегда 0.
Может у меня глаз замылился - очевидного не вижу?
Procedure WriteToLog(entry.s)
Protected hFile.l, LenFile.q, p, bytes, *MemoryID
LockMutex(LogFileMutex)
hFile = OpenFile(#PB_Any, glLogFile$)
If hFile = #Null
ProcedureReturn #False
EndIf
FileSeek(hFile, Lof(hFile))
WriteStringN(hFile, FormatDate("%yyyy%mm%dd %hh:%ii:%ss:", Date())+entry)
;контроль размера файла
LenFile=Lof(hFile)
If LenFile>51200 ;50k
FlushFileBuffers(hFile)
Debug Str(LenFile)+">51200"
*MemoryID = AllocateMemory(LenFile) ; allocate the needed memory
If *MemoryID
Debug "Lof(hFile)="+Str(Lof(hFile))
bytes = ReadData(hFile, *MemoryID, LenFile) ; read all data into the memory block
Debug "bytes="+Str(bytes)
For p=(LenFile-51200) To (LenFile-1)
If PeekS(*MemoryID+p , 2, #PB_Ascii)=#CRLF$
CloseFile(hFile)
If CreateFile(hFile, glLogFile$)
WriteData(hFile, *MemoryID+p, LenFile-p-1)
EndIf
EndIf
Next
EndIf
EndIf
CloseFile(hFile)
UnlockMutex(LogFileMutex)
ProcedureReturn #True
EndProcedure