コード例 #1
0
long	
C_File::CurPos()
{
	C_FileCritSect	cCS0( this, CRITSECT0 );
	int iFlag = FALSE;
	if( (_bIs32s && iFile == -1) || (!_bIs32s && hFile == INVALID_HANDLE_VALUE) ){
		if( ReOpen() != OK ){		   
			if( !_xFile ){
				return( -1 );
			}
			_xFile->PseudoClose();
			ReOpen();
			iFlag = TRUE;
		}
	}
	long 	lRet;
	DWORD	dwResult;
	if( _bIs32s ){
		lRet = lseek( iFile, 0, SEEK_CUR );
	} else {
		dwResult = SetFilePointer( hFile, 0, NULL, FILE_CURRENT );
	}
#ifdef _USE_PRINTF_
	Printf( "C_File: CurPos do arquivo %d eh %d", (int) hFile, _bIs32s ? iFile : (int) dwResult );
#endif
	if( iFlag ){
		PseudoClose();
		_xFile->ReOpen();
	}
	return( _bIs32s ? lRet : (long) dwResult );
}
コード例 #2
0
ファイル: FileLog.cpp プロジェクト: YeZhui/git_repository
int CFileLog::CheckFile()
{
	char szFileName[256] = {0};
	long lCurTime = 0;
	int length = 0;
	
	//要检查日期,一旦日期发生变化写日志就要修改
	lCurTime = GetCurTime();	
	if (lCurTime > m_lCurTime)
	{
		m_lCurTime = lCurTime;
		m_iFileNum = 0;
		ReOpen();
	}
	else
	{
		//超过50M就写下一个文件
		length = m_file.tellg();
		if (length > MAX_FILE_LENGTH)
		{
			m_file.flush();
			m_iFileNum++;
			ReOpen();
		}
	}
	return 0;
}
コード例 #3
0
/***
	PRIVATE
	RealLock

	Realiza um lock em uma regiao do arquivo, utilizando rotinas
	do Sistema Operacional
***/
int
C_File::RealLock( LockStruct *ls, BOOL bWait )
{
	C_FileCritSect	cCS0( this, CRITSECT0 );
	if( !bRealLock ){
		return( OK );
	}
	int	iRet = !OK;
	int	iFlag = FALSE;
	if( (_bIs32s && iFile == -1) || (!_bIs32s && hFile == INVALID_HANDLE_VALUE) ){
		if( ReOpen() != OK ){
			if( !_xFile ){
				return( !OK );
			}
			_xFile->PseudoClose();
			ReOpen();
			iFlag = TRUE;
		}
	}

	if( ls ){
		if( _bIs32s ){
			long lPos = CurPos();
			if( Seek( ls->iPos, SEEK_SET ) == OK ){
				iRet = locking( iFile, _LK_LOCK, ls->iSize );
			}
			Seek( lPos, SEEK_SET );
		} else {
			if( Seek( ls->iPos, SEEK_SET ) == OK ){
				DWORD	dwErr;

				SetLastError( 0 );
				iRet = LockFile( hFile, ls->iPos, 0, ls->iSize, 0 ) ? OK : !OK;
				dwErr = GetLastError();
				while( bWait && ((dwErr == ERROR_LOCK_FAILED) || (dwErr == ERROR_LOCK_VIOLATION)) ){
					// esperar e tentar novamente.
					cCS0.LeaveCriticalSection();
					Sleep( 1000 );	// 1 segundo
					cCS0.EnterCriticalSection();
					SetLastError( 0 );
					iRet = LockFile( hFile, ls->iPos, 0, ls->iSize, 0 ) ? OK : !OK;
					dwErr = GetLastError();
				}
			}
		}
	}
	if( iFlag ){
		PseudoClose();
		_xFile->ReOpen();
	}
	return( iRet );
}
コード例 #4
0
long
C_File::FileSize()
{
	C_FileCritSect	cCS0( this, CRITSECT0 );
	int iFlag = FALSE;
	if( (_bIs32s && iFile == -1) || (!_bIs32s && hFile == INVALID_HANDLE_VALUE) ){
		if( ReOpen() != OK ){		   
			if( !_xFile ){
				return( -1 );
			}
			_xFile->PseudoClose();
			ReOpen();
			iFlag = TRUE;
		}
	}

	if( _bIs32s ){
		long lCurPosAux = CurPos();
		Seek( 0, SEEK_END );
		long lSize = CurPos();
		Seek( lCurPosAux, SEEK_SET );
		if( iFlag ){
			PseudoClose();
			_xFile->ReOpen();
		}
		return( lSize );
	}
	// guarda a posicao corrente
//	long	lCurPosAux = CurPos();

	DWORD	dwResult = GetFileSize( hFile, NULL );

/*	// vai para o fim do arquivo e pega o numero do ultimo byte
	dwResult = SetFilePointer( hFile, 0, NULL, FILE_END );
/*
	if( dwResult == 0XFFFFFFFF ){
		DWORD	dw = GetLastError();
		char	szErr[ 500 ];

		sprintf( szErr, "Erro no GetFileSize: %d", (int) dw );
		MessageBox( NULL, szErr, "DEBUG - LIFILE", MB_OK );
	}

	// volta para a posicao que estava
	Seek( lCurPosAux, SEEK_SET );
*/
	if( iFlag ){
		PseudoClose();
		_xFile->ReOpen();
	}
	return( (long) dwResult );
}
コード例 #5
0
ファイル: KeyPair.cpp プロジェクト: mesoto/PPK
CKeyFile::CKeyFile(void)
{
    CKeyPair k;
    CHAR buff[300];
    
    // Get the PPK.exe file path
    GetModuleFileName( GetModuleHandle(NULL), (LPSTR)&buff[0], sizeof(buff) );
    GetFullPathName( (LPCSTR)&buff[0], sizeof(full_path), (LPSTR)&full_path[0], (LPSTR *)&file_name );
    strcpy_s( (char *)file_name, 20, "PPKDir.csv" );

    if( IsFilePresent( (char *)&full_path[0] )) return;

    if( GetEnvironmentVariable( "LOCALAPPDATA", (LPSTR)&buff[0], sizeof(buff) ) ||
        GetEnvironmentVariable( "APPDATA", (LPSTR)&buff[0], sizeof(buff) ))
    {
        strcat_s( (char *)&buff[0], sizeof(buff), "\\PPK" );
        if( !IsFilePresent( &buff[0] ))
            CreateDirectory( (LPCSTR)&buff[0], NULL );
        strcat_s( (char *)&buff[0], sizeof(buff), "\\PPKDir.csv" );

        GetFullPathName( (LPCSTR)&buff[0], sizeof(full_path), (LPSTR)&full_path[0], (LPSTR *)&file_name );
        if( IsFilePresent( (char *)&buff[0] )) return;
    }

    LoadString(hInst, IDS_INITIAL_KEY, buff, 80);
    k.ExtractPublicKey( (unsigned char *)&buff[0] );
    k.type = KEY_TYPE_OTHERS;

    if( ReOpen( "wt" ) == PPK_SUCCESS )
    {
        AddNewKey( &k );
        Close();
    }
}
コード例 #6
0
/***
	Grava uma linha em um arquivo texto. No final da linha, coloca um
	'\n'. Retorna OK ou !OK.
***/
size_t
C_File::WriteLine( char FAR *szBuf )
{
	C_FileCritSect	cCS0( this, CRITSECT0 );
	int iFlag = FALSE;
	if( !szBuf ){
		return( (size_t) E_BUFFNULL );
	}
	if( (_bIs32s && iFile == -1) || (!_bIs32s && hFile == INVALID_HANDLE_VALUE) ){
		if( ReOpen() != OK ){		   
			if( !_xFile ){
				return( !OK );
			}
			_xFile->PseudoClose();
			ReOpen();
			iFlag = TRUE;
		}
	}
	char cAuxCripto = cCriptoOn;
	cCriptoOn = FALSE;

	if( Write( szBuf, strlen( szBuf ) ) != OK ){
		if( iFlag ){
			PseudoClose();
			_xFile->ReOpen();
		}
		return( !OK );
	}
	char szTmp[] = "\r\n";
	if( Write( szTmp, strlen( szTmp ) ) != OK ){
		if( iFlag ){
			PseudoClose();
			_xFile->ReOpen();
		}
		return( !OK );
	}
	cCriptoOn = cAuxCripto;
	dwLastUse = GetTickCount();
	if( iFlag ){
		PseudoClose();
		_xFile->ReOpen();
	}
	return( OK );
}
コード例 #7
0
ファイル: CLogStream.cpp プロジェクト: kobake/KppLibs
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- //
// CLogStream
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- //
CLogStream::CLogStream(const wchar_t* szFileNameTemplate, int nRotationSize, bool bLogHold)
: m_nRef(0)
, m_strFileNameTemplate(szFileNameTemplate)
, m_fp(NULL)
, m_nRotationSize(nRotationSize)
, m_bLogHold(bLogHold)
{
	m_strFileNameTemplate = cpp_wcsreplace(m_strFileNameTemplate, L"\\", L"/");
	ReOpen();
}
コード例 #8
0
/***
	Metodo Release
	Libera um registro previamente travado

	Parameters:
		- pcfControlFile

	Return:
		LBS_OK se conseguir liberar ou erro.

	Comments:

***/
int
C_File::Release( long lSize )
{
	C_FileCritSect	cCS0( this, CRITSECT0 );
	if( (_bIs32s && iFile == -1) || (!_bIs32s && hFile == INVALID_HANDLE_VALUE) ){
		if( ReOpen() != OK ){		   
			return( E_NOTOPEN );
		}
	}
	LockStruct ls( this, CurPos(), lSize );
	return( DelLock( &ls ) );
}
コード例 #9
0
ファイル: SoundStream.cpp プロジェクト: dreamsxin/golf
// callback
void CSoundStreamServerSession::MaoscBufferCopied(TInt aError, const TDesC8& /*aBuffer*/) {
	readyForWrite=true;

	// underflow? reopen!
	if (aError==KErrUnderflow) {
		ReOpen();
	}
	
	// update next buffer
	if ((aError==KErrUnderflow) || (aError==KErrNone)) {
		UpdateBuffer();
	}
}
コード例 #10
0
/***
	PRIVATE
	RealRelease

	Realiza um unlock em uma regiao do arquivo, utilizando rotinas
	do Sistema Operacional
***/
int
C_File::RealRelease( LockStruct *ls )
{
	C_FileCritSect	cCS0( this, CRITSECT0 );
	if( !bRealLock ){
		return( OK );
	}
	int	iRet = !OK;
	int	iFlag = FALSE;
	if( (_bIs32s && iFile == -1) || (!_bIs32s && hFile == INVALID_HANDLE_VALUE) ){
		if( ReOpen() != OK ){
			if( !_xFile ){
				return( !OK );
			}
			_xFile->PseudoClose();
			ReOpen();
			iFlag = TRUE;
		}
	}

	if( ls ){
		if( _bIs32s ){
			long lPos = CurPos();
			if( Seek( ls->iPos, SEEK_SET ) == OK ){
				iRet = locking( iFile, _LK_UNLCK, ls->iSize );
			}
			Seek( lPos, SEEK_SET );
		} else {
			if( Seek( ls->iPos, SEEK_SET ) == OK ){
				iRet = UnlockFile( hFile, ls->iPos, 0, ls->iSize, 0 ) ? OK : !OK;
			}
		}
	}
	if( iFlag ){
		PseudoClose();
		_xFile->ReOpen();
	}
	return( iRet );
}
コード例 #11
0
ファイル: SoundStream.cpp プロジェクト: dreamsxin/golf
// playing stopped
void CSoundStreamServerSession::MaoscPlayComplete(TInt aError) {
	readyForWrite=true;

	timeOfUpdate.UniversalTime();
	
	// if underflow, restart
	if (aError==KErrUnderflow) {
		ReOpen();
		UpdateBuffer();
	} else {
		// no underflow? then it was manually stopped...
		CActiveScheduler::Stop();
	}
}
コード例 #12
0
/***
	Metodo Lock
	Trava o registro

	Parameters:
		- pcfControlFile

	Return:
		LBS_OK se conseguir travar ou erro.

	Comments:

***/
int
C_File::Lock( long lSize, BOOL bWait )
{
//	C_FileCritSect	cCS0( this, CRITSECT0 );
	if( (_bIs32s && iFile == -1) || (!_bIs32s && hFile == INVALID_HANDLE_VALUE) ){
		if( ReOpen() != OK ){		   
			return( E_NOTOPEN );
		}
	}

	LockStruct *ls = new LockStruct( this, CurPos(), lSize );
	if( ls ){
		if( AddLock( ls, bWait ) == OK ){
			return( OK );
		}
		delete ls;
	}
	return( !OK );
}
コード例 #13
0
ファイル: FileLog.cpp プロジェクト: YeZhui/git_repository
void CFileLog::Init()
{
	char szAllPath[128] = {0};
	//配置文件读取日志文件存放路径 TODO:
	memset(m_szFilePath, 0, sizeof(m_szFilePath));
	auto strLogDir = ConfigIni::ReadStr("FILE", "FILENAME");
	if (strLogDir == "")
	{
		std::cout << "read FILENAME failed" << std::endl;
		exit(-1);
	}
	strncpy(m_szFilePath, strLogDir.c_str(), sizeof(m_szFilePath)-1);
	//获取当前日期作为路径
	m_lCurTime = GetCurTime();
	snprintf(szAllPath, sizeof(szAllPath)-1, "%s/%ld", m_szFilePath, m_lCurTime );

	CheckDir(szAllPath);
	ReOpen();
}
コード例 #14
0
ファイル: ioc.c プロジェクト: jamjr/Helios-NG
static bool SetupStream( Stream *stream, MCB *mcb )
{
	IOCReply1 *rep = (IOCReply1 *)mcb->Control;
	Port server = mcb->MsgHdr.Reply;

	if( (mcb->MsgHdr.ContSize*sizeof(word)) < (sizeof(IOCReply1)-sizeof(word)) ) return false;
		
	stream->Type = rep->Type;
	stream->Flags = Flags_Stream|rep->Flags;

	if ( server == NullPort )
	{
		FreePort( stream->Server );
		stream->Server = rep->Object;
	}
	else 
	{
		if( stream->Server != server ) FreePort(stream->Server);
		stream->Server = server;
		stream->Flags |= Flags_Server;

		/* pipes do not have a server despite returning a port on open */
		if( stream->Type == Type_Pipe ) stream->Flags ^= Flags_Server;

		if( (server & Port_Flags_Remote) != 0 )
			stream->Flags |= Flags_Remote;
	}

	stream->Access = rep->Access;
	stream->Reply = mcb->MsgHdr.Dest;
	if(mcb->MsgHdr.FnRc >= Err_Null ) stream->FnMod = mcb->MsgHdr.FnRc;
	stream->Timeout = stream->Flags&Flags_Fast?mcb->Timeout:IOCTimeout;


	strcpy(stream->Name,&mcb->Data[rep->Pathname]);
	
	if( (stream->Type == Type_Pseudo) && (stream->Flags & Flags_OpenOnGet) )
		ReOpen(stream);	

	return true;
}
コード例 #15
0
ファイル: flow.cpp プロジェクト: cdaffara/symbiandump-os2
EXPORT_C TInt RFlowContext::Status()
	/**
	* Gets the status of the flow.
	*
	* This function attempts to return the current "effective" status
	* of the flow based on current settings. Thus, if the flows parameters
	* have been changed since the last connect, the function does an implicit
	* (re)connect first.
	*
	* For documentation on values, see CFlowContext::Status.
	*
	* @return
	*		KErrBadHandle, if handle is not attached to a flow context. Other returns
	*		are defined by CFlowContext::Status.
	*/
	{
	if (!iFlow)
		return KErrBadHandle;

	// If the flow is in error state (< 0), the Status() alone will not
	// clear it (changed bit is not effective!).
	if (iFlow->iStatus >= 0 && iFlow->iChanged)
		{
		//
		// The flow parameters have been changed
		//
		if (iFlow->iRefs > 0)
			{
			//
			// Need to allocate a new flow

			TInt err = ReOpen();
			if (err != KErrNone)
				return err;
			}
		// Assume: ConnectFlow will clean out all previous connection state! -- msa
		iFlow->Connect();
		}
	return iFlow->Status();
	}
コード例 #16
0
ファイル: flow.cpp プロジェクト: cdaffara/symbiandump-os2
EXPORT_C TInt RFlowContext::Clone(const RFlowContext &aFlow)
	/**
	* Creates a new flow with the flow parameters copied from another flow.
	*
	* @param aFlow
	*		a flow to be duplicated
	*
	* @return
	*		System wide error codes
	*/
	{
	//
	// This sequence of actions below tries to do the cloning in
	// such a way, that it is safe even if the this == aFlow (in which
	// case this is same as plain "ReOpen()").
	//
	CFlowContext *old = iFlow;
	iFlow = aFlow.iFlow;
	iFlow->Open();
	TInt ret = ReOpen();
	if (old)
		old->Close();
	return ret;
	}
コード例 #17
0
ファイル: KeyPair.cpp プロジェクト: mesoto/PPK
int CKeyFile::GetFirstKey( CKeyPair * key )
{
    ReOpen( "rt" );
    return GetNextKey(key);
}
コード例 #18
0
/***
	Write bytes in a file from a given buffer.
	Parameters:
		- pvBuf: User buffer with data to write in file
		- tsSize: Size of iten to write
		- tsNumItens: Number of itens to write
	Return:
		Number of writtem itens in succes or E_NOTOPEN,
		E_BUFFNULL or E_WRITE.
***/
size_t
C_File::Write( void FAR *pvBuf, size_t tsSize, size_t tsNumItens )
{
	C_FileCritSect	cCS0( this, CRITSECT0 );

	size_t	i = 0;
	BOOL	bContinue = TRUE;


#ifdef _USE_PRINTF_
	Printf( "C_File: Estou em Write. (arq %s)", szFileName );
#endif
	int iFlag = FALSE;
	if( !pvBuf ){
		return( (size_t) E_BUFFNULL );
	}
	if( (_bIs32s && iFile == -1) || (!_bIs32s && hFile == INVALID_HANDLE_VALUE) ){
		if( ReOpen() != OK ){		   
			if( !_xFile ){
				return( 0 );
			}
			_xFile->PseudoClose();
			ReOpen();		   
			iFlag = TRUE;
		}
	}
	LockStruct ls( this, CurPos(), (tsSize * tsNumItens) );
	if( IsLocked( &ls ) ){
		if( iFlag ){
			PseudoClose();
			_xFile->ReOpen();
		}
#ifdef _USE_PRINTF_
		Printf( "C_File: Write: IsLocked." );
#endif
		return( (size_t) E_WRITE );
	}

	if( cCriptoOn ){
		Encrypt( pvBuf, szKey, tsSize );
	}

	// MMF
	BOOL	bWriteHeader = FALSE;
	if( !_bIs32s && hMMF ){
		// preparar gravacao a partir do MMF

		long	lFSize = FileSize();
		long	lCPos = CurPos();
		if( ( lCPos + (int) (tsNumItens * tsSize) ) > lFSize ){
			// este write vai exceder os limites do arquivo. vamos aumentar-lo.
			if( GrowFile( lCPos + (tsNumItens * tsSize) ) != OK ){
				// nao foi possivel aumentar o arquivo.
				bContinue = FALSE;
			}
		}
		if( bContinue ){
			if( (lCPos == iHeadInit)  && (((int) tsSize) == iHeadSize) ){
				bWriteHeader = TRUE;
				// vamos fazer write no header do arquivo.
				if( !pHeadView ){
					// o header ainda nao esta' mapeado. vamos fazer isso.
					CreateViewOfHead();
				}
			} else {
				if( !pWinView ){
					// o arquivo ainda nao esta' mapeado. vamos fazer isso.
					CreateViewOfFile();
				}
			}
		}
	}

	if( bContinue ){
		for( i = 0; i < tsNumItens; i++ ){
			if( _bIs32s ){
				if( write( iFile, pvBuf, (unsigned) tsSize ) < (int) tsSize ){
					break;
				}
			} else {
				if( bWriteHeader ){
					// gravar header no MMF.
					memcpy( pHeadView, pvBuf, tsSize );
				} else {
					if( pWinView ){
						// gravar no MMF.
						int	iNumBytes = ((iMMFWinSize * iPageSize) - iSeekWin) - (iHeadSize + 1);
						memcpy( (void*) ((char*) PWINVIEW + iSeekWin), pvBuf, min( iNumBytes, ((int) tsSize) ) );
						if( iNumBytes < ((int) tsSize) ){
							// precisamos mapear outra janela e continuar a gravacao
							++iWinNum;	// proxima janela
							CreateViewOfFile();
							if( !pWinView ){
								// mapeamento nao foi feito. fudeu.
								break;
							}
							// gravacao do restante
							memcpy( (void*) ((char*) PWINVIEW + iSeekWin), (void*) ((char*) pvBuf + iNumBytes), (tsSize - iNumBytes) );
							iSeekWin += (tsSize - iNumBytes);
						} else {
							iSeekWin += tsSize;
						}
					} else {
						DWORD	dwWrittenBytes;
						BOOL	bResult = WriteFile( hFile, pvBuf, (unsigned) tsSize, &dwWrittenBytes, NULL );
						if( !bResult || ( dwWrittenBytes < tsSize ) ){
							DWORD	dwErr = GetLastError();
							break;
						}
					}
				}
			}
		}
	}
//	if( ::GetTypeInt() == PE_REDE ){
//		Flush();
//	}
	dwLastUse = GetTickCount();
	if( cCriptoOn ){
		Decrypt( pvBuf, szKey, tsSize );
	}
	if( i < tsNumItens ){
#ifdef _USE_PRINTF_
		Printf( "C_File: Write: E_WRITE." );
#endif
		i = (size_t) E_WRITE;
	}
	if( iFlag ){
		PseudoClose();
		_xFile->ReOpen();
	}
#ifdef _USE_PRINTF_
	Printf( "C_File: Write: Vou retornar %d.", i );
#endif
	return( i );
}
コード例 #19
0
/***
	Le uma linha de um arquivo texto. Para de ler quando acha
	um '\n' ou quando le szMaxlen caracteres. O '\n' nao eh
	deixado dentro do buffer. Em seu lugar, este metodo coloca
	um '\0'. Retorna o numero de caracteres lidos, incluindo o
	'\n'.
***/
size_t
C_File::ReadLine( char FAR *szBuf, size_t stMaxLen )
{
	C_FileCritSect	cCS0( this, CRITSECT0 );
	int iFlag = FALSE;
	if( !szBuf ){
		return( (size_t) E_BUFFNULL );
	}
	if( (_bIs32s && iFile == -1) || (!_bIs32s && hFile == INVALID_HANDLE_VALUE) ){
		if( ReOpen() != OK ){		   
			if( !_xFile ){
				return( 0 );
			}
			_xFile->PseudoClose();
			ReOpen();
			iFlag = TRUE;
		}
	}

	// MMF
	if( !_bIs32s && hMMF ){
		// preparar leitura a partir do MMF
		if( !pWinView ){
			// o arquivo ainda nao esta' mapeado. vamos fazer isso.
			CreateViewOfFile();
		}
	}

	for( size_t i = 0; i < stMaxLen; i++ ){
		if( _bIs32s ){
			if( read( iFile, ( char *) szBuf + i, sizeof( char ) ) < sizeof( char ) ){
				if( i == 0 ){
					if( iFlag ){
						PseudoClose();
						_xFile->ReOpen();
					}
					return( (size_t) EOF );
				}
				break;
			}
		} else {
			if( pWinView ){
				// ler a partir do MMF.
				int	iNumBytes = ((iMMFWinSize * iPageSize) - iSeekWin);
				memcpy( (void*) (( char *) szBuf + sizeof( char ) * i), (void*) ((char*) PWINVIEW + iSeekWin), 
						min( iNumBytes, sizeof( char ) ) );
				if( iNumBytes < sizeof( char ) ){
					// precisamos mapear outra janela e continuar a leitura
					++iWinNum;	// proxima janela
					CreateViewOfFile();
					if( !pWinView ){
						// mapeamento nao foi feito. vamos assumir fim-de-arquivo.
						if( i == 0 ){
							if( iFlag ){
								PseudoClose();
								_xFile->ReOpen();
							}
							return( (size_t) EOF );
						}
						break;
					}
					// ler o restante
					memcpy( (void*) ((( char *) szBuf + sizeof( char ) * i) + iNumBytes), (void*) ((char*) PWINVIEW + iSeekWin), 
							(sizeof( char ) - iNumBytes) );

					iSeekWin += (sizeof( char ) - iNumBytes);
				} else {
					iSeekWin += sizeof( char );
				}
			} else {
				DWORD	dwReadBytes;
				BOOL	bResult = ReadFile( hFile, ( char *) szBuf + i, sizeof( char ), &dwReadBytes, NULL );
				if( !bResult || ( dwReadBytes  < sizeof( char ) ) ){
					if( i == 0 ){
						if( iFlag ){
							PseudoClose();
							_xFile->ReOpen();
						}
						return( (size_t) EOF );
					}
					break;
				}
			}
		}
		if( ((char*)szBuf)[ i ] == '\n' ){
			break;
		}
	}
	if( i > 0 ){
		if( ((char*)szBuf)[ i-1 ] == '\r' ){
			--i;
		}
	}
	dwLastUse = GetTickCount();
	((char*)szBuf)[ i ] = '\0';

	// tirar os espacos em branco e tabs do final
	while( i > 0 && (((char*)szBuf)[ i-1 ] == ' ' || ((char*)szBuf)[ i-1 ] == '\t') ){
		((char*)szBuf)[ --i ] = '\0';
	}
	if( iFlag ){
		PseudoClose();
		_xFile->ReOpen();
	}
	return( i );
}
コード例 #20
0
/***
	Read bytes from a file to a buffer.
	Parameters:
		- pvBuf: User buffer. Contains the result of a read.
		- tsSize: Size of iten to read
		- tsNumItens: Number of itens to read
	Return:
		- O numero de itens lidos (nao o numero de bytes). Em caso
		de erro: E_NOTOPEN or E_BUFFNULL or EOF.
***/
size_t
C_File::Read( void FAR *pvBuf, size_t tsSize, size_t tsNumItens )
{
	C_FileCritSect	cCS0( this, CRITSECT0 );
	int iFlag = FALSE;
	if( !pvBuf ){
		return( (size_t) E_BUFFNULL );
	}
	if( (_bIs32s && iFile == -1) || (!_bIs32s && hFile == INVALID_HANDLE_VALUE) ){
		if( ReOpen() != OK ){
			if( !_xFile ){
				return( 0 );
			}
			_xFile->PseudoClose();
			ReOpen();
			iFlag = TRUE;
		}
	}
	// MMF
	BOOL	bReadHeader = FALSE;
	if( !_bIs32s && hMMF ){
		// preparar leitura a partir do MMF
		if( (CurPos() == iHeadInit)  && ((int) tsSize == iHeadSize) ){
			bReadHeader = TRUE;
			// vamos fazer read no header do arquivo.
			if( !pHeadView ){
				// o header ainda nao esta' mapeado. vamos fazer isso.
				CreateViewOfHead();
			}
		} else {
			if( !pWinView ){
				// o arquivo ainda nao esta' mapeado. vamos fazer isso.
				CreateViewOfFile();
			}
		}
	}

	for( size_t i = 0; i < tsNumItens; i++ ){
		if( _bIs32s ){
			if( read( iFile, ( char *) pvBuf + tsSize * i, tsSize ) < (int) tsSize ){
				break;
			}
		} else {
			if( bReadHeader ){
				// ler header a partir do MMF.
				memcpy( pvBuf, pHeadView, tsSize );
			} else {
				if( pWinView ){
					// ler a partir do MMF.
					int	iNumBytes = ((iMMFWinSize * iPageSize) - iSeekWin) - (iHeadSize + 1);
					memcpy( (void*) (( char *) pvBuf + tsSize * i), (void*) ((char*) PWINVIEW + iSeekWin), 
							min( iNumBytes, ((int) tsSize) ) );
					if( iNumBytes < ((int) tsSize) ){
						// precisamos mapear outra janela e continuar a leitura
						++iWinNum;	// proxima janela
						CreateViewOfFile();
						if( !pWinView ){
							// mapeamento nao foi feito. vamos assumir fim-de-arquivo.
							break;
						}
						// ler o restante
						memcpy( (void*) ((( char *) pvBuf + tsSize * i) + iNumBytes), (void*) ((char*) PWINVIEW + iSeekWin), 
								(tsSize - iNumBytes) );

						iSeekWin += (tsSize - iNumBytes);
					} else {
						iSeekWin += tsSize;
					}
				} else {
					// ler direto do arquivo
					DWORD	dwReadBytes;
					BOOL	bResult = ReadFile( hFile, ( char *) pvBuf + tsSize * i, tsSize, &dwReadBytes, NULL );
					if( !bResult || ( dwReadBytes  < tsSize ) ){
						break;
					}
				}
			}
		}
	}
	dwLastUse = GetTickCount();
	if( cCriptoOn && i >= tsNumItens ){
		Decrypt( pvBuf, szKey, tsSize * tsNumItens );
	}
	if( i < tsNumItens ){
		i = (size_t) EOF;
	}
	if( iFlag ){
		PseudoClose();
		_xFile->ReOpen();
	}
	return( i );
}
コード例 #21
0
ファイル: StreamIO.cpp プロジェクト: mesoto/PPK
int CStreamIO::Open( char * name, char * mode )
{
    GetFullPathName( name, sizeof(full_path), (LPSTR)full_path, (LPSTR*)&file_name );
    return ReOpen( mode );
}