int __doclose( FILE *fp, int close_handle ) { int ret; if( (fp->_flag & (_READ | _WRITE)) == 0 ) { return( -1 ); /* file already closed */ } ret = 0; if( fp->_flag & _DIRTY ) { if( __flush( fp ) ) { ret = -1; } } _AccessFile( fp ); /* * 02-nov-92 G.Turcotte Syncronize buffer pointer with the file pointer * IEEE Std 1003.1-1988 B.8.2.3.2 * 03-nov-03 B.Oldeman Inlined ftell; we already know the buffer isn't * dirty (because of the flush), so only a "get" applies */ if( fp->_cnt != 0 ) { /* if something in buffer */ __lseek( fileno( fp ), -fp->_cnt, SEEK_CUR ); } if( close_handle ) { #if defined( __UNIX__ ) || defined( __NETWARE__ ) || defined( __RDOS__ ) || defined( __RDOSDEV__ ) // we don't get to implement the close function on these systems ret |= close( fileno( fp ) ); #else ret |= __close( fileno( fp ) ); #endif } if( fp->_flag & _BIGBUF ) { /* if we allocated the buffer */ lib_free( _FP_BASE( fp ) ); _FP_BASE( fp ) = NULL; } #ifndef __UNIX__ /* this never happens under UNIX */ if( fp->_flag & _TMPFIL ) { /* if this is a temporary file */ __RmTmpFileFn( fp ); } #endif fp->_flag &= _DYNAMIC; _ReleaseFile( fp ); return( ret ); }
int __doclose( FILE *fp, int close_handle ) { int ret; if( fp->_flag == 0 ) { return( -1 ); /* file already closed */ } ret = 0; if( fp->_flag & _DIRTY ) { ret = __flush( fp ); } _AccessFile( fp ); if( fp->_cnt != 0 ) { /* if something in buffer */ __lseek( fileno( fp ), -fp->_cnt, SEEK_CUR ); } if( close_handle ) { #if defined(__UNIX__) || defined(__NETWARE__) // we don't get to implement the close function on these systems ret |= close( fileno( fp ) ); #else ret |= __close( fileno( fp ) ); #endif } if( fp->_flag & _BIGBUF ) { /* if we allocated the buffer */ lib_free( _FP_BASE(fp) ); _FP_BASE(fp) = NULL; } #ifndef __UNIX__ /* this never happens under UNIX */ if( fp->_flag & _TMPFIL ) { /* if this is a temporary file */ __RmTmpFileFn( fp ); } #endif _ReleaseFile( fp ); return( ret ); }