source: trunk/third/gnome-vfs2/test/test-sync-write.c @ 18317

Revision 18317, 2.5 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18316, which included commits to RCS files with non-trunk default branches.
Line 
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
3   Virtual File System.
4
5   Copyright (C) 1999 Free Software Foundation
6
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.
11
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.
16
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.
21
22   Author: Ettore Perazzoli <ettore@gnu.org>
23                                         Ian McKellar <yakk@yakk.net>
24
25         */
26
27#include <config.h>
28
29#include <libgnomevfs/gnome-vfs-init.h>
30#include <libgnomevfs/gnome-vfs-ops.h>
31#include <stdio.h>
32#include <stdlib.h>
33
34static void
35show_result (GnomeVFSResult result, const gchar *what, const gchar *text_uri)
36{
37        fprintf (stderr, "%s `%s': %s\n",
38                 what, text_uri, gnome_vfs_result_to_string (result));
39        if (result != GNOME_VFS_OK)
40                exit (1);
41}
42
43int
44main (int argc, char **argv)
45{
46        GnomeVFSResult    result;
47        GnomeVFSHandle   *handle;
48        gchar             buffer[1024];
49        GnomeVFSFileSize  bytes_read;
50        GnomeVFSURI      *uri;
51        gchar            *text_uri;
52
53        if (argc != 2) {
54                printf ("Usage: %s <uri>\n", argv[0]);
55                return 1;
56        }
57
58        if (! gnome_vfs_init ()) {
59                fprintf (stderr, "Cannot initialize gnome-vfs.\n");
60                return 1;
61        }
62
63        uri = gnome_vfs_uri_new (argv[1]);
64        if (uri == NULL) {
65                fprintf (stderr, "URI not valid.\n");
66                return 1;
67        }
68
69        text_uri = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE);
70
71        result = gnome_vfs_open_uri (&handle, uri, GNOME_VFS_OPEN_WRITE);
72        show_result (result, "open", text_uri);
73
74        while( result==GNOME_VFS_OK && !feof(stdin)) {
75                GnomeVFSFileSize temp;
76
77                bytes_read = fread(buffer, 1, sizeof buffer - 1, stdin);
78                if(!bytes_read) break;
79                buffer[bytes_read] = 0;
80                result = gnome_vfs_write (handle, buffer, bytes_read,
81                                        &temp);
82                show_result (result, "write", text_uri);
83       
84        }
85
86        result = gnome_vfs_close (handle);
87        show_result (result, "close", text_uri);
88
89        g_free (text_uri);
90
91        return 0;
92}
Note: See TracBrowser for help on using the repository browser.