Revision: 8612 https://osdn.net/projects/ttssh2/scm/svn/commits/8612 Author: zmatsuo Date: 2020-03-22 01:00:07 +0900 (Sun, 22 Mar 2020) Log Message: ----------- Windows 9x で、LoadFileWW() が使用できるよう修正 - LoadFileWW()は引数のファイル名がUnicode - ファイルオープンに _wfopen() を使用していた - _wfopen() はおそらく内部で CreateFileW() を使用している - 9x ではおそらく CreateFileW() は常に失敗する - このためファイルが読み込めなかった - _wfopen_s(), _fopen_s() を使用するよう変更 - 9x の場合、_wfopen_s() を使用しないようにした - 念の為、_wfopen_s() に失敗したとき _fopen_s() を使用するようにした - sendmem.cpp - ファイルオープンに失敗したとき assert() - 不要なincludeを削除 Modified Paths: -------------- trunk/teraterm/common/fileread.cpp trunk/teraterm/teraterm/sendmem.cpp -------------- next part -------------- Modified: trunk/teraterm/common/fileread.cpp =================================================================== --- trunk/teraterm/common/fileread.cpp 2020-03-21 15:59:50 UTC (rev 8611) +++ trunk/teraterm/common/fileread.cpp 2020-03-21 16:00:07 UTC (rev 8612) @@ -37,6 +37,8 @@ #include <crtdbg.h> #include "codeconv.h" +#include "ttlib.h" + #include "fileread.h" #if defined(_MSC_VER) && (_MSC_VER < 1600) @@ -43,6 +45,25 @@ typedef unsigned char uint8_t; #endif +static void __wfopen_s(FILE **fp, wchar_t const* filename, wchar_t const* mode) +{ + if (IsWindowsNTKernel()) { + // \x91\xBD\x95\xAA\x93\xE0\x95\x94\x82\xC5 CreateFileW() \x82\xF0\x8Eg\x97p\x82\xB5\x82Ă\xA2\x82\xE9 + // NT\x82ł̂ݎg\x97p\x82\xB7\x82\xE9 + _wfopen_s(fp, filename, mode); + if (fp != NULL) { + return; + } + // \x94O\x82̈\xD7 ANSI \x82ł\xE0\x83I\x81[\x83v\x83\x93\x82\xB7\x82\xE9 + } + // ANSI \x82ŃI\x81[\x83v\x83\x93 + char *filenameA = ToCharW(filename); + char *modeA = ToCharW(mode); + fopen_s(fp, filenameA, modeA); + free(filenameA); + free(modeA); +} + /** * \x83t\x83@\x83C\x83\x8B\x82\xF0\x83\x81\x83\x82\x83\x8A\x82ɓǂݍ\x9E\x82\xDE * @param[out] *_len \x83T\x83C\x83Y(terminater\x8A܂\xDE) @@ -97,7 +118,7 @@ uint8_t *LoadFileBinary(const wchar_t *FileName, size_t *_len) { FILE *fp; - _wfopen_s(&fp, FileName, L"rb"); + __wfopen_s(&fp, FileName, L"rb"); if (fp == NULL) { return NULL; } @@ -186,7 +207,8 @@ char *LoadFileU8A(const char *FileName, size_t *_len) { *_len = 0; - FILE *fp = fopen(FileName, "rb"); + FILE *fp; + fopen_s(&fp, FileName, "rb"); if (fp == NULL) { return NULL; } @@ -214,7 +236,8 @@ if (_len != NULL) { *_len = 0; } - FILE *fp = fopen(FileName, "rb"); + FILE *fp; + fopen_s(&fp, FileName, "rb"); if (fp == NULL) { return NULL; } @@ -248,7 +271,8 @@ if (_len != NULL) { *_len = 0; } - FILE *fp = _wfopen(FileName, L"rb"); + FILE *fp; + __wfopen_s(&fp, FileName, L"rb"); if (fp == NULL) { return NULL; } Modified: trunk/teraterm/teraterm/sendmem.cpp =================================================================== --- trunk/teraterm/teraterm/sendmem.cpp 2020-03-21 15:59:50 UTC (rev 8611) +++ trunk/teraterm/teraterm/sendmem.cpp 2020-03-21 16:00:07 UTC (rev 8612) @@ -31,8 +31,7 @@ #include <stdlib.h> #define _CRTDBG_MAP_ALLOC #include <crtdbg.h> -#include <sys/types.h> -#include <sys/stat.h> +#include <assert.h> #include "tttypes.h" #include "ttcommon.h" @@ -617,6 +616,7 @@ if (!binary) { size_t str_len; wchar_t *str_ptr = LoadFileWW(filename, &str_len); + assert(str_ptr != NULL); if (str_ptr == NULL) { return FALSE; } @@ -625,6 +625,7 @@ else { size_t data_len; unsigned char *data_ptr = LoadFileBinary(filename, &data_len); + assert(data_ptr != NULL); if (data_ptr == NULL) { return FALSE; }