Can someone tell me how I can copy a binary file



Can someone tell me how I can copy a binary file. Is glib not good for
this? And how should the code be then. A code example would be really
welcome! thx

Can someone please help me code this I'm really stuck.

Code:	

	EogWindowPrivate *priv;
	GnomeVFSURI *img_uri;
	GConfClient *client;
	char *options = NULL;
	
	gchar *wallpaperfile;
	gchar *filename;
			
	GError *error = NULL;
	
	GIOChannel *wallpaperdst,*wallpapersrc;
		
	gchar buf[256];

	gint written;
	
	g_return_if_fail (EOG_IS_WINDOW (window));
	g_return_if_fail (EOG_IS_IMAGE (image));

	priv = window->priv;

	img_uri = eog_image_get_uri (image);
	filename =
gnome_vfs_uri_to_string(img_uri,GNOME_VFS_URI_HIDE_TOPLEVEL_METHOD);
	wallpaperfile = g_strdup_printf ("%s/.%s-wallpaper" ,g_get_home_dir
(),g_get_prgname());		
	
	g_printerr("%s\n",filename);
	g_printerr("%s\n",wallpaperfile);
	
	/*
	g_file_get_contents (filename, &contents, NULL, &error);
	if (error != NULL) {
			g_printerr(_("error reading file %s\n"), error->message);
			g_error_free (error);
			return;
	}
	g_printerr("1");
	*/
	wallpapersrc = g_io_channel_new_file(filename, "r", &error);
	if (error != NULL) {
			g_printerr(_("error creating file %s\n"), error->message);
			g_error_free (error);
			return;
	}
	wallpaperdst = g_io_channel_new_file(wallpaperfile, "w", &error);
	if (error != NULL) {
			g_printerr(_("error creating file %s\n"), error->message);
			g_error_free (error);
			return;
	}
	
	g_io_channel_set_encoding (wallpapersrc, NULL, NULL);
	g_io_channel_set_encoding (wallpaperdst, NULL, NULL);
	
	
	g_io_channel_read_chars (wallpapersrc, buf, 256, 64,NULL);
	
	g_io_channel_write_chars (wallpaperdst, buf, -1, &written, &error);
	if (error != NULL) {
			g_printerr(_("error writing to file %s\n"), error->message);
			g_error_free (error);
			return;
	}
	
	g_io_channel_shutdown (wallpaperdsrc, TRUE, NULL);
	g_io_channel_shutdown (wallpaperdst, TRUE, NULL);
	
-- 
lupusBE (Kristof Vansant Belgium)




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]