static void
do_dump (void)
{
	char *from;
	MateVFSHandle *from_handle;
	MateVFSResult  result;
	guint32         offset;

	from = get_fname ();

	result = mate_vfs_open (&from_handle, from, MATE_VFS_OPEN_READ);
	if (show_if_error (result, "open ", from))
		return;

	for (offset = 0; 1; ) {
		MateVFSFileSize bytes_read;
		guint8           data [1024];
		
		result = mate_vfs_read (from_handle, data, 1024, &bytes_read);
		if (show_if_error (result, "read ", from))
			return;

		if (bytes_read == 0)
			break;

		ms_ole_dump (data, bytes_read, offset);
		
		offset += bytes_read;
	}

	result = mate_vfs_close (from_handle);
	if (show_if_error (result, "close ", from))
		return;
}
static void
do_open (void)
{
	char *from, *handle;
	MateVFSHandle *from_handle;
	MateVFSResult  result;

	handle = get_handle ();
	from = get_fname ();

	if (!handle || !from) {
		fprintf (vfserr, "open <handle> <filename>\n");
		return;
	}

	result = mate_vfs_open (&from_handle, from, MATE_VFS_OPEN_READ);
	if (show_if_error (result, "open ", from))
		return;

	register_file (handle, from_handle);
}
/**
 * mate_vfs_create_temp:
 * @prefix: Prefix for the name of the temporary file
 * @name_return: Pointer to a pointer that, on return, will point to
 * the dynamically allocated name for the new temporary file created.
 * @handle_return: Pointer to a variable that will hold a file handle for
 * the new temporary file on return.
 * 
 * Create a temporary file whose name is prefixed with @prefix, and return an
 * open file handle for it in @*handle_return.
 * 
 * Return value: An integer value representing the result of the operation
 **/
MateVFSResult
mate_vfs_create_temp (const gchar *prefix,
		       gchar **name_return,
		       MateVFSHandle **handle_return)
{
	MateVFSHandle *handle;
	MateVFSResult result;
	gchar *name;
	gint fd;

	while (1) {
		name = g_strdup_printf("%sXXXXXX", prefix);
		fd = g_mkstemp (name);

		if (fd < 0)
			return MATE_VFS_ERROR_INTERNAL;
		
#ifdef HAVE_FCHMOD
		fchmod (fd, 0600);
#endif
		close (fd);

		result = mate_vfs_open
			(&handle, name,
			 MATE_VFS_OPEN_WRITE | MATE_VFS_OPEN_READ);

		if (result == MATE_VFS_OK) {
			*name_return = name;
			*handle_return = handle;
			return MATE_VFS_OK;
		}

		if (result != MATE_VFS_ERROR_FILE_EXISTS) {
			*name_return = NULL;
			*handle_return = NULL;
			g_free (name);
			return result;
		}
	}
}
static void
do_cat (void)
{
	char *from;
	MateVFSHandle *from_handle;
	MateVFSResult  result;

	from = get_fname ();

	result = mate_vfs_open (&from_handle, from, MATE_VFS_OPEN_READ);
	if (show_if_error (result, "open ", from))
		return;

	while (1) {
		MateVFSFileSize bytes_read;
		guint8           data [1025];
		
		result = mate_vfs_read (from_handle, data, 1024, &bytes_read);
		if (show_if_error (result, "read ", from))
			return;

		if (bytes_read == 0)
			break;
		
		if (bytes_read >  0 &&
		    bytes_read <= 1024)
			data [bytes_read] = '\0';
		else {
			data [1024] = '\0';
			g_warning ("Wierd error from vfs_read");
		}
		fprintf (stdout, "%s", data);
	}

	result = mate_vfs_close (from_handle);
	if (show_if_error (result, "close ", from))
		return;
	fprintf (stdout, "\n");
}
static void
do_cp (void)
{
	char *from = NULL;
	char *to = NULL;
	MateVFSHandle *from_handle = NULL;
	MateVFSHandle *to_handle = NULL;
	MateVFSResult  result;

	from = get_fname ();

	if (from)
		to = get_fname ();
	else {
		fprintf (vfserr, "cp <from> <to>\n");
		goto out;
	}
       
	result = mate_vfs_open (&from_handle, from, MATE_VFS_OPEN_READ);
	if (show_if_error (result, "open ", from))
		goto out;

	result = mate_vfs_open (&to_handle, to, MATE_VFS_OPEN_WRITE);
	if (result == MATE_VFS_ERROR_NOT_FOUND)
		result = mate_vfs_create (&to_handle, to, MATE_VFS_OPEN_WRITE, FALSE,
					   MATE_VFS_PERM_USER_ALL);
	if (show_if_error (result, "open ", to))
		goto out;

	while (1) {
		MateVFSFileSize bytes_read;
		MateVFSFileSize bytes_written;
		guint8           data [1024];
		
		result = mate_vfs_read (from_handle, data, 1024, &bytes_read);
		if (show_if_error (result, "read ", from))
			goto out;

		if (bytes_read == 0)
			break;
		
		result = mate_vfs_write (to_handle, data, bytes_read, &bytes_written);
		if (show_if_error (result, "write ", to))
			goto out;

		if (bytes_read != bytes_written)
			fprintf (vfserr, "Didn't write it all");
	}

 out:
	g_free (from);
	g_free (to);

	if (to_handle) {
		result = mate_vfs_close (to_handle);
		if (show_if_error (result, "close ", to))
			/* Nothing */;
	}

	if (from_handle) {
		result = mate_vfs_close (from_handle);
		if (show_if_error (result, "close ", from))
			/* Nothing */;
	}
}