1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* test-sync.c - Test program for synchronous operation of the GNOME
5 Copyright (C) 1999 Free Software Foundation
7 The Gnome Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
12 The Gnome Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with the Gnome Library; see the file COPYING.LIB. If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
22 Author: Ettore Perazzoli <ettore@gnu.org> */
26 #include <libgnomevfs/gnome-vfs-init.h>
27 #include <libgnomevfs/gnome-vfs-ops.h>
33 show_result (GnomeVFSResult result, const gchar *what, const gchar *text_uri)
35 fprintf (stderr, "%s `%s': %s\n",
36 what, text_uri, gnome_vfs_result_to_string (result));
37 if (result != GNOME_VFS_OK && result != GNOME_VFS_ERROR_EOF)
42 main (int argc, char **argv)
44 GnomeVFSResult result;
45 GnomeVFSHandle *handle;
47 GnomeVFSFileSize bytes_read;
53 printf ("Usage: %s <uri>\n", argv[0]);
57 if (! gnome_vfs_init ()) {
58 fprintf (stderr, "Cannot initialize gnome-vfs.\n");
62 uri = gnome_vfs_uri_new (argv[1]);
64 fprintf (stderr, "URI not valid.\n");
68 text_uri = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE);
70 result = gnome_vfs_open_uri (&handle, uri, GNOME_VFS_OPEN_READ);
71 show_result (result, "open", text_uri);
73 while( result==GNOME_VFS_OK ) {
74 result = gnome_vfs_read (handle, buffer, sizeof buffer - 1,
76 show_result (result, "read", text_uri);
78 buffer[bytes_read] = 0;
79 write (1,buffer,bytes_read);
80 if(!bytes_read) break;
83 result = gnome_vfs_file_control (handle, "file:test", &out);
84 show_result (result, "file_control", text_uri);
85 if (result == GNOME_VFS_OK) {
86 g_print ("file_control file:test: %s\n", out);
91 result = gnome_vfs_close (handle);
92 show_result (result, "close", text_uri);