From 5a3e100f116a17967368feb5bf7696c84aab5b41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Czerpak?= Date: Fri, 27 Jun 2014 12:45:47 +0200 Subject: [PATCH] 2014-06-27 12:45 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * src/common/hbfopen.c * use _wfopen() instead of fopen() in MS-Windows UNICODE builds of hb_fopen(). It means that now hb_fopen() makes exactly the same file name conversions as hb_fs*() Harbour RTL functions, i.e. hb_fsOpen() * contrib/hbmxml/core.c ! fixed unnecessary conversions to UTF8 used for file names passed to hb_fopen() * contrib/hbmzip/3rd/minizip/ioapi.c * contrib/hbmzip/3rd/minizip/minizip.dif ! fixed wrongly used hb_fopen() instead of fopen() what caused double file name conversions when 32-bit stdio API was used. --- ChangeLog.txt | 15 +++++++++ contrib/hbmxml/core.c | 13 ++------ contrib/hbmzip/3rd/minizip/ioapi.c | 2 +- contrib/hbmzip/3rd/minizip/minizip.dif | 9 ------ src/common/hbfopen.c | 43 ++++++++++++++++++++++---- 5 files changed, 56 insertions(+), 26 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 117a10e81c..c9987aca55 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,21 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2014-06-27 12:45 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * src/common/hbfopen.c + * use _wfopen() instead of fopen() in MS-Windows UNICODE builds of + hb_fopen(). It means that now hb_fopen() makes exactly the same file + name conversions as hb_fs*() Harbour RTL functions, i.e. hb_fsOpen() + + * contrib/hbmxml/core.c + ! fixed unnecessary conversions to UTF8 used for file names passed + to hb_fopen() + + * contrib/hbmzip/3rd/minizip/ioapi.c + * contrib/hbmzip/3rd/minizip/minizip.dif + ! fixed wrongly used hb_fopen() instead of fopen() what caused double + file name conversions when 32-bit stdio API was used. + 2014-06-26 18:42 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * contrib/hbwin/olecore.c + added some additional error codes to win_oleErrorText() function diff --git a/contrib/hbmxml/core.c b/contrib/hbmxml/core.c index 56b85228d2..5d6a0338c9 100644 --- a/contrib/hbmxml/core.c +++ b/contrib/hbmxml/core.c @@ -736,7 +736,6 @@ static mxml_type_t type_cb( mxml_node_t * node ) HB_FUNC( MXMLLOADFILE ) { - void * hFree; mxml_node_t * node_top; mxml_node_t * node; mxml_load_cb_t cb = MXML_NO_CALLBACK; @@ -775,7 +774,7 @@ HB_FUNC( MXMLLOADFILE ) } } - file = hb_fopen( hb_parstr_utf8( 2, &hFree, NULL ), "rb" ); + file = hb_fopen( hb_parc( 2 ), "rb" ); if( file ) { node = mxmlLoadFile( node_top, file, cb ); @@ -786,7 +785,6 @@ HB_FUNC( MXMLLOADFILE ) } pCbs->type_cb = NULL; - hb_strfree( hFree ); } /* @@ -1135,7 +1133,6 @@ static void sax_cb( mxml_node_t * node, mxml_sax_event_t event, void * data ) HB_FUNC( MXMLSAXLOADFILE ) { - void * hFree; mxml_node_t * node_top; mxml_node_t * node; mxml_load_cb_t cb = MXML_NO_CALLBACK; @@ -1182,7 +1179,7 @@ HB_FUNC( MXMLSAXLOADFILE ) cb_sax = sax_cb; } - file = hb_fopen( hb_parstr_utf8( 2, &hFree, NULL ), "rb" ); + file = hb_fopen( hb_parc( 2 ), "rb" ); if( file ) { node = mxmlSAXLoadFile( node_top, file, cb, cb_sax, pData ); @@ -1194,8 +1191,6 @@ HB_FUNC( MXMLSAXLOADFILE ) pCbs->type_cb = NULL; pCbs->sax_cb = NULL; - - hb_strfree( hFree ); } /* @@ -1357,7 +1352,6 @@ HB_FUNC( MXMLSAVEFILE ) { mxml_node_t * node = mxml_node_param( 1 ); FILE * file; - void * hFree; if( node && HB_ISCHAR( 2 ) ) { @@ -1370,7 +1364,7 @@ HB_FUNC( MXMLSAVEFILE ) cb = save_cb; } - file = hb_fopen( hb_parstr_utf8( 2, &hFree, NULL ), "wb" ); + file = hb_fopen( hb_parc( 2 ), "wb" ); if( file ) { hb_retni( mxmlSaveFile( node, file, cb ) ); @@ -1383,7 +1377,6 @@ HB_FUNC( MXMLSAVEFILE ) hb_strfree( pCbs->hText ); pCbs->hText = NULL; } - hb_strfree( hFree ); } else MXML_ERR_ARGS; diff --git a/contrib/hbmzip/3rd/minizip/ioapi.c b/contrib/hbmzip/3rd/minizip/ioapi.c index ca6b6f9d46..b931473c08 100644 --- a/contrib/hbmzip/3rd/minizip/ioapi.c +++ b/contrib/hbmzip/3rd/minizip/ioapi.c @@ -110,7 +110,7 @@ static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, in mode_fopen = "wb"; if ((filename!=NULL) && (mode_fopen != NULL)) - file = hb_fopen(filename, mode_fopen); + file = fopen(filename, mode_fopen); return file; } diff --git a/contrib/hbmzip/3rd/minizip/minizip.dif b/contrib/hbmzip/3rd/minizip/minizip.dif index ff11c6f2ec..5dc939e080 100644 --- a/contrib/hbmzip/3rd/minizip/minizip.dif +++ b/contrib/hbmzip/3rd/minizip/minizip.dif @@ -31,15 +31,6 @@ diff -urN minizip.orig/ioapi.c minizip/ioapi.c if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) mode_fopen = "rb"; else -@@ -106,7 +110,7 @@ - mode_fopen = "wb"; - - if ((filename!=NULL) && (mode_fopen != NULL)) -- file = fopen(filename, mode_fopen); -+ file = hb_fopen(filename, mode_fopen); - return file; - } - @@ -114,6 +118,9 @@ { FILE* file = NULL; diff --git a/src/common/hbfopen.c b/src/common/hbfopen.c index caf9fafdd1..bac44efae0 100644 --- a/src/common/hbfopen.c +++ b/src/common/hbfopen.c @@ -53,20 +53,51 @@ #endif #include "hbapifs.h" +#include "hbvm.h" +#if defined( HB_OS_WIN ) + #include + #include "hbwinuni.h" +#endif FILE * hb_fopen( const char * path, const char * mode ) { - char * pszFree = NULL; FILE * file; - path = hb_fsNameConv( path, &pszFree ); -#if defined( _MSC_VER ) && _MSC_VER >= 1400 && ! defined( _CRT_SECURE_NO_WARNINGS ) - fopen_s( &file, path, mode ); +#if defined( HB_OS_WIN ) && defined( UNICODE ) && !defined( __XCC__ ) + LPCTSTR lpPath, lpMode; + LPTSTR lpFreeP, lpFreeM; + + lpPath = HB_FSNAMECONV( path, &lpFreeP ); + lpMode = HB_FSNAMECONV( mode, &lpFreeM ); + + hb_vmUnlock(); + #if defined( _MSC_VER ) && _MSC_VER >= 1400 && ! defined( _CRT_SECURE_NO_WARNINGS ) + _wfopen_s( &file, lpPath, lpMode ); + #else + file = _wfopen( lpPath, lpMode ); + #endif + hb_vmLock(); + + if( lpFreeP ) + hb_xfree( lpFreeP ); + if( lpFreeM ) + hb_xfree( lpFreeM ); #else - file = fopen( path, mode ); -#endif + char * pszFree = NULL; + + path = hb_fsNameConv( path, &pszFree ); + + hb_vmUnlock(); + #if defined( _MSC_VER ) && _MSC_VER >= 1400 && ! defined( _CRT_SECURE_NO_WARNINGS ) + fopen_s( &file, path, mode ); + #else + file = fopen( path, mode ); + #endif + hb_vmLock(); + if( pszFree ) hb_xfree( pszFree ); +#endif return file; }