summaryrefslogtreecommitdiff
path: root/src/core/xbfile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/xbfile.cpp')
-rwxr-xr-xsrc/core/xbfile.cpp103
1 files changed, 34 insertions, 69 deletions
diff --git a/src/core/xbfile.cpp b/src/core/xbfile.cpp
index a7d5257..937c16f 100755
--- a/src/core/xbfile.cpp
+++ b/src/core/xbfile.cpp
@@ -721,7 +721,7 @@ xbInt16 xbFile::GetFileSize( xbUInt64 &ullFileSize ){
try{
if(( iRc = xbFseek( 0, SEEK_END )) != XB_NO_ERROR ){
- iErrorStop = 10;
+ iErrorStop = 100;
throw iRc;
}
ullFileSize = xbFtell();
@@ -777,12 +777,10 @@ xbInt16 xbFile::GetOpenMode() const {
XB_MULTI_USER - (file buffering off)<br>
*/
-
xbInt16 xbFile::GetShareMode() const {
return iShareMode;
}
-
/************************************************************************/
//! @brief Get the file type byte and version of the dbf file.
/*!
@@ -845,13 +843,13 @@ xbInt16 xbFile::GetXbaseFileTypeByte( const xbString &sFileName, unsigned char
#ifdef HAVE__FSOPEN_F
// 0x40 is SH_DENYNO or _SH_DENYNO
if(( tfp = _fsopen( sFileName.Str(), "r", 0x40 )) == NULL ){
- iErrorStop = 20;
+ iErrorStop = 100;
iRc = XB_OPEN_ERROR;
throw iRc;
}
#else
if(( tfp = fopen( sFileName.Str(), "r" )) == NULL ){
- iErrorStop = 20;
+ iErrorStop = 110;
iRc = XB_OPEN_ERROR;
throw iRc;
}
@@ -864,13 +862,13 @@ xbInt16 xbFile::GetXbaseFileTypeByte( const xbString &sFileName, unsigned char
#endif
if( iRc != 0 ){
- iErrorStop = 30;
+ iErrorStop = 120;
iRc = XB_SEEK_ERROR;
throw iRc;
}
stRc = fread( &cFileTypeByte, (size_t) 1, (size_t) 1, tfp );
if( stRc != (size_t) 1 ){
- iErrorStop = 40;
+ iErrorStop = 130;
iRc = XB_READ_ERROR;
throw iRc;
}
@@ -960,7 +958,6 @@ xbInt16 xbFile::ReadBlock( xbUInt32 ulBlockNo, size_t lReadSize, void * buf ){
return ReadBlock( ulBlockNo, ulBlockSize, lReadSize, buf );
}
-
/***********************************************************************/
//! @brief Read a block of data from file.
/*!
@@ -980,13 +977,13 @@ xbInt16 xbFile::ReadBlock( xbUInt32 ulBlockNo, xbUInt32 ulBlockSize, size_t lRea
try{
if( ulBlockSize <= 0 ){
- iErrorStop = 10;
+ iErrorStop = 100;
iRc = XB_INVALID_BLOCK_SIZE;
throw iRc;
}
if(( iRc = xbFseek(((xbInt64) ulBlockNo*ulBlockSize ), SEEK_SET )) != XB_NO_ERROR ){
- iErrorStop = 20;
+ iErrorStop = 110;
iRc = XB_SEEK_ERROR;
throw iRc;
}
@@ -995,7 +992,7 @@ xbInt16 xbFile::ReadBlock( xbUInt32 ulBlockNo, xbUInt32 ulBlockSize, size_t lRea
lReadSize = ulBlockSize;
if(( iRc = xbFread( buf, lReadSize, 1 )) != XB_NO_ERROR ){
- iErrorStop = 30;
+ iErrorStop = 120;
iRc = XB_READ_ERROR;
throw iRc;
}
@@ -1149,18 +1146,18 @@ xbInt16 xbFile::WriteBlock( xbUInt32 ulBlockNo, size_t lWriteSize, void * buf ){
try{
if( ulBlockSize == 0 ){
- iErrorStop = 10;
+ iErrorStop = 100;
iRc = XB_INVALID_BLOCK_SIZE;
throw iRc;
}
if( lWriteSize <= 0 )
lWriteSize = ulBlockSize;
if(( iRc = xbFseek(( (xbInt64) ulBlockNo*ulBlockSize), SEEK_SET )) != XB_NO_ERROR ){
- iErrorStop = 20;
+ iErrorStop = 110;
throw iRc;
}
if(( iRc = xbFwrite( buf, lWriteSize, 1 )) != XB_NO_ERROR ){
- iErrorStop = 30;
+ iErrorStop = 120;
throw iRc;
}
}
@@ -1488,7 +1485,7 @@ xbInt16 xbFile::xbFseek( xbInt64 lOffset, xbInt32 iWhence ) {
#elif defined(HAVE__FSEEKI64_F)
iRc = _fseeki64( fp, lOffset, iWhence );
if( iRc != 0 ){
- iErrorStop = 200;
+ iErrorStop = 110;
throw iRc;
}
#else
@@ -1498,7 +1495,7 @@ xbInt16 xbFile::xbFseek( xbInt64 lOffset, xbInt32 iWhence ) {
if( lOffset > 2147483647 && iWhence == SEEK_SET ){
/* move forward max amt - 2G */
if(( iRc = fseek( fp, 2147483647, SEEK_SET )) != 0 ){
- iErrorStop = 300;
+ iErrorStop = 120;
throw iRc;
}
lOffset -= 2147483647;
@@ -1582,13 +1579,13 @@ xbInt16 xbFile::xbReadUntil( const char cDelim, xbString &sOut ){
try{
sOut = "";
if(( iRc = xbFgetc( c )) != XB_NO_ERROR ){
- iErrorStop = 10;
+ iErrorStop = 100;
throw iRc;
}
sOut = c;
while( iRc == XB_NO_ERROR && c != cDelim ){
if(( iRc = xbFgetc( c )) != XB_NO_ERROR ){
- iErrorStop = 10;
+ iErrorStop = 110;
throw iRc;
}
sOut += c;
@@ -1662,44 +1659,12 @@ xbInt16 xbFile::xbRemove( const xbString & sFileNameIn, xbInt16 iOption ) {
*/
xbInt16 xbFile::xbRename( const xbString & sOldName, const xbString & sNewName ){
- return xbRename( sOldName, sNewName, 0 );
-}
-
-/************************************************************************/
-//! @brief Rename file.
-/*!
- \param sOldName Original file name
- \param sNewName New file name
- \param iOption If Set to 1, assume this is a rename request for a dbf file, and should rename the dbt file also
- \returns <a href="xbretcod_8h.html">Return Codes</a>
-*/
-xbInt16 xbFile::xbRename( const xbString & sOldName, const xbString & sNewName, xbInt16 iOption ){
-
-
- if( rename( sOldName.Str(), sNewName.Str())){
+ if( rename( sOldName.Str(), sNewName.Str()))
return XB_RENAME_ERROR;
- }
- if( iOption == 1 ){
- xbString sOldName2 = sOldName;
- xbString sNewName2 = sNewName;
-
- if( sOldName2[sOldName2.Len()] == 'F' )
- sOldName2.PutAt( sOldName2.Len(), 'T' );
- else
- sOldName2.PutAt( sOldName2.Len(), 't' );
-
- if( sNewName2[sNewName2.Len()] == 'F' )
- sNewName2.PutAt( sNewName2.Len(), 'T' );
- else
- sNewName2.PutAt( sNewName2.Len(), 't' );
-
- if( rename( sOldName2.Str(), sNewName2.Str()))
- return XB_RENAME_ERROR;
- }
- return XB_NO_ERROR;
+ else
+ return XB_NO_ERROR;
}
-
/************************************************************************/
//! @brief Xbase wrapper for rewind.
/*!
@@ -1724,17 +1689,17 @@ xbInt16 xbFile::xbTruncate( xbInt64 llSize ) {
try{
#ifdef HAVE_FTRUNCATE_F
if(( iRc = ftruncate( iFileNo, llSize )) != 0 ){
- iErrorStop = 10;
+ iErrorStop = 100;
iRc = XB_WRITE_ERROR;
throw iRc;
}
#elif defined(HAVE_SETENDOFFILE_F)
if(( iRc = xbFseek( llSize, SEEK_SET )) != XB_NO_ERROR ){
- iErrorStop = 20;
+ iErrorStop = 110;
throw iRc;
}
if(( iRc = SetEndOfFile( fHandle )) == 0 ){
- iErrorStop = 30;
+ iErrorStop = 120;
iRc = XB_WRITE_ERROR;
throw iRc;
} else {
@@ -1781,7 +1746,7 @@ xbInt16 xbFile::xbLock( xbInt16 iFunction, xbInt64 lOffset, size_t stLen ){
/* Unix lock function */
if(( iRc = xbFseek( lOffset, SEEK_SET )) != XB_NO_ERROR ){
- iErrorStop = 10;
+ iErrorStop = 100;
throw iRc;
}
@@ -1794,7 +1759,7 @@ xbInt16 xbFile::xbLock( xbInt16 iFunction, xbInt64 lOffset, size_t stLen ){
fl.l_type = F_UNLCK;
break;
default:
- iErrorStop = 20;
+ iErrorStop = 110;
iRc = XB_INVALID_LOCK_OPTION;
throw iRc;
break;
@@ -1808,7 +1773,7 @@ xbInt16 xbFile::xbLock( xbInt16 iFunction, xbInt64 lOffset, size_t stLen ){
iTries++;
xbase->xbSleep( GetDefaultLockWait() );
} else if( iRc ){
- iErrorStop = 30;
+ iErrorStop = 120;
iRc = XB_LOCK_FAILED;
throw iRc;
}
@@ -1844,7 +1809,7 @@ xbInt16 xbFile::xbLock( xbInt16 iFunction, xbInt64 lOffset, size_t stLen ){
}
else
{
- iErrorStop = 30;
+ iErrorStop = 130;
iRc = XB_INVALID_LOCK_OPTION;
throw iRc;
}
@@ -1863,13 +1828,13 @@ xbInt16 xbFile::xbLock( xbInt16 iFunction, xbInt64 lOffset, size_t stLen ){
} else if( iFunction == XB_UNLOCK ){
iLockType = 0;
} else {
- iErrorStop = 50;
+ iErrorStop = 140;
iRc = XB_INVALID_LOCK_OPTION;
throw iRc;
}
if(( iRc = xbFseek( lOffset, SEEK_SET )) != XB_NO_ERROR ){
- iErrorStop = 60;
+ iErrorStop = 150;
iRc = XB_SEEK_ERROR;
throw iRc;
}
@@ -1961,13 +1926,13 @@ xbInt16 xbFile::DumpBlockToDisk( xbUInt32 ulBlockNo, size_t lBlkSize ){
char *buf = NULL;
FILE *fpd = NULL;
try{
- iErrorStop = 10;
+ iErrorStop = 100;
if( ulBlockNo == 0 ){
ulStartBlock = 0;
xbUInt64 ullFileSizeulBlockNo;
if(( iRc = GetFileSize( ullFileSizeulBlockNo )) != XB_NO_ERROR ){
- iErrorStop = 20;
+ iErrorStop = 110;
throw iRc;
}
ulEndBlock = (xbUInt32) (ullFileSizeulBlockNo / lBlkSize);
@@ -1977,7 +1942,7 @@ xbInt16 xbFile::DumpBlockToDisk( xbUInt32 ulBlockNo, size_t lBlkSize ){
}
if(( buf = (char *) malloc( lBlkSize )) == NULL ){
- iErrorStop = 30;
+ iErrorStop = 120;
iRc = XB_NO_MEMORY;
throw iRc;
}
@@ -1988,7 +1953,7 @@ xbInt16 xbFile::DumpBlockToDisk( xbUInt32 ulBlockNo, size_t lBlkSize ){
for( xbUInt32 l = ulStartBlock; l < ulEndBlock; l++ ){
if(( iRc = ReadBlock( l, lBlkSize, buf )) != XB_NO_ERROR ){
- iErrorStop = 40;
+ iErrorStop = 130;
throw iRc;
}
@@ -2004,7 +1969,7 @@ xbInt16 xbFile::DumpBlockToDisk( xbUInt32 ulBlockNo, size_t lBlkSize ){
#else
if(( fpd = fopen( sFn.Str(), "w+b")) == NULL ){
#endif
- iErrorStop = 50;
+ iErrorStop = 140;
iRc = XB_OPEN_ERROR;
throw iRc;
}
@@ -2014,7 +1979,7 @@ xbInt16 xbFile::DumpBlockToDisk( xbUInt32 ulBlockNo, size_t lBlkSize ){
for( size_t l = 0; l < lBlkSize; l++ ){
//if( fputc( *p, fpd ) != *p ){
if( fputc( *p, fpd ) == EOF ){
- iErrorStop = 60;
+ iErrorStop = 150;
iRc = XB_WRITE_ERROR;
throw iRc;
}
@@ -2030,7 +1995,7 @@ xbInt16 xbFile::DumpBlockToDisk( xbUInt32 ulBlockNo, size_t lBlkSize ){
}
catch (xbInt16 iRc ){
xbString sMsg;
- if( iErrorStop == 60 )
+ if( iErrorStop == 160 )
sMsg.Sprintf( "xbFile::DumpBlockToDisk() Exception Caught. Error Stop = [%d] iRc = [%d] c=[%c][%x]", iErrorStop, iRc, *p, *p );
else
sMsg.Sprintf( "xbFile::DumpBlockToDisk() Exception Caught. Error Stop = [%d] iRc = [%d]", iErrorStop, iRc );