int main (int argc, char **argv) { MateVFSResult result; MateVFSHandle *handle; gchar buffer[1024]; MateVFSFileSize bytes_read; MateVFSURI *uri; gchar *text_uri; if (argc != 2) { printf ("Usage: %s <uri>\n", argv[0]); return 1; } if (! mate_vfs_init ()) { fprintf (stderr, "Cannot initialize mate-vfs.\n"); return 1; } uri = mate_vfs_uri_new (argv[1]); if (uri == NULL) { fprintf (stderr, "URI not valid.\n"); return 1; } text_uri = mate_vfs_uri_to_string (uri, MATE_VFS_URI_HIDE_NONE); result = mate_vfs_open_uri (&handle, uri, MATE_VFS_OPEN_WRITE); show_result (result, "open", text_uri); while( result==MATE_VFS_OK && !feof(stdin)) { MateVFSFileSize temp; bytes_read = fread(buffer, 1, sizeof buffer - 1, stdin); if(!bytes_read) break; buffer[bytes_read] = 0; result = mate_vfs_write (handle, buffer, bytes_read, &temp); show_result (result, "write", text_uri); } result = mate_vfs_close (handle); show_result (result, "close", text_uri); g_free (text_uri); return 0; }
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 */; } }