source: trunk/third/gnome-vfs2/test/test-sync-create.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
34#define BUFFER_SIZE 1024
35
36static void
37show_result (GnomeVFSResult result, const gchar *what, const gchar *text_uri)
38{
39        fprintf (stderr, "%s `%s': %s\n",
40                 what, text_uri, gnome_vfs_result_to_string (result));
41        if (result != GNOME_VFS_OK)
42                exit (1);
43}
44
45int
46main (int argc, char **argv)
47{
48        GnomeVFSResult    result;
49        GnomeVFSHandle   *handle;
50        gchar             buffer[BUFFER_SIZE+1];
51        GnomeVFSFileSize  bytes_read;
52        GnomeVFSURI      *uri;
53        gchar            *text_uri;
54
55        if (argc != 2) {
56                printf ("Usage: %s <uri>\n", argv[0]);
57                return 1;
58        }
59
60        if (! gnome_vfs_init ()) {
61                fprintf (stderr, "Cannot initialize gnome-vfs.\n");
62                return 1;
63        }
64
65        uri = gnome_vfs_uri_new (argv[1]);
66        if (uri == NULL) {
67                fprintf (stderr, "URI not valid.\n");
68                return 1;
69        }
70
71        text_uri = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE);
72
73        result = gnome_vfs_create_uri (&handle, uri, GNOME_VFS_OPEN_WRITE, FALSE, 0644);
74        show_result (result, "create", text_uri);
75
76        while( result==GNOME_VFS_OK && !feof(stdin)) {
77                GnomeVFSFileSize temp;
78
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,
83                                        &temp);
84                show_result (result, "write", text_uri);
85       
86        }
87
88        result = gnome_vfs_close (handle);
89        show_result (result, "close", text_uri);
90
91        g_free (text_uri);
92
93        return 0;
94}
Note: See TracBrowser for help on using the repository browser.