2014-03-06 19:07 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)
* src/vm/set.c
! fixed freed memory access exploited by interactions between
modifications in last few years.
! do not try to remove trailing ^Z char reading from the stream
if FS_END seek reports 0.
! if possible open printer/alternate/extra output in write only mode
to avoid problem on devices where read access is not available.
* src/rtl/langapi.c
* keep EN lang active after deinitialization
* src/rtl/filesys.c
! fixed condition for file time refresh in *nix builds
! fixed file time setting in *nix builds
* include/hbapifs.h
* src/rtl/Makefile
* src/rtl/filebuf.c
+ src/rtl/filebufd.c
* renamed hb_fileRegister2() to hb_fileRegisterFull()
+ added new function hb_fileRegisterPart() which simplifies writing
small FILE IO redirectors.
* contrib/hbmemio/memio.c
* contrib/hbnetio/netiocli.c
* use hb_fileRegisterFull()
* contrib/hbplist.txt
+ contrib/hbtcpio/hbtcpio.hbc
+ contrib/hbtcpio/hbtcpio.hbp
+ contrib/hbtcpio/hbtcpio.hbx
+ contrib/hbtcpio/tcpio.c
+ added new Harbour FILE IO redirector.
It recognizes and process names with "tcp:" prefix, in form like:
tcp:<host>:<port>[:<timeout>]
It can be used in different subsystems using Harbour FILE IO and
stream read/write operations, i.e.
REQUEST HB_TCPIO
SET PRINTER TO tcp:192.168.0.110:9100
can be used to connect to network printers using TCP direct printing.
* utils/hbmk2/po/hbmk2.pt_BR.po
! fixed typo in translation
This commit is contained in:
@@ -48,6 +48,7 @@ C_SOURCES := \
|
||||
errintlo.c \
|
||||
file.c \
|
||||
filebuf.c \
|
||||
filebufd.c \
|
||||
filehb.c \
|
||||
filesys.c \
|
||||
fkmax.c \
|
||||
|
||||
@@ -921,7 +921,7 @@ static int s_fileFindDrv( const char * pszFileName )
|
||||
* public API functions
|
||||
*/
|
||||
|
||||
HB_BOOL hb_fileRegister2( const HB_FILE_FUNCS * pFuncs )
|
||||
HB_BOOL hb_fileRegisterFull( const HB_FILE_FUNCS * pFuncs )
|
||||
{
|
||||
HB_BOOL fResult = HB_FALSE;
|
||||
|
||||
|
||||
458
src/rtl/filebufd.c
Normal file
458
src/rtl/filebufd.c
Normal file
@@ -0,0 +1,458 @@
|
||||
/*
|
||||
* Harbour Project source code:
|
||||
* dummy I/O driver initialization
|
||||
*
|
||||
* Copyright 2014 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
|
||||
* www - http://harbour-project.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this software; see the file COPYING.txt. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
|
||||
*
|
||||
* As a special exception, the Harbour Project gives permission for
|
||||
* additional uses of the text contained in its release of Harbour.
|
||||
*
|
||||
* The exception is that, if you link the Harbour libraries with other
|
||||
* files to produce an executable, this does not by itself cause the
|
||||
* resulting executable to be covered by the GNU General Public License.
|
||||
* Your use of that executable is in no way restricted on account of
|
||||
* linking the Harbour library code into it.
|
||||
*
|
||||
* This exception does not however invalidate any other reasons why
|
||||
* the executable file might be covered by the GNU General Public License.
|
||||
*
|
||||
* This exception applies only to the code released by the Harbour
|
||||
* Project under the name Harbour. If you copy code from other
|
||||
* Harbour Project or Free Software Foundation releases into a copy of
|
||||
* Harbour, as the General Public License permits, the exception does
|
||||
* not apply to the code that you add in this way. To avoid misleading
|
||||
* anyone as to the status of such modified files, you must delete
|
||||
* this exception notice from them.
|
||||
*
|
||||
* If you write modifications of your own for Harbour, it is your choice
|
||||
* whether to permit this exception to apply to your modifications.
|
||||
* If you do not wish that, delete this exception notice.
|
||||
*
|
||||
*/
|
||||
|
||||
/* this has to be declared before hbapifs.h is included */
|
||||
#define _HB_FILE_IMPLEMENTATION_
|
||||
|
||||
#include "hbapi.h"
|
||||
#include "hbapifs.h"
|
||||
|
||||
#define HB_FILE_ERR_UNSUPPORTED ( ( HB_ERRCODE ) FS_ERROR )
|
||||
|
||||
static HB_BOOL s_fileAccept( const char * pszFileName )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pszFileName );
|
||||
|
||||
return HB_FALSE;
|
||||
}
|
||||
|
||||
static HB_BOOL s_fileExists( const char * pszFileName, char * pRetPath )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pszFileName );
|
||||
HB_SYMBOL_UNUSED( pRetPath );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return HB_FALSE;
|
||||
}
|
||||
|
||||
static HB_BOOL s_fileDelete( const char * pszFileName )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pszFileName );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return HB_FALSE;
|
||||
}
|
||||
|
||||
static HB_BOOL s_fileRename( const char * pszName, const char * pszNewName )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pszName );
|
||||
HB_SYMBOL_UNUSED( pszNewName );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return HB_FALSE;
|
||||
}
|
||||
|
||||
static HB_BOOL s_fileCopy( const char * pSrcFile, const char * pszDstFile )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pSrcFile );
|
||||
HB_SYMBOL_UNUSED( pszDstFile );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return HB_FALSE;
|
||||
}
|
||||
|
||||
static HB_BOOL s_fileDirExists( const char * pszDirName )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pszDirName );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return HB_FALSE;
|
||||
}
|
||||
|
||||
static HB_BOOL s_fileDirMake( const char * pszDirName )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pszDirName );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return HB_FALSE;
|
||||
}
|
||||
|
||||
static HB_BOOL s_fileDirRemove( const char * pszDirName )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pszDirName );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return HB_FALSE;
|
||||
}
|
||||
|
||||
static double s_fileDirSpace( const char * pszDirName, HB_USHORT uiType )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pszDirName );
|
||||
HB_SYMBOL_UNUSED( uiType );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
static PHB_ITEM s_fileDirectory( const char * pszDirSpec, const char * pszAttr )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pszDirSpec );
|
||||
HB_SYMBOL_UNUSED( pszAttr );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static HB_BOOL s_fileTimeGet( const char * pszFileName, long * plJulian, long * plMillisec )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pszFileName );
|
||||
HB_SYMBOL_UNUSED( plJulian );
|
||||
HB_SYMBOL_UNUSED( plMillisec );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return HB_FALSE;
|
||||
}
|
||||
|
||||
static HB_BOOL s_fileTimeSet( const char * pszFileName, long lJulian, long lMillisec )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pszFileName );
|
||||
HB_SYMBOL_UNUSED( lJulian );
|
||||
HB_SYMBOL_UNUSED( lMillisec );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return HB_FALSE;
|
||||
}
|
||||
|
||||
static HB_BOOL s_fileAttrGet( const char * pszFileName, HB_FATTR * pnAttr )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pszFileName );
|
||||
HB_SYMBOL_UNUSED( pnAttr );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return HB_FALSE;
|
||||
}
|
||||
|
||||
static HB_BOOL s_fileAttrSet( const char * pszFileName, HB_FATTR nAttr )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pszFileName );
|
||||
HB_SYMBOL_UNUSED( nAttr );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return HB_FALSE;
|
||||
}
|
||||
|
||||
static HB_BOOL s_fileLink( const char * pszExisting, const char * pszNewName )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pszExisting );
|
||||
HB_SYMBOL_UNUSED( pszNewName );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return HB_FALSE;
|
||||
}
|
||||
|
||||
static HB_BOOL s_fileLinkSym( const char * pszTarget, const char * pszNewName )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pszTarget );
|
||||
HB_SYMBOL_UNUSED( pszNewName );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return HB_FALSE;
|
||||
}
|
||||
|
||||
static char * s_fileLinkRead( const char * pszFileName )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pszFileName );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static PHB_FILE s_fileOpen( const char * pszName, const char * pszDefExt, HB_USHORT uiExFlags,
|
||||
const char * pPaths, PHB_ITEM pError )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pszName );
|
||||
HB_SYMBOL_UNUSED( pszDefExt );
|
||||
HB_SYMBOL_UNUSED( uiExFlags );
|
||||
HB_SYMBOL_UNUSED( pszDefExt );
|
||||
HB_SYMBOL_UNUSED( pPaths );
|
||||
HB_SYMBOL_UNUSED( pError );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void s_fileClose( PHB_FILE pFile )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pFile );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
}
|
||||
|
||||
static HB_BOOL s_fileLock( PHB_FILE pFile, HB_FOFFSET nStart,
|
||||
HB_FOFFSET nLen, int iType )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pFile );
|
||||
HB_SYMBOL_UNUSED( nStart );
|
||||
HB_SYMBOL_UNUSED( nLen );
|
||||
HB_SYMBOL_UNUSED( iType );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return HB_FALSE;
|
||||
}
|
||||
|
||||
static int s_fileLockTest( PHB_FILE pFile, HB_FOFFSET nStart,
|
||||
HB_FOFFSET nLen, int iType )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pFile );
|
||||
HB_SYMBOL_UNUSED( nStart );
|
||||
HB_SYMBOL_UNUSED( nLen );
|
||||
HB_SYMBOL_UNUSED( iType );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static HB_SIZE s_fileRead( PHB_FILE pFile, void * data,
|
||||
HB_SIZE nSize, HB_MAXINT timeout )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pFile );
|
||||
HB_SYMBOL_UNUSED( data );
|
||||
HB_SYMBOL_UNUSED( nSize );
|
||||
HB_SYMBOL_UNUSED( timeout );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static HB_SIZE s_fileWrite( PHB_FILE pFile, const void * data,
|
||||
HB_SIZE nSize, HB_MAXINT timeout )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pFile );
|
||||
HB_SYMBOL_UNUSED( data );
|
||||
HB_SYMBOL_UNUSED( nSize );
|
||||
HB_SYMBOL_UNUSED( timeout );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static HB_SIZE s_fileReadAt( PHB_FILE pFile, void * buffer,
|
||||
HB_SIZE nSize, HB_FOFFSET nOffset )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pFile );
|
||||
HB_SYMBOL_UNUSED( buffer );
|
||||
HB_SYMBOL_UNUSED( nSize );
|
||||
HB_SYMBOL_UNUSED( nOffset );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static HB_SIZE s_fileWriteAt( PHB_FILE pFile, const void * buffer,
|
||||
HB_SIZE nSize, HB_FOFFSET nOffset )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pFile );
|
||||
HB_SYMBOL_UNUSED( buffer );
|
||||
HB_SYMBOL_UNUSED( nSize );
|
||||
HB_SYMBOL_UNUSED( nOffset );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static HB_BOOL s_fileTruncAt( PHB_FILE pFile, HB_FOFFSET nOffset )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pFile );
|
||||
HB_SYMBOL_UNUSED( nOffset );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return HB_FALSE;
|
||||
}
|
||||
|
||||
static HB_FOFFSET s_fileSeek( PHB_FILE pFile, HB_FOFFSET nOffset,
|
||||
HB_USHORT uiFlags )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pFile );
|
||||
HB_SYMBOL_UNUSED( nOffset );
|
||||
HB_SYMBOL_UNUSED( uiFlags );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static HB_FOFFSET s_fileSize( PHB_FILE pFile )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pFile );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static HB_BOOL s_fileEof( PHB_FILE pFile )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pFile );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return HB_TRUE;
|
||||
}
|
||||
|
||||
static void s_fileFlush( PHB_FILE pFile, HB_BOOL fDirty )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pFile );
|
||||
HB_SYMBOL_UNUSED( fDirty );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
}
|
||||
|
||||
static void s_fileCommit( PHB_FILE pFile )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pFile );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
}
|
||||
|
||||
static HB_BOOL s_fileConfigure( PHB_FILE pFile, int iIndex, PHB_ITEM pValue )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pFile );
|
||||
HB_SYMBOL_UNUSED( iIndex );
|
||||
HB_SYMBOL_UNUSED( pValue );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return HB_FALSE;
|
||||
}
|
||||
|
||||
static HB_FHANDLE s_fileHandle( PHB_FILE pFile )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( pFile );
|
||||
|
||||
hb_fsSetError( HB_FILE_ERR_UNSUPPORTED );
|
||||
|
||||
return ( HB_FHANDLE ) FS_ERROR;
|
||||
}
|
||||
|
||||
static const HB_FILE_FUNCS s_fileFuncs =
|
||||
{
|
||||
s_fileAccept,
|
||||
|
||||
s_fileExists,
|
||||
s_fileDelete,
|
||||
s_fileRename,
|
||||
s_fileCopy,
|
||||
|
||||
s_fileDirExists,
|
||||
s_fileDirMake,
|
||||
s_fileDirRemove,
|
||||
s_fileDirSpace,
|
||||
s_fileDirectory,
|
||||
|
||||
s_fileTimeGet,
|
||||
s_fileTimeSet,
|
||||
s_fileAttrGet,
|
||||
s_fileAttrSet,
|
||||
|
||||
s_fileLink,
|
||||
s_fileLinkSym,
|
||||
s_fileLinkRead,
|
||||
|
||||
s_fileOpen,
|
||||
s_fileClose,
|
||||
s_fileLock,
|
||||
s_fileLockTest,
|
||||
s_fileRead,
|
||||
s_fileWrite,
|
||||
s_fileReadAt,
|
||||
s_fileWriteAt,
|
||||
s_fileTruncAt,
|
||||
s_fileSeek,
|
||||
s_fileSize,
|
||||
s_fileEof,
|
||||
s_fileFlush,
|
||||
s_fileCommit,
|
||||
s_fileConfigure,
|
||||
s_fileHandle
|
||||
};
|
||||
|
||||
typedef void * ( * HB_FILE_FUNC )( PHB_FILE );
|
||||
#define HB_FILE_FUNC_COUNT ( sizeof( HB_FILE_FUNCS ) / sizeof( HB_FILE_FUNC ) )
|
||||
|
||||
HB_BOOL hb_fileRegisterPart( HB_FILE_FUNCS * pFuncs )
|
||||
{
|
||||
const HB_FILE_FUNC * pDummyFunc;
|
||||
HB_FILE_FUNC * pFunction;
|
||||
int iCount;
|
||||
|
||||
pDummyFunc = ( const HB_FILE_FUNC * ) &s_fileFuncs;
|
||||
pFunction = ( HB_FILE_FUNC * ) pFuncs;
|
||||
|
||||
for( iCount = 0; iCount < ( int ) HB_FILE_FUNC_COUNT;
|
||||
iCount++, pDummyFunc++, pFunction++ )
|
||||
{
|
||||
if( * pFunction == NULL )
|
||||
* pFunction = * pDummyFunc;
|
||||
}
|
||||
|
||||
return hb_fileRegisterFull( pFuncs );
|
||||
}
|
||||
@@ -1602,7 +1602,7 @@ HB_BOOL hb_fsSetFileTime( const char * pszFileName, long lJulian, long lMillisec
|
||||
|
||||
pszFileName = hb_fsNameConv( pszFileName, &pszFree );
|
||||
|
||||
if( lJulian <= 0 && lMillisec )
|
||||
if( lJulian <= 0 && lMillisec < 0 )
|
||||
{
|
||||
# if defined( HB_OS_LINUX ) && ! defined( __WATCOMC__ )
|
||||
fResult = utimes( pszFileName, NULL ) == 0;
|
||||
@@ -1613,7 +1613,6 @@ HB_BOOL hb_fsSetFileTime( const char * pszFileName, long lJulian, long lMillisec
|
||||
else
|
||||
{
|
||||
struct tm new_value;
|
||||
time_t tim;
|
||||
|
||||
if( lJulian <= 0 || lMillisec < 0 )
|
||||
{
|
||||
@@ -1641,12 +1640,8 @@ HB_BOOL hb_fsSetFileTime( const char * pszFileName, long lJulian, long lMillisec
|
||||
new_value.tm_min = iMinute;
|
||||
new_value.tm_sec = iSecond;
|
||||
}
|
||||
tim = mktime( &new_value );
|
||||
# if defined( HB_HAS_LOCALTIME_R )
|
||||
gmtime_r( &tim, &new_value );
|
||||
# else
|
||||
new_value = *gmtime( &tim );
|
||||
# endif
|
||||
new_value.tm_isdst = 0;
|
||||
|
||||
# if defined( HB_OS_LINUX ) && ! defined( __WATCOMC__ )
|
||||
{
|
||||
struct timeval times[ 2 ];
|
||||
|
||||
@@ -229,8 +229,11 @@ static void hb_langRelease( PHB_LANG_BASE pBase )
|
||||
if( pBase->lang )
|
||||
{
|
||||
if( pBase->buffer )
|
||||
{
|
||||
hb_xfree( pBase->buffer );
|
||||
pBase->lang = NULL;
|
||||
pBase->buffer = NULL;
|
||||
}
|
||||
pBase->lang = pBase == s_langList ? &s_lang_en : NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
100
src/vm/set.c
100
src/vm/set.c
@@ -242,19 +242,18 @@ static const char * is_devicename( const char * szFileName )
|
||||
}
|
||||
|
||||
static void open_handle( PHB_SET_STRUCT pSet, const char * file_name,
|
||||
HB_BOOL bAppend, HB_set_enum set_specifier )
|
||||
HB_BOOL fAppend, HB_set_enum set_specifier )
|
||||
{
|
||||
HB_STACK_TLS_PRELOAD
|
||||
PHB_ITEM pError = NULL;
|
||||
PHB_FILE handle, * handle_ptr;
|
||||
HB_ERRCODE uiError;
|
||||
const char * szDevice = NULL;
|
||||
const char * szFileName = NULL;
|
||||
const char * def_ext;
|
||||
const char * szDevice = NULL, * def_ext;
|
||||
char * szFileName = NULL;
|
||||
char ** set_value;
|
||||
HB_BOOL bPipe = HB_FALSE;
|
||||
HB_BOOL fPipe = HB_FALSE, fStripEof;
|
||||
|
||||
HB_TRACE( HB_TR_DEBUG, ( "open_handle(%p, %s, %d, %d)", pSet, file_name, ( int ) bAppend, ( int ) set_specifier ) );
|
||||
HB_TRACE( HB_TR_DEBUG, ( "open_handle(%p, %s, %d, %d)", pSet, file_name, ( int ) fAppend, ( int ) set_specifier ) );
|
||||
|
||||
switch( set_specifier )
|
||||
{
|
||||
@@ -280,85 +279,59 @@ static void open_handle( PHB_SET_STRUCT pSet, const char * file_name,
|
||||
return;
|
||||
}
|
||||
|
||||
close_handle( pSet, set_specifier );
|
||||
|
||||
if( file_name && file_name[ 0 ] != '\0' )
|
||||
{
|
||||
#if defined( HB_OS_UNIX )
|
||||
bPipe = file_name[ 0 ] == '|';
|
||||
if( bPipe )
|
||||
{
|
||||
szFileName = file_name;
|
||||
bAppend = HB_FALSE;
|
||||
}
|
||||
fPipe = file_name[ 0 ] == '|';
|
||||
if( fPipe )
|
||||
szFileName = hb_strdup( file_name );
|
||||
else
|
||||
#endif
|
||||
{
|
||||
szDevice = is_devicename( file_name );
|
||||
if( szDevice )
|
||||
{
|
||||
szFileName = szDevice;
|
||||
szFileName = hb_strdup( szDevice );
|
||||
def_ext = NULL;
|
||||
}
|
||||
else
|
||||
szFileName = file_name;
|
||||
szFileName = hb_strdup( file_name );
|
||||
}
|
||||
}
|
||||
|
||||
/* free the old value before setting the new one (CA-Cl*pper does it).
|
||||
* This code must be executed after setting szFileName, [druzus]
|
||||
*/
|
||||
close_handle( pSet, set_specifier );
|
||||
if( *set_value )
|
||||
{
|
||||
hb_xfree( *set_value );
|
||||
*set_value = NULL;
|
||||
*set_value = NULL;
|
||||
}
|
||||
|
||||
if( ! szFileName )
|
||||
return;
|
||||
|
||||
/* Open the file either in append (bAppend) or truncate mode (! bAppend), but
|
||||
fStripEof = fAppend && szDevice == NULL && ! fPipe;
|
||||
|
||||
/* Open the file either in append (fAppend) or truncate mode (! fAppend), but
|
||||
always use binary mode */
|
||||
|
||||
/* QUESTION: What sharing mode does Clipper use ? [vszakats] */
|
||||
|
||||
do
|
||||
{
|
||||
if( bPipe )
|
||||
{
|
||||
if( fPipe )
|
||||
handle = hb_filePOpen( szFileName + 1, "w" );
|
||||
}
|
||||
else
|
||||
{
|
||||
handle = hb_fileExtOpen( szFileName,
|
||||
hb_stackSetStruct()->HB_SET_DEFEXTENSIONS ? def_ext : NULL,
|
||||
FO_READWRITE | FO_READWRITE | FXO_SHARELOCK |
|
||||
( bAppend ? FXO_APPEND : FXO_TRUNCATE ) |
|
||||
( !fStripEof || set_specifier == HB_SET_PRINTFILE ? FO_WRITE : FO_READWRITE ) |
|
||||
FO_DENYWRITE | FXO_SHARELOCK |
|
||||
( fAppend ? FXO_APPEND : FXO_TRUNCATE ) |
|
||||
( szDevice ? 0 : FXO_DEFAULTS ),
|
||||
NULL, pError );
|
||||
|
||||
if( handle != NULL && szDevice == NULL && bAppend )
|
||||
{
|
||||
/* Position to EOF */
|
||||
/* Special binary vs. text file handling - even for UN*X, now
|
||||
that there's an HB_SET_EOF flag. */
|
||||
if( set_specifier == HB_SET_PRINTFILE )
|
||||
{
|
||||
/* PRINTFILE is always binary and needs no special handling. */
|
||||
hb_fileSeek( handle, 0, FS_END );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* All other files are text files and may have an EOF
|
||||
('\x1A') character at the end (both UN*X and non-UN*X,
|
||||
now that theres an HB_SET_EOF flag). */
|
||||
char cEOF = '\0';
|
||||
hb_fileSeek( handle, -1, FS_END ); /* Position to last char. */
|
||||
hb_fileRead( handle, &cEOF, 1, -1 ); /* Read the last char. */
|
||||
if( cEOF == '\x1A' ) /* If it's an EOF, */
|
||||
hb_fileSeek( handle, -1, FS_END ); /* Then write over it. */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( handle == NULL )
|
||||
{
|
||||
pError = hb_errRT_FileError( pError, HB_ERR_SS_TERMINAL, EG_CREATE, uiError, szFileName );
|
||||
@@ -371,14 +344,43 @@ static void open_handle( PHB_SET_STRUCT pSet, const char * file_name,
|
||||
if( pError )
|
||||
hb_itemRelease( pError );
|
||||
|
||||
if( handle != NULL && fStripEof )
|
||||
{
|
||||
/* Position to EOF */
|
||||
if( hb_fileSeek( handle, 0, FS_END ) > 0 )
|
||||
{
|
||||
/* Special binary vs. text file handling - even for UN*X, now
|
||||
that there's an HB_SET_EOF flag. */
|
||||
|
||||
/* PRINTFILE is always binary and needs no special handling. */
|
||||
if( set_specifier != HB_SET_PRINTFILE )
|
||||
{
|
||||
/* All other files are text files and may have an EOF
|
||||
('\x1A') character at the end (both UN*X and non-UN*X,
|
||||
now that theres an HB_SET_EOF flag). */
|
||||
char cEOF = '\0';
|
||||
hb_fileSeek( handle, -1, FS_END ); /* Position to last char. */
|
||||
hb_fileRead( handle, &cEOF, 1, -1 ); /* Read the last char. */
|
||||
if( cEOF == '\x1A' ) /* If it's an EOF, */
|
||||
hb_fileSeek( handle, -1, FS_END ); /* Then write over it. */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* user RT error handler can open it too so we have to
|
||||
* close it again if necessary
|
||||
*/
|
||||
if( handle == NULL )
|
||||
{
|
||||
hb_xfree( szFileName );
|
||||
szFileName = NULL;
|
||||
}
|
||||
|
||||
close_handle( pSet, set_specifier );
|
||||
*handle_ptr = handle;
|
||||
if( *set_value )
|
||||
hb_xfree( *set_value );
|
||||
*set_value = handle != NULL ? hb_strdup( szFileName ) : NULL;
|
||||
*set_value = szFileName;
|
||||
}
|
||||
|
||||
HB_BOOL hb_setSetCentury( HB_BOOL new_century_setting )
|
||||
|
||||
Reference in New Issue
Block a user