home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / s / s001 / 1.ddi / TS / SRC / CCLOSE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-07  |  1014 b   |  38 lines

  1.                  /******************************************
  2.            *            CCLOSE.C             *
  3.                * Copyright TimeSlice, Inc. 1985, 86, 87. *
  4.                ******************************************/
  5.  
  6. #include <ts.h>
  7. #include <itsmem.h>
  8. #include <stdio.h>
  9.  
  10. /***
  11. * CCLOSE( CHAN *CN )  - This function decrements CN->OPENLEV. If C->OPENLEV == 0
  12. * and CN->Q->EMPTY == TRUE, then the channel is de-allocated. 
  13. ***/
  14. int    cclose( cn )
  15. CHAN    *cn ;
  16. {
  17.     CHAN  *cn2, *flag;
  18.  
  19.     critstart( DOS_CRCLASS ) ;
  20.     for( cn2 = (CHAN *)&_chfrnt ; cn2->nxt && cn2->nxt != cn ;cn2 = cn2->nxt )
  21.         ;
  22.     if ( flag = cn2->nxt ) {            /* was cn found ? */
  23.     if ( (!--cn->openlev) && (cn->q.empty ) ) {
  24.        cn2->nxt = cn->nxt ;    /* remove cn from linked list */    
  25. #if defined(TURBOC)
  26.        _ts_free( cn->q.buf ) ;
  27.        _ts_free( (char *)cn ) ;
  28. #else
  29.        ITS_FREE( cn->q.buf ) ;
  30.        ITS_FREE( (char *)cn ) ;
  31. #endif
  32.     } else
  33.        crel( cn ) ;
  34.     }         
  35.     critend( DOS_CRCLASS ) ;
  36.     return( flag != NULL );
  37. }
  38.