void * super_block_t::new_block(size_t count)
	{
		if (avail_space() == 0)
		{
			throw std::runtime_error("out of blocks");
		}

		if (count > get_block_size())
		{
			throw std::invalid_argument("incorrect block size");
		}

		void * result = header.avail;
		header.avail = header.avail->next;
		header.blocks_avail--;
		return result;
	}
Example #2
0
// START FUNC DECL
int
open_file_in_dir(
		 char *cwd,
		 char *dir,
		 char *fname,
		 size_t filesize
		 )
// STOP FUNC DECL
{
  int status = 0;

  if ( cwd == NULL ) { go_BYE(-1); }
  if ( dir == NULL ) { go_BYE(-1); }
  if ( fname == NULL ) { go_BYE(-1); }
  FILE *fp = NULL;
  
  if ( filesize > 0 ) {
    /* Check that there is space to write */
    size_t space_available;
    status = avail_space(dir, &space_available); cBYE(status);
    if ( space_available <= filesize  ) {
      fprintf(stderr, "Space (%lld bytes) in directory [%s] not available \n", 
	      (long long)filesize, dir);
      go_BYE(-1);
    }
  }
  /* Check that directory is accessible */
  status = chdir(dir); cBYE(status);
  if ( status != 0 ) { 
    fprintf(stderr, "Directory [%s] not accessible \n", dir);
    go_BYE(-1);
  }
  // Create temp file 
  fp = fopen(fname, "wb"); 
  return_if_fopen_failed(fp,  fname, "wb"); 
  fclose_if_non_null(fp);
  // Get back to where you once belonged
  status = chdir(cwd); cBYE(status);
 BYE:
  return(status);
}
Example #3
0
std::unique_ptr<RenderQueue> BREW::CreateLabelDrawable( std::shared_ptr<const Label> label ) const {
	const auto& font_name = GetProperty<std::string>( "FontName", label );
	const auto& font = GetResourceManager().GetFont( font_name );
	auto font_size = GetProperty<unsigned int>( "FontSize", label );
	auto font_color = GetProperty<sf::Color>( "Color", label );

	std::unique_ptr<RenderQueue> queue( new RenderQueue );

	sf::Text vis_label( label->GetWrappedText(), *font, font_size );
	vis_label.setColor( font_color );

	if( !label->GetLineWrap() ) {
		// Calculate alignment when word wrap is disabled.
		sf::Vector2f avail_space( label->GetAllocation().width - label->GetRequisition().x, label->GetAllocation().height - label->GetRequisition().y );
		sf::Vector2f position( avail_space.x * label->GetAlignment().x, avail_space.y * label->GetAlignment().y );

		vis_label.setPosition( position.x, position.y );
	}

	queue->Add( Renderer::Get().CreateText( vis_label ) );

	return queue;
}
Example #4
0
// START FUNC DECL
int
open_temp_file(
	       char *fname,
	       size_t filesize
	       )
// STOP FUNC DECL
{
  int status = 0;
  char cwd[MAX_LEN_DIR_NAME+1];
  int fd; 
  char *file_dir = NULL;
  size_t space_available = 0;
  char *data_dir = getenv("Q_DATA_DIR");

  if ( data_dir == NULL ) { go_BYE(-1); }
  zero_string(cwd, MAX_LEN_DIR_NAME+1);
  getcwd(cwd, MAX_LEN_DIR_NAME);
  if ( strlen(cwd) == 0 ) { go_BYE(-1); }
  
  if ( ( filesize > 0 ) && ( g_write_to_temp_dir ) ) {
    file_dir = getenv("Q_TEMP_DIR");
    if ( file_dir == NULL ) { 
      file_dir = data_dir;
    }
    else { 
      /* Check that direcory is accessible */
      status = chdir(file_dir);
      if ( status != 0 ) { 
        fprintf(stderr, "temp dir [%s] not accessible \n", file_dir);
        file_dir = data_dir;
      }
      else {
	/* Check that there is space to write */
	char *tempfs_root = getenv("Q_TEMPFS_ROOT");
	if ( tempfs_root == NULL ) { go_BYE(-1); }
	status = avail_space(tempfs_root, &space_available); cBYE(status);
	if ( space_available <= filesize  ) {
	  /* No space on temp dir. Use DATA_DIR instead */
	  file_dir = data_dir;
	}
      }
      status = chdir(cwd);
    }
  }
  else {
    file_dir = data_dir;
  }
  // Some basic checks 
  if ( ( file_dir == NULL ) || ( *file_dir == '\0' ) ) { go_BYE(-1); }
  status = chdir(file_dir);
  if ( status != 0 ) { 
    fprintf(stderr, "Unable to cd to dir [%s] \n", file_dir);
    go_BYE(-1);
  }
  // Create temp file 
  strcat(fname, "_tempf_XXXXXX");
  fd = mkstemp(fname);
  close(fd);
  // Get back to where you once belonged
  status = chdir(cwd); cBYE(status);

 BYE:
  return(status);
}