Revision: 9077 https://osdn.net/projects/ttssh2/scm/svn/commits/9077 Author: zmatsuo Date: 2020-12-20 21:11:08 +0900 (Sun, 20 Dec 2020) Log Message: ----------- Win16API を Win32API へ置き換え - ttpfile/filesys_win32.cpp,h へ分離 - Win32 API に変更 - _lopen(), _lread(), _lwrite() などを使用いない - Win16 API wrapper (win16api.h) を使用しない - TFileVarProto に OpenRead(), OpenWrite(), Seek() を追加 Modified Paths: -------------- trunk/teraterm/teraterm/CMakeLists.txt trunk/teraterm/teraterm/filesys_proto.cpp trunk/teraterm/teraterm/filesys_proto.h trunk/teraterm/teraterm/ttermpro.v16.vcxproj trunk/teraterm/teraterm/ttermpro.v16.vcxproj.filters trunk/teraterm/teraterm/ttermpro.v8.vcproj trunk/teraterm/ttpfile/bplus.c trunk/teraterm/ttpfile/ftlib.c trunk/teraterm/ttpfile/kermit.c trunk/teraterm/ttpfile/quickvan.c trunk/teraterm/ttpfile/xmodem.c trunk/teraterm/ttpfile/ymodem.c trunk/teraterm/ttpfile/zmodem.c Added Paths: ----------- trunk/teraterm/ttpfile/filesys_win32.cpp trunk/teraterm/ttpfile/filesys_win32.h -------------- next part -------------- Modified: trunk/teraterm/teraterm/CMakeLists.txt =================================================================== --- trunk/teraterm/teraterm/CMakeLists.txt 2020-12-20 12:10:57 UTC (rev 9076) +++ trunk/teraterm/teraterm/CMakeLists.txt 2020-12-20 12:11:08 UTC (rev 9077) @@ -182,6 +182,8 @@ PRIVATE ../ttpfile/bplus.c ../ttpfile/bplus.h + ../ttpfile/filesys_win32.cpp + ../ttpfile/filesys_win32.h ../ttpfile/ftlib.c ../ttpfile/ftlib.h ../ttpfile/kermit.c Modified: trunk/teraterm/teraterm/filesys_proto.cpp =================================================================== --- trunk/teraterm/teraterm/filesys_proto.cpp 2020-12-20 12:10:57 UTC (rev 9076) +++ trunk/teraterm/teraterm/filesys_proto.cpp 2020-12-20 12:11:08 UTC (rev 9077) @@ -55,6 +55,8 @@ #include "filesys_proto.h" #include "ttfile_proto.h" #include "tt_res.h" +#include "filesys_win32.h" + #include "kermit.h" #include "xmodem.h" #include "ymodem.h" @@ -69,47 +71,6 @@ static PProtoDlg PtDlg = NULL; -static size_t _ReadFile(TFileVarProto *fv, void *buf, size_t bytes) -{ - HANDLE hFile = fv->FileHandle; - DWORD NumberOfBytesRead; - BOOL Result = ReadFile(hFile, buf, (UINT)bytes, &NumberOfBytesRead, NULL); - if (Result == FALSE) { - return 0; - } - return NumberOfBytesRead; -} - -static size_t _WriteFile(TFileVarProto *fv, const void *buf, size_t bytes) -{ - HANDLE hFile = fv->FileHandle; - DWORD NumberOfBytesWritten; - UINT length = (UINT)bytes; - BOOL result = WriteFile(hFile, buf, length, &NumberOfBytesWritten, NULL); - if (result == FALSE) { - return 0; - } - return NumberOfBytesWritten; -} - -static void _Close(TFileVarProto *fv) -{ - HANDLE hFile = fv->FileHandle; - CloseHandle(hFile); - fv->FileHandle = 0; -} - -/** - * \x83t\x83@\x83C\x83\x8B\x82̃t\x83@\x83C\x83\x8B\x83T\x83C\x83Y\x82\xF0\x8E擾 - * @param[in] filenameU8 \x83t\x83@\x83C\x83\x8B\x96\xBC(UTF-8) - * @retval \x83t\x83@\x83C\x83\x8B\x83T\x83C\x83Y - */ -static size_t _GetFSize(struct FileVarProto *fv, const char *filenameU8) -{ - size_t file_size = GetFSize64W(wc::fromUtf8(filenameU8)); - return file_size; -} - static void _SetDlgTime(TFileVarProto *fv, DWORD elapsed, int bytes) { SetDlgTime(fv->HWin, IDC_PROTOELAPSEDTIME, fv->StartTime, fv->ByteCount); @@ -165,10 +126,7 @@ fv->NoMsg = FALSE; fv->HideDialog = FALSE; - fv->ReadFile = _ReadFile; - fv->WriteFile = _WriteFile; - fv->Close = _Close; - fv->GetFSize = _GetFSize; + FilesysCreate(fv); fv->InitDlgProgress = _InitDlgProgress; fv->SetDlgTime = _SetDlgTime; @@ -193,12 +151,16 @@ fv->Destroy(fv); } - if (fv->FileOpen) CloseHandle(fv->FileHandle); + if (fv->FileOpen) { + fv->Close(fv); + fv->FileOpen = FALSE; + } if (fv->FnStrMemHandle != 0) { GlobalUnlock(fv->FnStrMemHandle); GlobalFree(fv->FnStrMemHandle); } + fv->FileSysDestroy(fv); free(fv); *pfv = NULL; Modified: trunk/teraterm/teraterm/filesys_proto.h =================================================================== --- trunk/teraterm/teraterm/filesys_proto.h 2020-12-20 12:10:57 UTC (rev 9076) +++ trunk/teraterm/teraterm/filesys_proto.h 2020-12-20 12:11:08 UTC (rev 9077) @@ -43,7 +43,6 @@ int FnPtr; BOOL FileOpen; - HANDLE FileHandle; LONG FileSize, ByteCount; BOOL OverWrite; @@ -69,10 +68,15 @@ void *data; // file I/O + BOOL (*OpenRead)(struct FileVarProto *fv, const char *filenameU8); + BOOL (*OpenWrite)(struct FileVarProto *fv, const char *filenameU8); size_t (*ReadFile)(struct FileVarProto *fv, void *buf, size_t bytes); size_t (*WriteFile)(struct FileVarProto *fv, const void *buf, size_t bytes); void (*Close)(struct FileVarProto *fv); size_t (*GetFSize)(struct FileVarProto *fv, const char *filenameU8); + int (*Seek)(struct FileVarProto *fv, size_t offset); + void (*FileSysDestroy)(struct FileVarProto *fv); + HANDLE FileHandle; // UI void (*InitDlgProgress)(struct FileVarProto *fv, int *CurProgStat); Modified: trunk/teraterm/teraterm/ttermpro.v16.vcxproj =================================================================== --- trunk/teraterm/teraterm/ttermpro.v16.vcxproj 2020-12-20 12:10:57 UTC (rev 9076) +++ trunk/teraterm/teraterm/ttermpro.v16.vcxproj 2020-12-20 12:11:08 UTC (rev 9077) @@ -138,6 +138,7 @@ <ClCompile Include="..\common\ttlib.c" /> <ClCompile Include="..\susie_plugin\libsusieplugin.cpp" /> <ClCompile Include="..\ttpfile\bplus.c" /> + <ClCompile Include="..\ttpfile\filesys_win32.cpp" /> <ClCompile Include="..\ttpfile\ftlib.c" /> <ClCompile Include="..\ttpfile\kermit.c" /> <ClCompile Include="..\ttpfile\quickvan.c" /> @@ -187,6 +188,7 @@ <ClInclude Include="../ttpdlg/ttdlg.h" /> <ClInclude Include="..\susie_plugin\libsusieplugin.h" /> <ClInclude Include="..\ttpfile\bplus.h" /> + <ClInclude Include="..\ttpfile\filesys_win32.h" /> <ClInclude Include="..\ttpfile\file_res.h" /> <ClInclude Include="..\ttpfile\ftlib.h" /> <ClInclude Include="..\ttpfile\kermit.h" /> Modified: trunk/teraterm/teraterm/ttermpro.v16.vcxproj.filters =================================================================== --- trunk/teraterm/teraterm/ttermpro.v16.vcxproj.filters 2020-12-20 12:10:57 UTC (rev 9076) +++ trunk/teraterm/teraterm/ttermpro.v16.vcxproj.filters 2020-12-20 12:11:08 UTC (rev 9077) @@ -22,6 +22,9 @@ <Filter Include="ttpdlg"> <UniqueIdentifier>{1cdaec4a-75c1-4600-b434-45286f5bec80}</UniqueIdentifier> </Filter> + <Filter Include="ffpfile"> + <UniqueIdentifier>{0494dec4-73a6-4271-9dfa-ad4b61e2b62c}</UniqueIdentifier> + </Filter> </ItemGroup> <ItemGroup> <ClCompile Include="filesys.cpp"> @@ -153,6 +156,36 @@ <ClCompile Include="checkeol.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="..\ttpfile\bplus.c"> + <Filter>ffpfile</Filter> + </ClCompile> + <ClCompile Include="..\ttpfile\ftlib.c"> + <Filter>ffpfile</Filter> + </ClCompile> + <ClCompile Include="..\ttpfile\kermit.c"> + <Filter>ffpfile</Filter> + </ClCompile> + <ClCompile Include="..\ttpfile\quickvan.c"> + <Filter>ffpfile</Filter> + </ClCompile> + <ClCompile Include="..\ttpfile\ttfile_proto.cpp"> + <Filter>ffpfile</Filter> + </ClCompile> + <ClCompile Include="..\ttpfile\xmodem.c"> + <Filter>ffpfile</Filter> + </ClCompile> + <ClCompile Include="..\ttpfile\ymodem.c"> + <Filter>ffpfile</Filter> + </ClCompile> + <ClCompile Include="..\ttpfile\zmodem.c"> + <Filter>ffpfile</Filter> + </ClCompile> + <ClCompile Include="filesys_proto.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="..\ttpfile\filesys_win32.cpp"> + <Filter>ffpfile</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <Image Include="..\..\cygterm\cygterm.ico"> @@ -387,5 +420,35 @@ <ClInclude Include="checkeol.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="..\ttpfile\bplus.h"> + <Filter>ffpfile</Filter> + </ClInclude> + <ClInclude Include="..\ttpfile\ftlib.h"> + <Filter>ffpfile</Filter> + </ClInclude> + <ClInclude Include="..\ttpfile\kermit.h"> + <Filter>ffpfile</Filter> + </ClInclude> + <ClInclude Include="..\ttpfile\quickvan.h"> + <Filter>ffpfile</Filter> + </ClInclude> + <ClInclude Include="..\ttpfile\ttfile_proto.h"> + <Filter>ffpfile</Filter> + </ClInclude> + <ClInclude Include="..\ttpfile\xmodem.h"> + <Filter>ffpfile</Filter> + </ClInclude> + <ClInclude Include="..\ttpfile\ymodem.h"> + <Filter>ffpfile</Filter> + </ClInclude> + <ClInclude Include="..\ttpfile\zmodem.h"> + <Filter>ffpfile</Filter> + </ClInclude> + <ClInclude Include="..\ttpfile\file_res.h"> + <Filter>ffpfile</Filter> + </ClInclude> + <ClInclude Include="..\ttpfile\filesys_win32.h"> + <Filter>ffpfile</Filter> + </ClInclude> </ItemGroup> </Project> \ No newline at end of file Modified: trunk/teraterm/teraterm/ttermpro.v8.vcproj =================================================================== --- trunk/teraterm/teraterm/ttermpro.v8.vcproj 2020-12-20 12:10:57 UTC (rev 9076) +++ trunk/teraterm/teraterm/ttermpro.v8.vcproj 2020-12-20 12:11:08 UTC (rev 9077) @@ -711,6 +711,14 @@ > </File> <File + RelativePath="..\ttpfile\filesys_win32.cpp" + > + </File> + <File + RelativePath="..\ttpfile\filesys_win32.h" + > + </File> + <File RelativePath="..\ttpfile\ftlib.c" > </File> Modified: trunk/teraterm/ttpfile/bplus.c =================================================================== --- trunk/teraterm/ttpfile/bplus.c 2020-12-20 12:10:57 UTC (rev 9076) +++ trunk/teraterm/ttpfile/bplus.c 2020-12-20 12:11:08 UTC (rev 9077) @@ -38,7 +38,6 @@ #include "ftlib.h" #include "ttcommon.h" #include "ttlib.h" -#include "win16api.h" #include "bplus.h" @@ -102,15 +101,16 @@ BOOL BPOpenFileToBeSent(PFileVarProto fv) { + BOOL r; + if (fv->FileOpen) return TRUE; if (strlen(&(fv->FullName[fv->DirLen]))==0) return FALSE; - fv->FileHandle = _lopen(fv->FullName,OF_READ); - fv->FileOpen = fv->FileHandle != INVALID_HANDLE_VALUE; - if (fv->FileOpen) - { + r = fv->OpenRead(fv, fv->FullName); + fv->FileOpen = r; + if (r == TRUE) { SetDlgItemText(fv->HWin, IDC_PROTOFNAME, &(fv->FullName[fv->DirLen])); - fv->FileSize = GetFSize(fv->FullName); + fv->FileSize = fv->GetFSize(fv, fv->FullName); } return fv->FileOpen; } @@ -508,7 +508,7 @@ c = 1; while ((i-4 < bv->PktSize-1) && (c>0)) { - c = _lread(fv->FileHandle,&b,1); + c = fv->ReadFile(fv, &b, 1); if (c==1) BPPut1Byte(bv,b,&i); fv->ByteCount = fv->ByteCount + c; @@ -515,7 +515,7 @@ } if (c==0) { - _lclose(fv->FileHandle); + fv->Close(fv); fv->FileOpen = FALSE; } i = i - 4; @@ -581,7 +581,7 @@ case 'C': /* Close */ if (fv->FileOpen) { - _lclose(fv->FileHandle); + fv->Close(fv); fv->FileOpen = FALSE; } fv->Success = TRUE; @@ -717,7 +717,7 @@ BPSendFailure(bv,'E'); return; } - _lwrite(fv->FileHandle,&(bv->PktIn[2]),bv->PktInCount-2); + fv->WriteFile(fv, &(bv->PktIn[2]), bv->PktInCount-2); fv->ByteCount = fv->ByteCount + bv->PktInCount - 2; SetDlgNum(fv->HWin, IDC_PROTOBYTECOUNT, fv->ByteCount); Added: trunk/teraterm/ttpfile/filesys_win32.cpp =================================================================== --- trunk/teraterm/ttpfile/filesys_win32.cpp (rev 0) +++ trunk/teraterm/ttpfile/filesys_win32.cpp 2020-12-20 12:11:08 UTC (rev 9077) @@ -0,0 +1,133 @@ +/* + * (C) 2020 TeraTerm Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <windows.h> +#include "tttypes.h" +#include "codeconv.h" + +#include "filesys_win32.h" + +static BOOL _OpenRead(TFileVarProto *fv, const char *filename) +{ + HANDLE hFile = CreateFileA(filename, + GENERIC_READ, FILE_SHARE_READ, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (hFile == INVALID_HANDLE_VALUE) { + fv->FileHandle = INVALID_HANDLE_VALUE; + return FALSE; + } + fv->FileHandle = hFile; + return TRUE; +} + +static BOOL _OpenWrite(TFileVarProto *fv, const char *filename) +{ + HANDLE hFile = CreateFileA(filename, + GENERIC_WRITE, FILE_SHARE_WRITE, NULL, + CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if (hFile == INVALID_HANDLE_VALUE) { + fv->FileHandle = INVALID_HANDLE_VALUE; + return FALSE; + } + fv->FileHandle = hFile; + return TRUE; +} + +static size_t _ReadFile(TFileVarProto *fv, void *buf, size_t bytes) +{ + HANDLE hFile = fv->FileHandle; + DWORD NumberOfBytesRead; + BOOL Result = ReadFile(hFile, buf, (UINT)bytes, &NumberOfBytesRead, NULL); + if (Result == FALSE) { + return 0; + } + return NumberOfBytesRead; +} + +static size_t _WriteFile(TFileVarProto *fv, const void *buf, size_t bytes) +{ + HANDLE hFile = fv->FileHandle; + DWORD NumberOfBytesWritten; + UINT length = (UINT)bytes; + BOOL result = WriteFile(hFile, buf, length, &NumberOfBytesWritten, NULL); + if (result == FALSE) { + return 0; + } + return NumberOfBytesWritten; +} + +static void _Close(TFileVarProto *fv) +{ + if (fv->FileHandle != INVALID_HANDLE_VALUE) { + CloseHandle(fv->FileHandle); + fv->FileHandle = INVALID_HANDLE_VALUE; + } +} + +/** + * \x83t\x83@\x83C\x83\x8B\x82̃t\x83@\x83C\x83\x8B\x83T\x83C\x83Y\x82\xF0\x8E擾 + * @param[in] filenameU8 \x83t\x83@\x83C\x83\x8B\x96\xBC(UTF-8) + * @retval \x83t\x83@\x83C\x83\x8B\x83T\x83C\x83Y + */ +static size_t _GetFSize(struct FileVarProto *fv, const char *filenameU8) +{ + size_t file_size = GetFSize64W(wc::fromUtf8(filenameU8)); + return file_size; +} + +/** + * @retval 0 ok + * @retval -1 error + */ +static int Seek(struct FileVarProto *fv, size_t offset) +{ + LONG lo = (LONG)((offset >> 0) & 0xffffffff); + LONG hi = (LONG)((offset >> 32) & 0xffffffff); + DWORD pos = SetFilePointer(fv->FileHandle, lo, &hi, 0); + if (GetLastError() != 0) { + return -1; + } + return 0; +} + +static void FileSysDestroy(TFileVarProto *fv) +{ + fv->Close(fv); +} + +void FilesysCreate(TFileVarProto *fv) +{ + fv->OpenRead = _OpenRead; + fv->OpenWrite = _OpenWrite; + fv->ReadFile = _ReadFile; + fv->WriteFile = _WriteFile; + fv->Close = _Close; + fv->GetFSize = _GetFSize; + fv->Seek = Seek; + fv->FileSysDestroy = FileSysDestroy; +} Added: trunk/teraterm/ttpfile/filesys_win32.h =================================================================== --- trunk/teraterm/ttpfile/filesys_win32.h (rev 0) +++ trunk/teraterm/ttpfile/filesys_win32.h 2020-12-20 12:11:08 UTC (rev 9077) @@ -0,0 +1,34 @@ +/* + * (C) 2020 TeraTerm Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once +#include <windows.h> +#include "tttypes.h" +#include "filesys_proto.h" + +void FilesysCreate(TFileVarProto *fv); Modified: trunk/teraterm/ttpfile/ftlib.c =================================================================== --- trunk/teraterm/ttpfile/ftlib.c 2020-12-20 12:10:57 UTC (rev 9076) +++ trunk/teraterm/ttpfile/ftlib.c 2020-12-20 12:11:08 UTC (rev 9077) @@ -35,7 +35,6 @@ #include "ttlib.h" #include <stdio.h> #include <string.h> -#include "win16api.h" #include "ftlib.h" #include "tt_res.h" @@ -151,8 +150,7 @@ } strncpy_s(fv->FullName, sizeof(fv->FullName),Temp, _TRUNCATE); } - fv->FileHandle = _lcreat(fv->FullName,0); - fv->FileOpen = (fv->FileHandle != INVALID_HANDLE_VALUE); + fv->FileOpen = fv->OpenWrite(fv, fv->FullName); if (! fv->FileOpen && ! fv->NoMsg) MessageBox(fv->HMainWin,"Cannot create file", "Tera Term: Error",MB_ICONEXCLAMATION); @@ -175,7 +173,9 @@ static BOOL Open(TProtoLog *pv, const char *file) { - pv->LogFile = _lcreat(file, 0); + pv->LogFile = CreateFileA(file, + GENERIC_WRITE, FILE_SHARE_WRITE, NULL, + CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); pv->LogCount = 0; pv->LogState = 0; return pv->LogFile == INVALID_HANDLE_VALUE ? FALSE : TRUE; @@ -194,8 +194,12 @@ static size_t WriteRawData(struct ProtoLog *pv, const void *data, size_t len) { - size_t r = _lwrite(pv->LogFile, data, len); - return r; + DWORD NumberOfBytesWritten; + BOOL result = WriteFile(pv->LogFile, data, len, &NumberOfBytesWritten, NULL); + if (result == FALSE) { + return 0; + } + return NumberOfBytesWritten; } static size_t WriteStr(TProtoLog *pv, const char *str) @@ -224,7 +228,7 @@ d[1] = (b & 0x0F) + 0x37; d[2] = 0x20; - _lwrite(pv->LogFile,d,3); + pv->WriteRaw(pv,d,3); pv->LogLineBuf[pv->LogCount] = b; // add (2008.6.3 yutaka) pv->LogCount++; } @@ -235,18 +239,18 @@ int i; for (i = 0 ; i < rest ; i++) - _lwrite(pv->LogFile," ", 3); + pv->WriteRaw(pv," ", 3); // ASCII\x95\\x8E\xA6\x82\xF0\x92lj\xC1 (2008.6.3 yutaka) - _lwrite(pv->LogFile," ", 4); + pv->WriteRaw(pv," ", 4); for (i = 0 ; i < pv->LogCount ; i++) { char ch[5]; if (isprint(pv->LogLineBuf[i])) { _snprintf_s(ch, sizeof(ch), _TRUNCATE, "%c", pv->LogLineBuf[i]); - _lwrite(pv->LogFile, ch, 1); + pv->WriteRaw(pv, ch, 1); } else { - _lwrite(pv->LogFile, ".", 1); + pv->WriteRaw(pv, ".", 1); } @@ -253,7 +257,7 @@ } pv->LogCount = 0; - _lwrite(pv->LogFile,"\015\012",2); + pv->WriteRaw(pv,"\015\012",2); } static void ProtoLogDestroy(TProtoLog *pv) Modified: trunk/teraterm/ttpfile/kermit.c =================================================================== --- trunk/teraterm/ttpfile/kermit.c 2020-12-20 12:10:57 UTC (rev 9076) +++ trunk/teraterm/ttpfile/kermit.c 2020-12-20 12:11:08 UTC (rev 9077) @@ -42,7 +42,6 @@ #include "ttlib.h" #include "dlglib.h" #include "ftlib.h" -#include "win16api.h" #include "kermit.h" @@ -705,7 +704,7 @@ for (j = 1 ; j <= kv->RepeatCount ; j++) { if (Buff==NULL) /* write to file */ - _lwrite(fv->FileHandle,&b,1); + fv->WriteFile(fv,&b,1); else /* write to buffer */ if (BuffPtr < *BuffLen) { @@ -887,7 +886,7 @@ b = kv->NextByte; kv->NextByteFlag = FALSE; } - else if (_lread(fv->FileHandle,&b,1)==0) + else if (fv->ReadFile(fv,&b,1)==0) return FALSE; else fv->ByteCount++; @@ -924,7 +923,7 @@ TempStr[Len] = 0; kv->RepeatCount = 1; - if (_lread(fv->FileHandle,&(kv->NextByte),1)==1) + if (fv->ReadFile(fv,&(kv->NextByte),1)==1) { fv->ByteCount++; kv->NextByteFlag = TRUE; @@ -934,7 +933,7 @@ (kv->NextByte==b) && (kv->RepeatCount<94)) { kv->RepeatCount++; - if (_lread(fv->FileHandle,&(kv->NextByte),1)==0) + if (fv->ReadFile(fv,&(kv->NextByte),1)==0) kv->NextByteFlag = FALSE; else fv->ByteCount++; } @@ -965,7 +964,7 @@ { /* close file */ if (fv->FileOpen) - _lclose(fv->FileHandle); + fv->Close(fv); fv->FileOpen = FALSE; KmtIncPacketNum(kv); @@ -1046,6 +1045,7 @@ { char uimsg[MAX_UIMSG], uimsg2[MAX_UIMSG]; struct _stati64 st; + BOOL r; if (! GetNextFname(fv)) { @@ -1064,8 +1064,8 @@ } /* file open */ - fv->FileHandle = _lopen(fv->FullName,OF_READ); - fv->FileOpen = fv->FileHandle != INVALID_HANDLE_VALUE; + r = fv->OpenRead(fv, fv->FullName); + fv->FileOpen = r; if (! fv->FileOpen) { if (! fv->NoMsg) @@ -1077,7 +1077,7 @@ return FALSE; } else - fv->FileSize = GetFSize(fv->FullName); + fv->FileSize = fv->GetFSize(fv, fv->FullName); fv->ByteCount = 0; fv->ProgStat = 0; @@ -1574,7 +1574,7 @@ case 'Z': if (kv->KmtState == ReceiveData) { - if (fv->FileOpen) _lclose(fv->FileHandle); + if (fv->FileOpen) fv->Close(fv); fv->FileOpen = FALSE; kv->KmtState = ReceiveFile; Modified: trunk/teraterm/ttpfile/quickvan.c =================================================================== --- trunk/teraterm/ttpfile/quickvan.c 2020-12-20 12:10:57 UTC (rev 9076) +++ trunk/teraterm/ttpfile/quickvan.c 2020-12-20 12:11:08 UTC (rev 9077) @@ -42,7 +42,6 @@ #include "ftlib.h" #include "ttlib.h" #include "ttcommon.h" -#include "win16api.h" #include "quickvan.h" @@ -505,7 +504,7 @@ { if (fv->FileOpen) { - _lclose(fv->FileHandle); + fv->Close(fv); fv->FileOpen = FALSE; /* set file date & time */ if ((qv->Year >= 1900) && (qv->Hour < 24)) @@ -550,7 +549,7 @@ C = fv->FileSize - fv->ByteCount; else C = 128; - _lwrite(fv->FileHandle,&(qv->PktIn[3]),C); + fv->WriteFile(fv,&(qv->PktIn[3]),C); fv->ByteCount = fv->ByteCount + C; SetDlgNum(fv->HWin, IDC_PROTOPKTNUM, qv->SeqNum); @@ -838,6 +837,7 @@ struct stat stbuf; struct tm tmbuf; char fullname_upper[MAX_PATH]; + BOOL r; if (! GetNextFname(fv)) { @@ -846,7 +846,7 @@ } /* find file and get file info */ - fv->FileSize = GetFSize(fv->FullName); + fv->FileSize = fv->GetFSize(fv, fv->FullName); if (fv->FileSize>0) { qv->FileEnd = (WORD)(fv->FileSize >> 7); @@ -859,8 +859,8 @@ } /* file open */ - fv->FileHandle = _lopen(fv->FullName,OF_READ); - fv->FileOpen = fv->FileHandle != INVALID_HANDLE_VALUE; + r = fv->OpenRead(fv, fv->FullName); + fv->FileOpen = r; if (! fv->FileOpen) { QVCancel(fv,cv); @@ -931,8 +931,8 @@ else C = 128; /* read data from file */ - _llseek(fv->FileHandle,Pos,0); - _lread(fv->FileHandle,&(qv->PktOut[3]),C); + fv->Seek(fv, Pos); + fv->ReadFile(fv,&(qv->PktOut[3]),C); fv->ByteCount = Pos + (LONG)C; SetDlgNum(fv->HWin, IDC_PROTOPKTNUM, qv->SeqSent); SetDlgNum(fv->HWin, IDC_PROTOBYTECOUNT, fv->ByteCount); @@ -1104,7 +1104,7 @@ if (qv->EnqFlag && (qv->PktIn[3]==0x30)) { if (fv->FileOpen) - _lclose(fv->FileHandle); + fv->Close(fv); fv->FileOpen = FALSE; qv->EnqFlag = FALSE; qv->RetryCount = 10; Modified: trunk/teraterm/ttpfile/xmodem.c =================================================================== --- trunk/teraterm/ttpfile/xmodem.c 2020-12-20 12:10:57 UTC (rev 9076) +++ trunk/teraterm/ttpfile/xmodem.c 2020-12-20 12:11:08 UTC (rev 9077) @@ -35,7 +35,6 @@ #include "ttcommon.h" #include "ttlib.h" #include "ftlib.h" -#include "win16api.h" #include "xmodem.h" @@ -229,16 +228,15 @@ fv->FileSize = 0; if (xv->XMode == IdXSend) { - fv->FileHandle = _lopen(fv->FullName,OF_READ); - if (fv->FileHandle == INVALID_HANDLE_VALUE) { + fv->FileOpen = fv->OpenRead(fv, fv->FullName); + if (fv->FileOpen == FALSE) { return FALSE; } - fv->FileOpen = TRUE; fv->FileSize = fv->GetFSize(fv, fv->FullName); fv->InitDlgProgress(fv, &fv->ProgStat); } else { - fv->FileHandle = _lcreat(fv->FullName,0); - if (fv->FileHandle == INVALID_HANDLE_VALUE) { + fv->FileOpen = fv->OpenWrite(fv, fv->FullName); + if (fv->FileOpen == FALSE) { return FALSE; } fv->ProgStat = -1; @@ -574,7 +572,6 @@ } else { /* send EOT */ if (fv->FileOpen) { fv->Close(fv); - fv->FileHandle = 0; fv->FileOpen = FALSE; } xv->PktOut[0] = EOT; Modified: trunk/teraterm/ttpfile/ymodem.c =================================================================== --- trunk/teraterm/ttpfile/ymodem.c 2020-12-20 12:10:57 UTC (rev 9076) +++ trunk/teraterm/ttpfile/ymodem.c 2020-12-20 12:11:08 UTC (rev 9077) @@ -36,7 +36,6 @@ #include "teraterm.h" #include "tttypes.h" #include "ttftypes.h" -#include "win16api.h" #include "tt_res.h" #include "ttcommon.h" @@ -296,21 +295,20 @@ { if (yv->YMode == IdYSend) { if (fv->FileOpen) { - _lclose(fv->FileHandle); + fv->Close(fv); if (fv->FileMtime > 0) { SetFMtime(fv->FullName, fv->FileMtime); } } - fv->FileHandle = _lopen(fv->FullName,OF_READ); - fv->FileSize = GetFSize(fv->FullName); + fv->FileOpen = fv->OpenRead(fv, fv->FullName); + fv->FileSize = fv->GetFSize(fv, fv->FullName); } else { - fv->FileHandle = INVALID_HANDLE_VALUE; + fv->FileOpen = FALSE; fv->FileSize = 0; fv->FileMtime = 0; yv->RecvFilesize = FALSE; } - fv->FileOpen = fv->FileHandle != INVALID_HANDLE_VALUE; if (yv->YMode == IdYSend) { InitDlgProgress(fv->HWin, IDC_PROTOPROGRESS, &fv->ProgStat); @@ -491,9 +489,8 @@ { // EOT\x82\xAA\x97\x88\x82\xBD\x82\xE7\x81A1\x82̃t\x83@\x83C\x83\x8B\x8E\xF3\x90M\x82\xAA\x8A\xAE\x97\xB9\x82\xB5\x82\xBD\x82\xB1\x82Ƃ\xF0\x8E\xA6\x82\xB7\x81B if (fv->FileOpen) { - fv->FileOpen = 0; - _lclose(fv->FileHandle); - fv->FileHandle = INVALID_HANDLE_VALUE; + fv->Close(fv); + fv->FileOpen = FALSE; if (fv->FileMtime > 0) { SetFMtime(fv->FullName, fv->FileMtime); @@ -674,14 +671,14 @@ { b = yv->PktIn[3+i]; if ((b==LF) && (! yv->CRRecv)) - _lwrite(fv->FileHandle,"\015",1); + fv->WriteFile(fv,"\015",1); if (yv->CRRecv && (b!=LF)) - _lwrite(fv->FileHandle,"\012",1); + fv->WriteFile(fv,"\012",1); yv->CRRecv = b==CR; - _lwrite(fv->FileHandle,&b,1); + fv->WriteFile(fv,&b,1); } else - _lwrite(fv->FileHandle, &(yv->PktIn[3]), c); + fv->WriteFile(fv, &(yv->PktIn[3]), c); fv->ByteCount = fv->ByteCount + c; @@ -959,7 +956,7 @@ yv->__DataLen = current_packet_size; while ((idx <= current_packet_size) && fv->FileOpen && - (1 == _lread(fv->FileHandle, &fsym, 1))) + (1 == fv->ReadFile(fv, &fsym, 1))) { // TODO: remove magic number. yv->PktOut[2 + idx] = fsym; @@ -973,8 +970,7 @@ // Close file handle. if (fv->FileOpen) { - _lclose(fv->FileHandle); - fv->FileHandle = 0; + fv->Close(fv); fv->FileOpen = FALSE; } Modified: trunk/teraterm/ttpfile/zmodem.c =================================================================== --- trunk/teraterm/ttpfile/zmodem.c 2020-12-20 12:10:57 UTC (rev 9076) +++ trunk/teraterm/ttpfile/zmodem.c 2020-12-20 12:11:08 UTC (rev 9077) @@ -58,7 +58,6 @@ #include "ftlib.h" #include "ttcommon.h" #include "ttlib.h" -#include "win16api.h" #include "zmodem.h" @@ -579,7 +578,7 @@ ZPutBin(zv, &(zv->PktOutCount), 0); zv->CRC = UpdateCRC(0, zv->CRC); /* file size */ - fv->FileSize = GetFSize(fv->FullName); + fv->FileSize = fv->GetFSize(fv, fv->FullName); /* timestamp */ fv->FileMtime = GetFMtime(fv->FullName); @@ -645,12 +644,12 @@ fv->ByteCount = zv->Pos; if (fv->FileOpen && (zv->Pos < fv->FileSize)) - _llseek(fv->FileHandle, zv->Pos, 0); + fv->Seek(fv, zv->Pos); zv->CRC = 0; zv->PktOutCount = 0; do { - c = _lread(fv->FileHandle, &b, 1); + c = fv->ReadFile(fv, &b, 1); if (c > 0) { ZPutBin(zv, &(zv->PktOutCount), b); zv->CRC = UpdateCRC(b, zv->CRC); @@ -873,7 +872,7 @@ if (fv->FileOpen) // close previous file { - _lclose(fv->FileHandle); + fv->Close(fv); fv->FileOpen = FALSE; if (fv->FileMtime > 0) { @@ -888,8 +887,7 @@ } /* file open */ - fv->FileHandle = _lopen(fv->FullName, OF_READ); - fv->FileOpen = fv->FileHandle != INVALID_HANDLE_VALUE; + fv->FileOpen = fv->OpenRead(fv, fv->FullName); if (zv->CtlEsc) { if ((zv->RxHdr[ZF0] & ESCCTL) == 0) { @@ -961,7 +959,7 @@ break; case ZSKIP: if (fv->FileOpen) { - _lclose(fv->FileHandle); + fv->Close(fv); // \x83T\x81[\x83o\x91\xA4\x82ɑ\xB6\x8D݂\xB7\x82\xE9\x83t\x83@\x83C\x83\x8B\x82𑗐M\x82\xB5\x82悤\x82Ƃ\xB7\x82\xE9\x82ƁAZParseRInit()\x82œ\xF1\x8Fdclose\x82ɂȂ邽\x82߁A // \x82\xB1\x82\xB1\x82Ńt\x83\x89\x83O\x82𗎂Ƃ\xB5\x82Ă\xA8\x82\xAD\x81B (2007.12.20 yutaka) fv->FileOpen = FALSE; @@ -1034,9 +1032,9 @@ if (fv->FileOpen) { if (zv->CRRecv) { zv->CRRecv = FALSE; - _lwrite(fv->FileHandle, "\012", 1); + fv->WriteFile(fv, "\012", 1); } - _lclose(fv->FileHandle); + fv->Close(fv); fv->FileOpen = FALSE; if (fv->FileMtime > 0) { @@ -1126,16 +1124,16 @@ FTSetTimeOut(fv, 0); if (zv->BinFlag) - _lwrite(fv->FileHandle, zv->PktIn, zv->PktInPtr); + fv->WriteFile(fv, zv->PktIn, zv->PktInPtr); else for (i = 0; i <= zv->PktInPtr - 1; i++) { b = zv->PktIn[i]; if ((b == 0x0A) && (!zv->CRRecv)) - _lwrite(fv->FileHandle, "\015", 1); + fv->WriteFile(fv, "\015", 1); if (zv->CRRecv && (b != 0x0A)) - _lwrite(fv->FileHandle, "\012", 1); + fv->WriteFile(fv, "\012", 1); zv->CRRecv = b == 0x0D; - _lwrite(fv->FileHandle, &b, 1); + fv->WriteFile(fv, &b, 1); } fv->ByteCount = fv->ByteCount + zv->PktInPtr;