Blame gio/glocalfileiostream.c

Packit ae235b
/* GIO - GLib Input, IO and Streaming Library
Packit ae235b
 * 
Packit ae235b
 * Copyright (C) 2006-2007 Red Hat, Inc.
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General
Packit ae235b
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 *
Packit ae235b
 * Author: Alexander Larsson <alexl@redhat.com>
Packit ae235b
 */
Packit ae235b
Packit ae235b
#include "config.h"
Packit ae235b
Packit ae235b
#include <glib.h>
Packit ae235b
#include <glib/gstdio.h>
Packit ae235b
#include "glibintl.h"
Packit ae235b
#include "gioerror.h"
Packit ae235b
#include "gcancellable.h"
Packit ae235b
#include "glocalfileiostream.h"
Packit ae235b
#include "glocalfileinputstream.h"
Packit ae235b
#include "glocalfileinfo.h"
Packit ae235b
Packit ae235b
#ifdef G_OS_UNIX
Packit ae235b
#include "gfiledescriptorbased.h"
Packit ae235b
#endif
Packit ae235b
Packit ae235b
Packit ae235b
#define g_local_file_io_stream_get_type _g_local_file_io_stream_get_type
Packit ae235b
G_DEFINE_TYPE (GLocalFileIOStream, g_local_file_io_stream, G_TYPE_FILE_IO_STREAM)
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_local_file_io_stream_finalize (GObject *object)
Packit ae235b
{
Packit ae235b
  GLocalFileIOStream *file;
Packit ae235b
Packit ae235b
  file = G_LOCAL_FILE_IO_STREAM (object);
Packit ae235b
Packit ae235b
  g_object_unref (file->input_stream);
Packit ae235b
  g_object_unref (file->output_stream);
Packit ae235b
Packit ae235b
  G_OBJECT_CLASS (g_local_file_io_stream_parent_class)->finalize (object);
Packit ae235b
}
Packit ae235b
Packit ae235b
GFileIOStream *
Packit ae235b
_g_local_file_io_stream_new (GLocalFileOutputStream *output_stream)
Packit ae235b
{
Packit ae235b
  GLocalFileIOStream *stream;
Packit ae235b
  int fd;
Packit ae235b
Packit ae235b
  stream = g_object_new (G_TYPE_LOCAL_FILE_IO_STREAM, NULL);
Packit ae235b
  stream->output_stream = g_object_ref (G_OUTPUT_STREAM (output_stream));
Packit ae235b
  _g_local_file_output_stream_set_do_close (output_stream, FALSE);
Packit ae235b
  fd = _g_local_file_output_stream_get_fd (output_stream);
Packit ae235b
  stream->input_stream = (GInputStream *)_g_local_file_input_stream_new (fd);
Packit ae235b
Packit ae235b
  _g_local_file_input_stream_set_do_close (G_LOCAL_FILE_INPUT_STREAM (stream->input_stream),
Packit ae235b
					   FALSE);
Packit ae235b
Packit ae235b
  return G_FILE_IO_STREAM (stream);
Packit ae235b
}
Packit ae235b
Packit ae235b
static GInputStream *
Packit ae235b
g_local_file_io_stream_get_input_stream (GIOStream *stream)
Packit ae235b
{
Packit ae235b
  return G_LOCAL_FILE_IO_STREAM (stream)->input_stream;
Packit ae235b
}
Packit ae235b
Packit ae235b
static GOutputStream *
Packit ae235b
g_local_file_io_stream_get_output_stream (GIOStream *stream)
Packit ae235b
{
Packit ae235b
  return G_LOCAL_FILE_IO_STREAM (stream)->output_stream;
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
static gboolean
Packit ae235b
g_local_file_io_stream_close (GIOStream  *stream,
Packit ae235b
			      GCancellable   *cancellable,
Packit ae235b
			      GError        **error)
Packit ae235b
{
Packit ae235b
  GLocalFileIOStream *file = G_LOCAL_FILE_IO_STREAM (stream);
Packit ae235b
Packit ae235b
  /* There are shortcutted and can't fail */
Packit ae235b
  g_output_stream_close (file->output_stream, cancellable, NULL);
Packit ae235b
  g_input_stream_close (file->input_stream, cancellable, NULL);
Packit ae235b
Packit ae235b
  return
Packit ae235b
    _g_local_file_output_stream_really_close (G_LOCAL_FILE_OUTPUT_STREAM (file->output_stream),
Packit ae235b
					      cancellable, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_local_file_io_stream_class_init (GLocalFileIOStreamClass *klass)
Packit ae235b
{
Packit ae235b
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
Packit ae235b
  GIOStreamClass *stream_class = G_IO_STREAM_CLASS (klass);
Packit ae235b
Packit ae235b
  gobject_class->finalize = g_local_file_io_stream_finalize;
Packit ae235b
Packit ae235b
  stream_class->get_input_stream = g_local_file_io_stream_get_input_stream;
Packit ae235b
  stream_class->get_output_stream = g_local_file_io_stream_get_output_stream;
Packit ae235b
  stream_class->close_fn = g_local_file_io_stream_close;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_local_file_io_stream_init (GLocalFileIOStream *stream)
Packit ae235b
{
Packit ae235b
}