home *** CD-ROM | disk | FTP | other *** search
- /******************************************
- * COPEN.C *
- * Copyright TimeSlice, Inc. 1985, 86, 87. *
- ******************************************/
-
- #include <ts.h>
- #include <itsmem.h>
- #include <stdio.h>
- /***
- * COPEN( CHAR *CNAME , INT CSIZ ) - This function first checks to see
- * if channel CNAME already exists. If no channel CNAME exists, it allocates one
- * of CSIZ bytes and inserts it at the front of the list pointed by _CFRNT.
- * If one already exists, it simply increments the CNAME->openlev.
- * In both cases, a pointer to the CHAN structure is returned
- ***/
- CHAN *copen( cname , csiz )
- char *cname ;
- int csiz ;
- {
- CHAN *cn ;
-
- /** search for CNAME **/
- critstart( DOS_CRCLASS ) ;
- for( cn = _chfrnt ; cn && strncmp(cn->cname, cname, CNSIZ) ; cn = cn->nxt)
- ;
- if ( cn ) /* does cname exists ? */
- cn->openlev++ ; /* yes, just incr openlevel */
- else {
- #if defined(TURBOC)
- if ( cn = (CHAN *)_ts_malloc( sizeof(CHAN) ) ) {
- #else
- if ( cn = (CHAN *)ITS_ALLOC(mem_XMS, sizeof(CHAN) ) ) {
- #endif
- if ( cn->q.buf = ITS_ALLOC(mem_XMS, csiz ) ) {
- cn->nxt = _chfrnt ; /* insert channel in list */
- _chfrnt = cn ;
- strncpy( cn->cname , cname , CNSIZ ) ;
- cn->openlev = 1; /* first time its opened */
- cn->rf = cn->wf = NULL; /* okay to read and write */
- cn->q.bot = cn->q.top = cn->q.ahead = NULL ;
- cn->q.size = csiz ;
- cn->q.full = 0 ;
- cn->q.empty = 1 ;
- } else {
- #if defined(TURBOC)
- _ts_free( (char *)cn ) ;
- #else
- ITS_FREE( (char *)cn ) ;
- #endif
- cn = NULL ;
- }
- }
- }
- critend( DOS_CRCLASS ) ;
- return cn ;
- }
-