1 // vim: noet sw=4 ts=4:
3 ==================================================================================
4 Copyright (c) 2020 Nokia
5 Copyright (c) 2020 AT&T Intellectual Property.
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18 ==================================================================================
22 *******************************************************************************
25 * Abstract: This routine is responsible for alocating a new block based on
26 * the block type and initializing it.
27 * Parms: type - Block id to create
28 * Returns: Pointer to the new block or NULL if not successful
30 * Author: E. Scott Daniels
31 * Mod: 22 Feb 2002 - To ensure new field in tp block is initialised
33 ******************************************************************************
37 extern void *SInew( int type ) {
38 void *retptr; // generic pointer for return
39 struct tp_blk *tpptr; // pointer at a new tp block
40 struct ginfo_blk *gptr; // pointer at gen info blk
41 struct ioq_blk *qptr; // pointer to an I/O queue block
44 case IOQ_BLK: // make an I/O queue block
45 if( (qptr = (struct ioq_blk *) malloc( sizeof( struct ioq_blk) )) != NULL ) {
51 retptr = (void *) qptr; // set pointer for return
55 if( (tpptr = (struct tp_blk *) malloc( sizeof( struct tp_blk ) )) != NULL ) {
56 memset( tpptr, 0, sizeof( *tpptr ) );
59 tpptr->flags = TPF_UNBIND; // default to unbind on termination
61 retptr = (void *) tpptr; // setup for later return
64 case GI_BLK: // create global info block
65 if( (gptr = (struct ginfo_blk *) malloc( sizeof( struct ginfo_blk ) )) != NULL ) {
66 memset( gptr, 0, sizeof( *gptr ) );
68 gptr->magicnum = MAGICNUM; // inidicates valid block
71 FD_ZERO( &gptr->readfds); // clear the fdsets
72 FD_ZERO( &gptr->writefds) ;
73 FD_ZERO( &gptr->execpfds );
74 gptr->rbuf = NULL; // no read buffer
79 retptr = (void *) gptr; // set up for return at end
83 retptr = NULL; // bad type - just return null
87 return( retptr ); // send back the new pointer