示例#1
0
/* create a .o file that references all the undefined symbols we want to resolve */
static char *create_undef_symbols_file( DLLSPEC *spec )
{
    char *as_file, *obj_file;
    int i;
    unsigned int j;
    FILE *f;

    as_file = get_temp_file_name( output_file_name, ".s" );
    if (!(f = fopen( as_file, "w" ))) fatal_error( "Cannot create %s\n", as_file );
    fprintf( f, "\t.data\n" );

    for (i = 0; i < spec->nb_entry_points; i++)
    {
        ORDDEF *odp = &spec->entry_points[i];
        if (odp->type == TYPE_STUB || odp->type == TYPE_ABS || odp->type == TYPE_VARIABLE) continue;
        if (odp->flags & FLAG_FORWARD) continue;
        fprintf( f, "\t%s %s\n", get_asm_ptr_keyword(), asm_name(odp->link_name) );
    }
    for (j = 0; j < extra_ld_symbols.count; j++)
        fprintf( f, "\t%s %s\n", get_asm_ptr_keyword(), asm_name(extra_ld_symbols.names[j]) );
    fclose( f );

    obj_file = get_temp_file_name( output_file_name, ".o" );
    assemble_file( as_file, obj_file );
    return obj_file;
}
示例#2
0
/* output an import library for a Win32 module and additional object files */
void output_import_lib( DLLSPEC *spec, char **argv )
{
    struct strarray *args = strarray_init();
    char *def_file;

    if (target_platform != PLATFORM_WINDOWS)
        fatal_error( "Unix-style import libraries not supported yet\n" );

    def_file = get_temp_file_name( output_file_name, ".def" );
    fclose( output_file );
    if (!(output_file = fopen( def_file, "w" )))
        fatal_error( "Unable to create output file '%s'\n", def_file );
    output_def_file( spec, 0 );
    fclose( output_file );
    output_file = NULL;

    strarray_add( args, find_tool( "dlltool", NULL ), "-k", "-l", output_file_name, "-d", def_file, NULL );
    spawn( args );
    strarray_free( args );

    if (argv[0])
    {
        args = strarray_init();
        strarray_add( args, find_tool( "ar", NULL ), "rs", output_file_name, NULL );
        strarray_addv( args, argv );
        spawn( args );
        strarray_free( args );
    }
    output_file_name = NULL;
}
int main()
{
    std::string temp = get_temp_file_name();
    {
        std::fstream fs;
        assert(!fs.is_open());
        fs.open(temp, std::ios_base::in | std::ios_base::out
                                                     | std::ios_base::trunc);
        assert(fs.is_open());
        double x = 0;
        fs << 3.25;
        fs.seekg(0);
        fs >> x;
        assert(x == 3.25);
    }
    std::remove(temp.c_str());
    {
        std::wfstream fs;
        assert(!fs.is_open());
        fs.open(temp, std::ios_base::in | std::ios_base::out
                                                     | std::ios_base::trunc);
        assert(fs.is_open());
        double x = 0;
        fs << 3.25;
        fs.seekg(0);
        fs >> x;
        assert(x == 3.25);
    }
    std::remove(temp.c_str());
}
示例#4
0
std::pair<std::string, std::string> get_temp_file_names() {
  std::pair<std::string, std::string> names;
  names.first = get_temp_file_name();

  // Create the file so the next call to `get_temp_file_name()` doesn't
  // return the same file.
  std::FILE *fd1 = std::fopen(names.first.c_str(), "w");

  names.second = get_temp_file_name();
  assert(names.first != names.second);

  std::fclose(fd1);
  std::remove(names.first.c_str());

  return names;
}
示例#5
0
/* returns the name of the combined file */
static const char *ldcombine_files( DLLSPEC *spec, char **argv )
{
    char *ld_tmp_file, *undef_file;
    struct strarray *args = get_ld_command();

    undef_file = create_undef_symbols_file( spec );
    ld_tmp_file = get_temp_file_name( output_file_name, ".o" );

    strarray_add( args, "-r", "-o", ld_tmp_file, undef_file, NULL );
    strarray_addv( args, argv );
    spawn( args );
    strarray_free( args );
    return ld_tmp_file;
}
示例#6
0
int main(int, char**) {
  fs::path p = get_temp_file_name();
  {
    std::ofstream fs;
    assert(!fs.is_open());
    char c = 'a';
    fs << c;
    assert(fs.fail());
    fs.open(p);
    assert(fs.is_open());
    fs << c;
  }
  {
    std::ifstream fs(p.c_str());
    char c = 0;
    fs >> c;
    assert(c == 'a');
  }
  std::remove(p.c_str());
  {
    std::wofstream fs;
    assert(!fs.is_open());
    wchar_t c = L'a';
    fs << c;
    assert(fs.fail());
    fs.open(p);
    assert(fs.is_open());
    fs << c;
  }
  {
    std::wifstream fs(p.c_str());
    wchar_t c = 0;
    fs >> c;
    assert(c == L'a');
  }
  std::remove(p.c_str());

  return 0;
}
示例#7
0
int main()
{
    std::string temp = get_temp_file_name();
    {
        std::ofstream fs(temp);
        fs << 3.25;
    }
    {
        std::ifstream fs(temp);
        double x = 0;
        fs >> x;
        assert(x == 3.25);
    }
    {
        std::ifstream fs(temp, std::ios_base::out);
        double x = 0;
        fs >> x;
        assert(x == 3.25);
    }
    std::remove(temp.c_str());
    {
        std::wofstream fs(temp);
        fs << 3.25;
    }
    {
        std::wifstream fs(temp);
        double x = 0;
        fs >> x;
        assert(x == 3.25);
    }
    {
        std::wifstream fs(temp, std::ios_base::out);
        double x = 0;
        fs >> x;
        assert(x == 3.25);
    }
    std::remove(temp.c_str());
}
int main(int, char**)
{
    std::string temp = get_temp_file_name();
    {
        std::filebuf f;
        assert(f.open(temp.c_str(), std::ios_base::out | std::ios_base::in
                                               | std::ios_base::trunc) != 0);
        assert(f.is_open());
        assert(f.sputn("123", 3) == 3);
        f.pubseekoff(1, std::ios_base::beg);
        assert(f.sgetc() == '2');
        std::filebuf f2;
        swap(f2, f);
        assert(!f.is_open());
        assert(f2.is_open());
        assert(f2.sgetc() == '2');
    }
    std::remove(temp.c_str());
    {
        std::wfilebuf f;
        assert(f.open(temp.c_str(), std::ios_base::out | std::ios_base::in
                                               | std::ios_base::trunc) != 0);
        assert(f.is_open());
        assert(f.sputn(L"123", 3) == 3);
        f.pubseekoff(1, std::ios_base::beg);
        assert(f.sgetc() == L'2');
        std::wfilebuf f2;
        swap(f2, f);
        assert(!f.is_open());
        assert(f2.is_open());
        assert(f2.sgetc() == L'2');
    }
    std::remove(temp.c_str());

  return 0;
}
示例#9
0
int main(int, char**) {

  fs::path p = get_temp_file_name();
  {
    std::filebuf f;
    assert(f.open(p, std::ios_base::out) != 0);
    assert(f.is_open());
    assert(f.sputn("123", 3) == 3);
  }
  {
    std::filebuf f;
    assert(f.open(p, std::ios_base::in) != 0);
    assert(f.is_open());
    assert(f.sbumpc() == '1');
    assert(f.sbumpc() == '2');
    assert(f.sbumpc() == '3');
  }
  std::remove(p.c_str());
  {
    std::wfilebuf f;
    assert(f.open(p, std::ios_base::out) != 0);
    assert(f.is_open());
    assert(f.sputn(L"123", 3) == 3);
  }
  {
    std::wfilebuf f;
    assert(f.open(p, std::ios_base::in) != 0);
    assert(f.is_open());
    assert(f.sbumpc() == L'1');
    assert(f.sbumpc() == L'2');
    assert(f.sbumpc() == L'3');
  }
  remove(p.c_str());

  return 0;
}
示例#10
0
int main(int, char**)
{
    std::string temp = get_temp_file_name();
    {
        std::fstream fs;
        assert(!fs.is_open());
        fs.open(temp.c_str(), std::ios_base::out);
        assert(fs.is_open());
        fs.close();
        assert(!fs.is_open());
    }
    std::remove(temp.c_str());
    {
        std::wfstream fs;
        assert(!fs.is_open());
        fs.open(temp.c_str(), std::ios_base::out);
        assert(fs.is_open());
        fs.close();
        assert(!fs.is_open());
    }
    std::remove(temp.c_str());

  return 0;
}
示例#11
0
文件: res32.c 项目: bilboed/wine
/* output the resources into a .o file */
void output_res_o_file( DLLSPEC *spec )
{
    unsigned int i;
    char *res_file = NULL;
    int fd, err;

    if (!spec->nb_resources) fatal_error( "--resources mode needs at least one resource file as input\n" );
    if (!output_file_name) fatal_error( "No output file name specified\n" );

    byte_swapped = 0;
    init_output_buffer();

    put_dword( 0 );      /* ResSize */
    put_dword( 32 );     /* HeaderSize */
    put_word( 0xffff );  /* ResType */
    put_word( 0x0000 );
    put_word( 0xffff );  /* ResName */
    put_word( 0x0000 );
    put_dword( 0 );      /* DataVersion */
    put_word( 0 );       /* Memory options */
    put_word( 0 );       /* Language */
    put_dword( 0 );      /* Version */
    put_dword( 0 );      /* Characteristics */

    for (i = 0; i < spec->nb_resources; i++)
    {
        unsigned int header_size = get_resource_header_size( &spec->resources[i] );

        put_dword( spec->resources[i].data_size );
        put_dword( (header_size + 3) & ~3 );
        put_string( &spec->resources[i].type );
        put_string( &spec->resources[i].name );
        align_output( 4 );
        put_dword( 0 );
        put_word( spec->resources[i].mem_options );
        put_word( spec->resources[i].lang );
        put_dword( 0 );
        put_dword( 0 );
        put_data( spec->resources[i].data, spec->resources[i].data_size );
        align_output( 4 );
    }

    /* if the output file name is a .res too, don't run the results through windres */
    if (strendswith( output_file_name, ".res"))
    {
        flush_output_buffer();
        return;
    }

    res_file = get_temp_file_name( output_file_name, ".res" );
    if ((fd = open( res_file, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0600 )) == -1)
        fatal_error( "Cannot create %s\n", res_file );
    if (write( fd, output_buffer, output_buffer_pos ) != output_buffer_pos)
        fatal_error( "Error writing to %s\n", res_file );
    close( fd );
    free( output_buffer );

    if (res_file)
    {
        char *prog = find_tool( "windres", NULL );
        char *cmd = xmalloc( strlen(prog) + strlen(res_file) + strlen(output_file_name) + 9 );
        sprintf( cmd, "%s -i %s -o %s", prog, res_file, output_file_name );
        if (verbose) fprintf( stderr, "%s\n", cmd );
        err = system( cmd );
        if (err) fatal_error( "%s failed with status %d\n", prog, err );
        free( cmd );
        free( prog );
    }
    output_file_name = NULL;  /* so we don't try to assemble it */
}
示例#12
0
OutCoreInterp::OutCoreInterp(double dist_x, double dist_y,
                             int size_x, int size_y,
                             double r_sqr,
                             double _min_x, double _max_x,
                             double _min_y, double _max_y,
                             int _window_size)
{
    int i;

    GRID_DIST_X = dist_x;
    GRID_DIST_Y = dist_y;

    GRID_SIZE_X = size_x;
    GRID_SIZE_Y = size_y;

    radius_sqr = r_sqr;

    min_x = _min_x;
    max_x = _max_x;
    min_y = _min_y;
    max_y = _max_y;

    window_size = _window_size;

    overlapSize = (int)ceil(sqrt(radius_sqr)/GRID_DIST_Y);
    int window_dist = window_size / 2;
    if (window_dist > overlapSize) {
        overlapSize = window_dist;
    }

    // how many pieces will there be?
    // numFiles = (GRID_SIZE_X*GRID_SIZE_Y + (2 * overlapSize + 1) * GRID_SIZE_X * numFiles) / MEM_LIMIT;
    // (2 * overlapSize + 1) means, each component has one more row to handle the points in-between two components.
    numFiles = (int)ceil((double)GRID_SIZE_X * GRID_SIZE_Y / (Interpolation::MEM_LIMIT - (2 * overlapSize + 1) * GRID_SIZE_X));
    cerr << "numFiles " << numFiles << endl;

    if(numFiles == 0)
        cerr << "The number of files is 0!" << endl;

    // TODO: if one row is too long,
    // i.e. the shape of decomposition is long, and thin in one direction,
    // alternative decomposition scheme may be more efficient.

    // row-wise decomposition

    local_grid_size_x = GRID_SIZE_X;
    local_grid_size_y = (int)ceil((double)GRID_SIZE_Y/numFiles);


    // define overlap.. a funtion of (radius_sqr)
    // overlap size: sqrt(radius_sqr)/GRID_DIST_Y;

    // construct a map indicating which file corresponds which area
    if((gridMap = new GridMap*[numFiles]) == NULL)
        cerr << "OutCoreInterp::OutCoreInterp() GridMap[] allocation error" << endl;

    for(i = 0; i < numFiles; i++)
    {
        int lower_bound = i * local_grid_size_y;
        int upper_bound = (i+1) * local_grid_size_y - 1;

        if(upper_bound >= GRID_SIZE_Y)
            upper_bound = GRID_SIZE_Y - 1;

        int overlap_lower_bound = lower_bound - overlapSize;
        if(overlap_lower_bound < 0)
            overlap_lower_bound = 0;

        int overlap_upper_bound = upper_bound + overlapSize + 1;
        if(overlap_upper_bound >= GRID_SIZE_Y)
            overlap_upper_bound = GRID_SIZE_Y - 1;

        char fname[1024];
        get_temp_file_name(fname, sizeof(fname));

        gridMap[i] = new GridMap(i,
                                 GRID_SIZE_X,
                                 lower_bound,
                                 upper_bound,
                                 overlap_lower_bound,
                                 overlap_upper_bound,
                                 false,
                                 fname);
        if(gridMap[i] == NULL)
            cerr << "OutCoreInterp::OutCoreInterp() GridMap alloc error" << endl;

        cerr << "[" <<  lower_bound << "," << upper_bound << "]" << endl;
        cerr << "[" << overlap_lower_bound << "," << overlap_upper_bound << "]" << endl;
    }

    // initializing queues
    qlist = new list<UpdateInfo> [numFiles];
    if(qlist == NULL)
        cerr << "OutCoreInterp::OutCoreInterp() qlist alloc error" << endl;

    openFile = -1;

    //cout << overlapSize << endl;
    //cout << "data size: " << (size_x * size_y) << " numFiles: " << numFiles << " local_grid_size_y: " << local_grid_size_y << " overlap: " << overlapSize << endl;
    //cout << fname << endl;
    //cout << "GridMap is created: " << i << endl;
}
示例#13
0
文件: res32.c 项目: AlexSteel/wine
/* output the resources into a .o file */
void output_res_o_file( DLLSPEC *spec )
{
    unsigned int i;
    char *res_file = NULL;
    int fd;
    struct strarray *args;

    if (!spec->nb_resources) fatal_error( "--resources mode needs at least one resource file as input\n" );
    if (!output_file_name) fatal_error( "No output file name specified\n" );

    qsort( spec->resources, spec->nb_resources, sizeof(*spec->resources), cmp_res );
    remove_duplicate_resources( spec );

    byte_swapped = 0;
    init_output_buffer();

    put_dword( 0 );      /* ResSize */
    put_dword( 32 );     /* HeaderSize */
    put_word( 0xffff );  /* ResType */
    put_word( 0x0000 );
    put_word( 0xffff );  /* ResName */
    put_word( 0x0000 );
    put_dword( 0 );      /* DataVersion */
    put_word( 0 );       /* Memory options */
    put_word( 0 );       /* Language */
    put_dword( 0 );      /* Version */
    put_dword( 0 );      /* Characteristics */

    for (i = 0; i < spec->nb_resources; i++)
    {
        unsigned int header_size = get_resource_header_size( &spec->resources[i] );

        put_dword( spec->resources[i].data_size );
        put_dword( (header_size + 3) & ~3 );
        put_string( &spec->resources[i].type );
        put_string( &spec->resources[i].name );
        align_output( 4 );
        put_dword( 0 );
        put_word( spec->resources[i].mem_options );
        put_word( spec->resources[i].lang );
        put_dword( spec->resources[i].version );
        put_dword( 0 );
        put_data( spec->resources[i].data, spec->resources[i].data_size );
        align_output( 4 );
    }

    /* if the output file name is a .res too, don't run the results through windres */
    if (strendswith( output_file_name, ".res"))
    {
        flush_output_buffer();
        return;
    }

    res_file = get_temp_file_name( output_file_name, ".res" );
    if ((fd = open( res_file, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0600 )) == -1)
        fatal_error( "Cannot create %s\n", res_file );
    if (write( fd, output_buffer, output_buffer_pos ) != output_buffer_pos)
        fatal_error( "Error writing to %s\n", res_file );
    close( fd );
    free( output_buffer );

    args = find_tool( "windres", NULL );
    strarray_add( args, "-i", res_file, "-o", output_file_name, NULL );
    spawn( args );
    strarray_free( args );

    output_file_name = NULL;  /* so we don't try to assemble it */
}
示例#14
0
gboolean
apply_transformation_jpeg (FileData       *file,
			   GthTransform    transform,
			   JpegMcuAction   mcu_action,
			   GError        **error)
{
	gboolean          result = TRUE;
	char             *tmp_dir = NULL;
	char             *tmp_output_file = NULL;
	JXFORM_CODE       transf;
	char		 *local_file;
	GnomeVFSFileInfo *info = NULL;

	if (file == NULL)
		return FALSE;

	if (transform == GTH_TRANSFORM_NONE)
		return TRUE;

	tmp_dir = get_temp_dir_name ();
	if (tmp_dir == NULL) {
		if (error != NULL)
			*error = g_error_new (GTHUMB_ERROR, 0, "%s", _("Could not create a temporary folder"));
		return FALSE;
	}

	local_file = get_cache_filename_from_uri (file->path);
	if (local_file == NULL) {
		if (error != NULL)
			*error = g_error_new (GTHUMB_ERROR, 0, "%s", _("Could not create a local temporary copy of the remote file."));
		result = FALSE;
		goto apply_transformation_jpeg__free_and_close;
	}

	info = gnome_vfs_file_info_new ();
	gnome_vfs_get_file_info (file->path, info, GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS | GNOME_VFS_FILE_INFO_FOLLOW_LINKS);

	switch (transform) {
	case GTH_TRANSFORM_NONE:
		transf = JXFORM_NONE;
		break;
	case GTH_TRANSFORM_FLIP_H:
		transf = JXFORM_FLIP_H;
		break;
	case GTH_TRANSFORM_ROTATE_180:
		transf = JXFORM_ROT_180;
		break;
	case GTH_TRANSFORM_FLIP_V:
		transf = JXFORM_FLIP_V;
		break;
	case GTH_TRANSFORM_TRANSPOSE:
		transf = JXFORM_TRANSPOSE;
		break;
	case GTH_TRANSFORM_ROTATE_90:
		transf = JXFORM_ROT_90;
		break;
	case GTH_TRANSFORM_TRANSVERSE:
		transf = JXFORM_TRANSVERSE;
		break;
	case GTH_TRANSFORM_ROTATE_270:
		transf = JXFORM_ROT_270;
		break;
	default:
		transf = JXFORM_NONE;
		break;
	}

	tmp_output_file = get_temp_file_name (tmp_dir, NULL);
	if (! jpegtran (local_file, tmp_output_file, transf, mcu_action, error)) {
		result = FALSE;
		goto apply_transformation_jpeg__free_and_close;
	}

	if (! local_file_move (tmp_output_file, local_file)) {
		if (error != NULL)
			*error = g_error_new (GTHUMB_ERROR, 0, "%s", _("Could not move temporary file to local destination. Check folder permissions."));
		result = FALSE;
		goto apply_transformation_jpeg__free_and_close;	
	}

	if (info != NULL) {
		char *local_uri;
		
		local_uri = get_uri_from_local_path (local_file);
		gnome_vfs_set_file_info (local_uri, info, GNOME_VFS_SET_FILE_INFO_PERMISSIONS | GNOME_VFS_SET_FILE_INFO_OWNER);
		gnome_vfs_file_info_unref (info);
		g_free (local_uri);
	}

apply_transformation_jpeg__free_and_close:

	local_dir_remove_recursive (tmp_dir);
	g_free (tmp_output_file);
	g_free (tmp_dir);

	return result;
}