Revision: 8862 https://osdn.net/projects/ttssh2/scm/svn/commits/8862 Author: zmatsuo Date: 2020-07-26 01:00:46 +0900 (Sun, 26 Jul 2020) Log Message: ----------- 9x上でも動作する _wfopen() 互換関数追加 - _wfopen() でエラーが出た時 fopen() でリトライする Modified Paths: -------------- trunk/teraterm/common/CMakeLists.txt trunk/teraterm/common/common_static.v16.vcxproj trunk/teraterm/common/common_static.v8.vcproj Added Paths: ----------- trunk/teraterm/common/layer_for_unicode_crt.cpp trunk/teraterm/common/layer_for_unicode_crt.h -------------- next part -------------- Modified: trunk/teraterm/common/CMakeLists.txt =================================================================== --- trunk/teraterm/common/CMakeLists.txt 2020-07-25 16:00:36 UTC (rev 8861) +++ trunk/teraterm/common/CMakeLists.txt 2020-07-25 16:00:46 UTC (rev 8862) @@ -24,6 +24,8 @@ layer_for_unicode.cpp layer_for_unicode.h layer_for_unicode_comctl32.cpp + layer_for_unicode_crt.h + layer_for_unicode_crt.cpp tipwin.cpp tipwin.h tmfc.cpp Modified: trunk/teraterm/common/common_static.v16.vcxproj =================================================================== --- trunk/teraterm/common/common_static.v16.vcxproj 2020-07-25 16:00:36 UTC (rev 8861) +++ trunk/teraterm/common/common_static.v16.vcxproj 2020-07-25 16:00:46 UTC (rev 8862) @@ -136,6 +136,7 @@ <ClCompile Include="dlglib_cpp.cpp" /> <ClCompile Include="dlglib_tmpl.cpp" /> <ClCompile Include="fileread.cpp" /> + <ClCompile Include="layer_for_unicode_crt.cpp" /> <ClCompile Include="tipwin.cpp" /> <ClCompile Include="tmfc.cpp" /> <ClCompile Include="tmfc_frame.cpp" /> @@ -155,6 +156,7 @@ <ClInclude Include="asprintf.h" /> <ClInclude Include="dlglib.h" /> <ClInclude Include="fileread.h" /> + <ClInclude Include="layer_for_unicode_crt.h" /> <ClInclude Include="tipwin.h" /> <ClInclude Include="tmfc.h" /> <ClInclude Include="compat_win.h" /> Modified: trunk/teraterm/common/common_static.v8.vcproj =================================================================== --- trunk/teraterm/common/common_static.v8.vcproj 2020-07-25 16:00:36 UTC (rev 8861) +++ trunk/teraterm/common/common_static.v8.vcproj 2020-07-25 16:00:46 UTC (rev 8862) @@ -257,6 +257,14 @@ > </File> <File + RelativePath=".\layer_for_unicode_crt.cpp" + > + </File> + <File + RelativePath=".\layer_for_unicode_crt.h" + > + </File> + <File RelativePath=".\tipwin.cpp" > </File> Added: trunk/teraterm/common/layer_for_unicode_crt.cpp =================================================================== --- trunk/teraterm/common/layer_for_unicode_crt.cpp (rev 0) +++ trunk/teraterm/common/layer_for_unicode_crt.cpp 2020-07-25 16:00:46 UTC (rev 8862) @@ -0,0 +1,51 @@ +/* + * Copyright (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 <stdlib.h> + +#include "codeconv.h" + +#include "layer_for_unicode_crt.h" + +/** + * fopen \x82\xCC wchar_t, char \x97\xBC\x91Ή\x9E\x94\xC5 + * TODO __wfopen_s()#fileread.cpp \x82\xE0\x82\xB1\x82̃t\x83@\x83C\x83\x8B\x82Ɉړ\xAE\x82\xB7\x82\xE9 + */ +FILE *__wfopen(const wchar_t *fname, const wchar_t *mode) +{ + FILE *fp = _wfopen(fname, mode); + if (fp != NULL) { + return fp; + } + char *fnameA = ToCharW(fname); + char *modeA = ToCharW(mode); + fp = fopen(fnameA, modeA); + free(fnameA); + free(modeA); + return fp; +} Added: trunk/teraterm/common/layer_for_unicode_crt.h =================================================================== --- trunk/teraterm/common/layer_for_unicode_crt.h (rev 0) +++ trunk/teraterm/common/layer_for_unicode_crt.h 2020-07-25 16:00:46 UTC (rev 8862) @@ -0,0 +1,41 @@ +/* + * Copyright (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 <stdio.h> + +#ifdef __cplusplus +extern "C" { +#endif + +FILE *__wfopen(const wchar_t *fname, const wchar_t *mode); + +#ifdef __cplusplus +} +#endif