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>
23 Ian McKellar <yakk@yakk.net>
29 #include <libgnomevfs/gnome-vfs-init.h>
30 #include <libgnomevfs/gnome-vfs-ops.h>
34 #define BUFFER_SIZE 1024
37 show_result (GnomeVFSResult result, const gchar *what, const gchar *text_uri)
39 fprintf (stderr, "%s `%s': %s\n",
40 what, text_uri, gnome_vfs_result_to_string (result));
41 if (result != GNOME_VFS_OK)
46 main (int argc, char **argv)
48 GnomeVFSResult result;
49 GnomeVFSHandle *handle;
50 gchar buffer[BUFFER_SIZE+1];
51 GnomeVFSFileSize bytes_read;
56 printf ("Usage: %s <uri>\n", argv[0]);
60 if (! gnome_vfs_init ()) {
61 fprintf (stderr, "Cannot initialize gnome-vfs.\n");
65 uri = gnome_vfs_uri_new (argv[1]);
67 fprintf (stderr, "URI not valid.\n");
71 text_uri = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE);
73 result = gnome_vfs_create_uri (&handle, uri, GNOME_VFS_OPEN_WRITE, FALSE, 0644);
74 show_result (result, "create", text_uri);
76 while( result==GNOME_VFS_OK && !feof(stdin)) {
77 GnomeVFSFileSize temp;
79 bytes_read = fread(buffer, 1, BUFFER_SIZE, stdin);
80 if(!bytes_read) break;
81 buffer[bytes_read] = 0;
82 result = gnome_vfs_write (handle, buffer, bytes_read,
84 show_result (result, "write", text_uri);
88 result = gnome_vfs_close (handle);
89 show_result (result, "close", text_uri);