rtsysutl.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 615 行 · 第 1/2 页
C
615 行
if( fcb->accmode == ACCM_APPEND ) {
attrs |= APPEND;
} else if( fcb->accmode == ACCM_DIRECT ) {
attrs |= SEEK;
}
if( fcb->action == ACTION_READ ) {
attrs |= RDONLY;
} else if( fcb->action == ACTION_WRITE ) {
attrs |= WRONLY;
} else {
attrs |= RDWR;
}
return( attrs );
}
//
// The above "open" routines correspond to WATFOR-77 "ACTION=" specifiers.
//
void CloseFile( ftnfile *fcb ) {
//=================================
// Close a 'ftnfile'.
file_handle fh;
if( fcb->fileptr == NULL ) return;
if( fcb->fileptr == FStdIn ) return;
if( fcb->fileptr == FStdOut ) {
// check if standard output device redirected to a disk file
if( ((a_file *)(fcb->fileptr))->attrs & BUFFERED ) {
FlushBuffer( fcb->fileptr );
ChkIOErr( fcb );
}
return;
}
if( fcb->fileptr == FStdErr ) return;
Closef( fcb->fileptr );
// save file handle
fh = fcb->fileptr;
// set file handle in fcb to NULL - we don't want
// to get the i/o status from the file handle since
// it will no longer be valid if the close succeeded
fcb->fileptr = NULL;
if( GetIOErr( fcb ) ) {
// close failed so restore file handle in fcb
fcb->fileptr = fh;
IOErr( IO_FILE_PROBLEM );
}
}
bool Scrtched( ftnfile *fcb ) {
//================================
// Erase specified file.
Scratchf( fcb->filename );
return( Errorf( NULL ) == IO_OK );
}
void CloseDeleteFile( ftnfile *fcb ) {
//=======================================
// Close and delete 'ftnfile'.
int win_con = FALSE;
#if defined( __IS_WINDOWED__ )
if( fcb->fileptr ) {
win_con = _dwDeleteOnClose( ((a_file *)(fcb->fileptr))->handle );
}
#endif
CloseFile( fcb );
if( win_con ) return;
if( Scrtched( fcb ) ) return;
IOErr( IO_FILE_PROBLEM );
}
bool Errf( ftnfile *fcb ) {
//============================
// Determine if an i/o error exists.
bool err;
err = Errorf( fcb->fileptr );
if( err == IO_EOF ) {
SetEOF();
err = IO_OK;
}
return( err != IO_OK );
}
void FPutBuff( ftnfile *fcb ) {
//================================
// Write a record to a file.
if( IOCB->flags & IOF_NOCR ) {
((a_file *)fcb->fileptr)->attrs |= CC_NOCR;
}
if( fcb->flags & FTN_LOGICAL_RECORD ) {
((a_file *)fcb->fileptr)->attrs |= LOGICAL_RECORD;
}
FPutRec( fcb->fileptr, fcb->buffer, fcb->col );
if( IOCB->flags & IOF_NOCR ) {
((a_file *)fcb->fileptr)->attrs &= ~CC_NOCR;
}
((a_file *)fcb->fileptr)->attrs &= ~( TRUNC_ON_WRITE | LOGICAL_RECORD );
}
void FGetBuff( ftnfile *fcb ) {
//================================
// Read a record from a file.
if( _NoRecordOrganization( fcb ) ) {
fcb->len = FGetRec( fcb->fileptr, fcb->buffer, fcb->len );
} else {
fcb->len = FGetRec( fcb->fileptr, fcb->buffer, fcb->bufflen );
}
}
void SeekFile( ftnfile *fcb ) {
//================================
// Position file to specified record.
FSeekRec( fcb->fileptr, fcb->recnum - 1, fcb->bufflen );
}
bool NoEOF( ftnfile *fcb ) {
//=============================
// Determine if file has an EOF (SERIAL, TERMINAL).
if( fcb->fileptr == NULL ) return( FALSE );
return( IsDevice( fcb ) );
}
void SysClearEOF( ftnfile *fcb ) {
//===================================
// Clear EOF on file with no EOF (SERIAL, TERMINAL).
IOOk( fcb->fileptr );
#if defined( __DOS__ )
if( ( fcb->fileptr == FStdIn ) && IsDevice( fcb ) ) {
// DOS bug: if a read from stdin causes eof, all subsequent reads
// will also cause eof unless we write to stdout
write( ((a_file *)FStdOut)->handle, 0, 0 );
}
#endif
}
bool SameFile( char *fn1, char *fn2 ) {
//========================================
// Determine if file specifications are for the same file.
#if defined( __UNIX__ )
return( strcmp( fn1, fn2 ) == 0 );
#else
return( stricmp( fn1, fn2 ) == 0 );
#endif
}
void Rewindf( ftnfile *fcb ) {
//===============================
// System dependent rewind.
if( fcb->fileptr != NULL ) {
ChkDisk( fcb );
FRewind( fcb->fileptr );
((a_file *)fcb->fileptr)->attrs |= TRUNC_ON_WRITE;
}
}
void SysCreateFile( ftnfile *fcb ) {
//=====================================
// Cause the file to exist in the file system.
fcb->fileptr = Openf( fcb->filename, REC_TEXT | WRONLY );
if( fcb->fileptr != NULL ) {
Closef( fcb->fileptr );
fcb->fileptr = NULL;
fcb->flags |= FTN_FSEXIST;
} else {
IOErr( IO_FILE_PROBLEM );
}
}
bool CheckLogicalRecord( ftnfile *fcb ) {
//=========================================
int rc;
rc = FCheckLogical( fcb->fileptr );
ChkIOErr( fcb );
return( rc );
}
void SkipLogicalRecord( ftnfile *fcb ) {
//=========================================
if( fcb->fileptr != NULL ) {
FSkipLogical( fcb->fileptr );
ChkIOErr( fcb );
}
}
void BackSpacef( ftnfile *fcb ) {
//==================================
// System dependent file backspace.
if( fcb->fileptr != NULL ) {
ChkDisk( fcb );
FBackspace( fcb->fileptr, fcb->bufflen );
((a_file *)fcb->fileptr)->attrs |= TRUNC_ON_WRITE;
}
}
void EndFilef( ftnfile *fcb ) {
//================================
// Chop the file off at it current position.
if( fcb->fileptr != NULL ) {
FTruncate( fcb->fileptr );
((a_file *)fcb->fileptr)->attrs &= ~TRUNC_ON_WRITE;
}
}
static void ChkDisk( ftnfile *fcb ) {
//=======================================
// Make sure that the file is a disk file.
if( IsDevice( fcb ) ) {
FSetErr( IO_BAD_OPERATION, fcb->fileptr );
}
}
void GetIOErrMsg( ftnfile *fcb, char *buff ) {
//===============================================
// Get i/o error message.
file_handle fp;
if( fcb == NULL ) {
fp = NULL;
} else {
fp = fcb->fileptr;
}
strcpy( buff, ErrorMsg( fp ) );
}
void ReportNExist( ftnfile *fcb ) {
//====================================
// Set i/o error condition to "file not found".
errno = ENOENT;
FSetSysErr( fcb->fileptr );
}
void ReportEOF( ftnfile *fcb ) {
//=================================
// Set i/o error condition to "end-of-file".
FSetEof( fcb->fileptr );
}
void WaitForEnter( void ) {
//======================
while( GetStdChar() != '\n' ) {
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?