1 /* GIO - GLib Input, IO and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Alexander Larsson <alexl@redhat.com>
26 #include <glib/gstdio.h>
29 #include "gcancellable.h"
30 #include "glocalfileiostream.h"
31 #include "glocalfileinputstream.h"
32 #include "glocalfileinfo.h"
35 #include "gfiledescriptorbased.h"
39 #define g_local_file_io_stream_get_type _g_local_file_io_stream_get_type
40 G_DEFINE_TYPE (GLocalFileIOStream
, g_local_file_io_stream
, G_TYPE_FILE_IO_STREAM
);
43 g_local_file_io_stream_finalize (GObject
*object
)
45 GLocalFileIOStream
*file
;
47 file
= G_LOCAL_FILE_IO_STREAM (object
);
49 g_object_unref (file
->input_stream
);
50 g_object_unref (file
->output_stream
);
52 G_OBJECT_CLASS (g_local_file_io_stream_parent_class
)->finalize (object
);
56 _g_local_file_io_stream_new (GLocalFileOutputStream
*output_stream
)
58 GLocalFileIOStream
*stream
;
61 stream
= g_object_new (G_TYPE_LOCAL_FILE_IO_STREAM
, NULL
);
62 stream
->output_stream
= g_object_ref (output_stream
);
63 _g_local_file_output_stream_set_do_close (output_stream
, FALSE
);
64 fd
= _g_local_file_output_stream_get_fd (output_stream
);
65 stream
->input_stream
= (GInputStream
*)_g_local_file_input_stream_new (fd
);
67 _g_local_file_input_stream_set_do_close (G_LOCAL_FILE_INPUT_STREAM (stream
->input_stream
),
70 return G_FILE_IO_STREAM (stream
);
74 g_local_file_io_stream_get_input_stream (GIOStream
*stream
)
76 return G_LOCAL_FILE_IO_STREAM (stream
)->input_stream
;
79 static GOutputStream
*
80 g_local_file_io_stream_get_output_stream (GIOStream
*stream
)
82 return G_LOCAL_FILE_IO_STREAM (stream
)->output_stream
;
87 g_local_file_io_stream_close (GIOStream
*stream
,
88 GCancellable
*cancellable
,
91 GLocalFileIOStream
*file
= G_LOCAL_FILE_IO_STREAM (stream
);
93 /* There are shortcutted and can't fail */
94 g_output_stream_close (file
->output_stream
, cancellable
, NULL
);
95 g_input_stream_close (file
->input_stream
, cancellable
, NULL
);
98 _g_local_file_output_stream_really_close (G_LOCAL_FILE_OUTPUT_STREAM (file
->output_stream
),
103 g_local_file_io_stream_class_init (GLocalFileIOStreamClass
*klass
)
105 GObjectClass
*gobject_class
= G_OBJECT_CLASS (klass
);
106 GIOStreamClass
*stream_class
= G_IO_STREAM_CLASS (klass
);
108 gobject_class
->finalize
= g_local_file_io_stream_finalize
;
110 stream_class
->get_input_stream
= g_local_file_io_stream_get_input_stream
;
111 stream_class
->get_output_stream
= g_local_file_io_stream_get_output_stream
;
112 stream_class
->close_fn
= g_local_file_io_stream_close
;
116 g_local_file_io_stream_init (GLocalFileIOStream
*stream
)