static void show_result (MateVFSResult result, const gchar *what, const gchar *text_uri) { fprintf (stderr, "%s `%s': %s\n", what, text_uri, mate_vfs_result_to_string (result)); if (result != MATE_VFS_OK) { fprintf (stdout, "Error: %s\n", mate_vfs_result_to_string (result)); exit (1); } }
static void read_callback (MateVFSAsyncHandle *handle, MateVFSResult result, gpointer buffer, MateVFSFileSize bytes_requested, MateVFSFileSize bytes_read, gpointer callback_data) { char **op_data; if (result != MATE_VFS_OK) { fprintf (stderr, "Read failed: %s\n", mate_vfs_result_to_string (result)); } else { printf ("%"MATE_VFS_SIZE_FORMAT_STR"/" "%"MATE_VFS_SIZE_FORMAT_STR" " "byte(s) read, callback data `%s'\n", bytes_read, bytes_requested, (gchar *) callback_data); *((gchar *) buffer + bytes_read) = 0; fprintf (stderr, "%s", (char *) buffer); } fprintf (stderr, "Now testing file_control.\n"); op_data = g_new (char *, 1); mate_vfs_async_file_control (handle, "file:test", op_data, g_free, file_control_callback, "file_control"); }
/* Callbacks. */ static void close_callback (MateVFSAsyncHandle *handle, MateVFSResult result, gpointer callback_data) { fprintf (stderr, "Close: %s.\n", mate_vfs_result_to_string (result)); g_main_loop_quit (main_loop); }
char * ne_addr_error (const ne_sock_addr *addr, char *buffer, size_t bufsiz) { const char *error_str; error_str = mate_vfs_result_to_string (addr->result); g_strlcpy (buffer, error_str, bufsiz); return buffer; }
static gboolean show_if_error (MateVFSResult result, const char *what, const char *what2) { if (result != MATE_VFS_OK) { fprintf (vfserr, "%s%s `%s'\n", what, what2, mate_vfs_result_to_string (result)); return TRUE; } else return FALSE; }
static void show_result (MateVFSResult result, const gchar *what, const gchar *from, const gchar *to) { if (result != MATE_VFS_OK) { fprintf (stderr, "%s `%s' `%s': %s\n", what, from, to, mate_vfs_result_to_string (result)); exit (1); } }
static void show_result (MateVFSResult result, const gchar *what, const gchar *host, gint port) { fprintf (stderr, "%s `%s:%d': %s\n", what, host, port, mate_vfs_result_to_string (result)); if (result != MATE_VFS_OK) exit (1); }
static void file_control_callback (MateVFSAsyncHandle *handle, MateVFSResult result, gpointer operation_data, gpointer callback_data) { if (result != MATE_VFS_OK) { fprintf (stderr, "file_control failed: %s\n", mate_vfs_result_to_string (result)); } else { printf ("file_control result: %s\n", *(char **)operation_data); } fprintf (stderr, "Now closing the file.\n"); mate_vfs_async_close (handle, close_callback, "close"); }
static void open_callback (MateVFSAsyncHandle *handle, GIOChannel *channel, MateVFSResult result, gpointer data) { if (result != MATE_VFS_OK) { printf ("Error opening: %s.\n", mate_vfs_result_to_string (result)); return; } printf ("Open successful, callback data `%s'.\n", (gchar *) data); g_io_add_watch_full (channel, G_PRIORITY_HIGH, G_IO_IN | G_IO_NVAL | G_IO_HUP, io_channel_callback, handle, NULL); g_io_channel_unref (channel); }
static void open_callback (MateVFSAsyncHandle *handle, MateVFSResult result, gpointer callback_data) { if (result != MATE_VFS_OK) { fprintf (stderr, "Open failed: %s.\n", mate_vfs_result_to_string (result)); g_main_loop_quit (main_loop); } else { gchar *buffer; const gulong buffer_size = 1024; fprintf (stderr, "File opened correctly, data `%s'.\n", (gchar *) callback_data); buffer = g_malloc (buffer_size); mate_vfs_async_read (handle, buffer, buffer_size - 1, read_callback, "read_callback"); } }
int main (int argc, char **argv) { MateVFSResult result; char *text_uri; MateVFSURI *src, *dest; MateVFSFileInfo *info; if (argc != 3) { printf ("Usage: %s <src> <dest>\n", argv[0]); return 1; } if (!mate_vfs_init ()) { fprintf (stderr, "Cannot initialize mate-vfs.\n"); return 1; } command_line_authentication_init (); text_uri = mate_vfs_make_uri_from_shell_arg (argv[1]); src = mate_vfs_uri_new (text_uri); g_free (text_uri); text_uri = mate_vfs_make_uri_from_shell_arg (argv[2]); dest = mate_vfs_uri_new (text_uri); g_free (text_uri); if (src == NULL || dest == NULL) { result = MATE_VFS_ERROR_INVALID_URI; goto out; } info = mate_vfs_file_info_new (); result = mate_vfs_get_file_info_uri (dest, info, MATE_VFS_FILE_INFO_DEFAULT); if (result != MATE_VFS_OK && result != MATE_VFS_ERROR_NOT_FOUND) { mate_vfs_file_info_unref (info); goto out; } /* If the target is a directory do not overwrite it but copy the source into the directory! (This is like cp does it) */ if (info->valid_fields & MATE_VFS_FILE_INFO_FIELDS_TYPE && info->type == MATE_VFS_FILE_TYPE_DIRECTORY) { char *name; MateVFSURI *new_dest; name = mate_vfs_uri_extract_short_path_name (src); new_dest = mate_vfs_uri_append_string (dest, name); mate_vfs_uri_unref (dest); g_free (name); dest = new_dest; } mate_vfs_file_info_unref (info); result = mate_vfs_xfer_uri (src, dest, MATE_VFS_XFER_RECURSIVE, MATE_VFS_XFER_ERROR_MODE_ABORT, MATE_VFS_XFER_OVERWRITE_MODE_REPLACE, NULL, NULL); out: if (src) { mate_vfs_uri_unref (src); } if (dest) { mate_vfs_uri_unref (dest); } if (result != MATE_VFS_OK) { fprintf (stderr, "Failed to copy %s to %s\nReason: %s\n", argv[1], argv[2], mate_vfs_result_to_string (result)); return 1; } return 0; }
const char * ne_sock_error (const ne_socket *sock) { return mate_vfs_result_to_string (sock->last_error); }