xp_comm_proj/dlgtools/read/ram.c
/*********************************************************************

  create a new empty block

  no input error checking

*********************************************************************/
create a new empty block
no input error checking
create a new empty block no input error checking
Ram_Block_Data *ram_add_block( int block_number, size_t block_size )
{
  Ram_Block_Data *this_block;
  this_block = (Ram_Block_Data *) malloc( sizeof(Ram_Block_Data) );
  if( this_block == NULL )
    {
      error_message[0] = '\0';
      sprintf( error_message+strlen(error_message),
              "Block %i\nmalloc failure: can't malloc %i bytes for the block structure", block_number, sizeof(Ram_Block_Data) );
      ALF(error_message);
      P_MESS( "ram_add_block", error_message  );
      return( NULL );
    }
  this_block->head = (char *) malloc( block_size );
  if( this_block->head == NULL )
    {
      error_message[0] = '\0';
      sprintf( error_message+strlen(error_message),
              "Block %i\nmalloc failure: can't malloc %i bytes for the block data", block_number, block_size );
      ALF(error_message);
      P_MESS( "ram_block_add", error_message  );
      return( NULL );
    }
  this_block->tail = this_block->head;
  this_block->size = block_size;
  this_block->used = 0;
  this_block->left = block_size;
  this_block->next = NULL;
  return( this_block );
}
Ram_Block_Data * ram_add_block ( int block_number , size_t block_size ) { Ram_Block_Data * this_block ; this_block = ( Ram_Block_Data * ) malloc ( sizeof ( Ram_Block_Data ) ) ; if ( this_block == NULL ) { error_message [ 0 ] = ' \0 ' ; sprintf ( error_message + strlen ( error_message ) , " \n " , block_number , sizeof ( Ram_Block_Data ) ) ; ALF ( error_message ) ; P_MESS ( " " , error_message ) ; return ( NULL ) ; } this_block -> head = ( char * ) malloc ( block_size ) ; if ( this_block -> head == NULL ) { error_message [ 0 ] = ' \0 ' ; sprintf ( error_message + strlen ( error_message ) , " \n " , block_number , block_size ) ; ALF ( error_message ) ; P_MESS ( " " , error_message ) ; return ( NULL ) ; } this_block -> tail = this_block -> head ; this_block -> size = block_size ; this_block -> used = 0 ; this_block -> left = block_size ; this_block -> next = NULL ; return ( this_block ) ; }
create a new empty block
no input error checking
create a new empty block no input error checking
/* get the structure for the block */ /* get the memory for the block */ /* initialize the remaining parts of the structure */ /* return the new block number */