Example #1
0
int __shutdown_stream( FILE *fp, int close_handle )
{
    int         ret;

    ret = __doclose( fp, close_handle );
    __freefp( fp );
    return( ret );
}
Example #2
0
static FILE *close_file( FILE *fp )
{
    __stream_link * link;
    __stream_link **owner;

    _AccessIOB();
    /* See if the file pointer is a currently open file. */
    link = _RWD_ostream;
    for( ;; ) {
        if( link == NULL ) break;
        if( link->stream == fp ) {
            if( fp->_flag & (_READ|_WRITE) ) {
                __doclose( fp, 1 );
            }
            _ReleaseIOB();
            return( fp );
        }
        link = link->next;
    }
    /*
       It's not on the list of open files, so check the list of
       recently closed ones.
    */
    owner = &_RWD_cstream;
    for( ;; ) {
        link = *owner;
        if( link == NULL ) break;
        if( link->stream == fp ) {
            /* remove from closed list and put on open */
            *owner = link->next;
            link->next = _RWD_ostream;
            _RWD_ostream = link;
            _ReleaseIOB();
            return( fp );
        }
        owner = &link->next;
    }
    /* We ain't seen that file pointer ever. Leave things be. */
    __set_errno( EBADF );
    _ReleaseIOB();
    return( NULL );
}