home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / s / s001 / 1.ddi / TS / SRC / COPEN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-11  |  1.7 KB  |  57 lines

  1.                  /******************************************
  2.            *            COPEN.C             *
  3.                * Copyright TimeSlice, Inc. 1985, 86, 87. *
  4.                ******************************************/
  5.  
  6. #include <ts.h>
  7. #include <itsmem.h>
  8. #include <stdio.h>
  9. /***
  10. * COPEN( CHAR *CNAME , INT CSIZ ) - This function first checks to see
  11. * if channel CNAME already exists. If no channel CNAME exists, it allocates one
  12. * of CSIZ bytes and inserts it at the front of the list pointed by _CFRNT. 
  13. * If one already exists, it simply increments the CNAME->openlev.
  14. * In both cases, a pointer to the CHAN structure is returned 
  15. ***/
  16. CHAN    *copen( cname , csiz )
  17. char    *cname ;            
  18. int    csiz ;
  19. {
  20.     CHAN *cn ;
  21.  
  22.     /** search for CNAME **/
  23.     critstart( DOS_CRCLASS ) ;
  24.     for( cn = _chfrnt ; cn && strncmp(cn->cname, cname, CNSIZ) ; cn = cn->nxt) 
  25.         ;
  26.     if ( cn )                 /* does cname exists ? */
  27.         cn->openlev++ ;            /* yes, just incr openlevel */
  28.     else {
  29. #if defined(TURBOC)
  30.     if ( cn = (CHAN *)_ts_malloc( sizeof(CHAN) ) ) {
  31. #else
  32.     if ( cn = (CHAN *)ITS_ALLOC(mem_XMS, sizeof(CHAN) ) ) {
  33. #endif
  34.         if ( cn->q.buf = ITS_ALLOC(mem_XMS, csiz ) ) {
  35.             cn->nxt = _chfrnt ;    /* insert channel in list */
  36.         _chfrnt = cn ;
  37.         strncpy( cn->cname , cname , CNSIZ ) ;
  38.         cn->openlev = 1;    /* first time its opened */
  39.         cn->rf = cn->wf = NULL; /* okay to read and write */
  40.         cn->q.bot = cn->q.top = cn->q.ahead = NULL ;
  41.         cn->q.size = csiz ;
  42.         cn->q.full = 0 ;
  43.         cn->q.empty = 1 ;
  44.         } else {
  45. #if defined(TURBOC)
  46.             _ts_free( (char *)cn ) ;
  47. #else
  48.         ITS_FREE( (char *)cn ) ;
  49. #endif
  50.         cn = NULL ;
  51.         }
  52.     }
  53.     }
  54.     critend( DOS_CRCLASS ) ;
  55.     return cn ;
  56. }
  57.