mirror of
				https://gitlab.gnome.org/GNOME/glib.git
				synced 2025-11-04 01:58:54 +01:00 
			
		
		
		
	GLocalFileOutputStream: Implement GFileDescriptorBased
Also convert GLocalFileIOStream to use the new interface to obtain the file descriptor.
This commit is contained in:
		@@ -27,6 +27,7 @@
 | 
			
		||||
#include "glibintl.h"
 | 
			
		||||
#include "gioerror.h"
 | 
			
		||||
#include "gcancellable.h"
 | 
			
		||||
#include "gfiledescriptorbased.h"
 | 
			
		||||
#include "glocalfileiostream.h"
 | 
			
		||||
#include "glocalfileinputstream.h"
 | 
			
		||||
#include "glocalfileinfo.h"
 | 
			
		||||
@@ -58,7 +59,7 @@ _g_local_file_io_stream_new (GLocalFileOutputStream *output_stream)
 | 
			
		||||
  stream = g_object_new (G_TYPE_LOCAL_FILE_IO_STREAM, NULL);
 | 
			
		||||
  stream->output_stream = g_object_ref (output_stream);
 | 
			
		||||
  _g_local_file_output_stream_set_do_close (output_stream, FALSE);
 | 
			
		||||
  fd = _g_local_file_output_stream_get_fd (output_stream);
 | 
			
		||||
  fd = g_file_descriptor_based_get_fd (G_FILE_DESCRIPTOR_BASED (output_stream));
 | 
			
		||||
  stream->input_stream = (GInputStream *)_g_local_file_input_stream_new (fd);
 | 
			
		||||
  _g_local_file_input_stream_set_do_close (G_LOCAL_FILE_INPUT_STREAM (stream->input_stream),
 | 
			
		||||
					   FALSE);
 | 
			
		||||
 
 | 
			
		||||
@@ -36,6 +36,7 @@
 | 
			
		||||
#include "glibintl.h"
 | 
			
		||||
#include "gioerror.h"
 | 
			
		||||
#include "gcancellable.h"
 | 
			
		||||
#include "gfiledescriptorbased.h"
 | 
			
		||||
#include "glocalfileoutputstream.h"
 | 
			
		||||
#include "glocalfileinfo.h"
 | 
			
		||||
 | 
			
		||||
@@ -55,8 +56,12 @@
 | 
			
		||||
 | 
			
		||||
#include "gioalias.h"
 | 
			
		||||
 | 
			
		||||
static void       g_file_descriptor_based_iface_init   (GFileDescriptorBasedIface *iface);
 | 
			
		||||
#define g_local_file_output_stream_get_type _g_local_file_output_stream_get_type
 | 
			
		||||
G_DEFINE_TYPE (GLocalFileOutputStream, g_local_file_output_stream, G_TYPE_FILE_OUTPUT_STREAM);
 | 
			
		||||
G_DEFINE_TYPE_WITH_CODE (GLocalFileOutputStream, g_local_file_output_stream, G_TYPE_FILE_OUTPUT_STREAM,
 | 
			
		||||
			 G_IMPLEMENT_INTERFACE (G_TYPE_FILE_DESCRIPTOR_BASED,
 | 
			
		||||
						g_file_descriptor_based_iface_init));
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/* Some of the file replacement code was based on the code from gedit,
 | 
			
		||||
 * relicenced to LGPL with permissions from the authors.
 | 
			
		||||
@@ -99,6 +104,7 @@ static gboolean   g_local_file_output_stream_truncate     (GFileOutputStream  *s
 | 
			
		||||
							   goffset             size,
 | 
			
		||||
							   GCancellable       *cancellable,
 | 
			
		||||
							   GError            **error);
 | 
			
		||||
static int        g_local_file_output_stream_get_fd       (GFileDescriptorBased *stream);
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
g_local_file_output_stream_finalize (GObject *object)
 | 
			
		||||
@@ -115,6 +121,7 @@ g_local_file_output_stream_finalize (GObject *object)
 | 
			
		||||
  G_OBJECT_CLASS (g_local_file_output_stream_parent_class)->finalize (object);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
g_local_file_output_stream_class_init (GLocalFileOutputStreamClass *klass)
 | 
			
		||||
{
 | 
			
		||||
@@ -137,6 +144,12 @@ g_local_file_output_stream_class_init (GLocalFileOutputStreamClass *klass)
 | 
			
		||||
  file_stream_class->truncate_fn = g_local_file_output_stream_truncate;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
g_file_descriptor_based_iface_init (GFileDescriptorBasedIface *iface)
 | 
			
		||||
{
 | 
			
		||||
  iface->get_fd = g_local_file_output_stream_get_fd;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
g_local_file_output_stream_init (GLocalFileOutputStream *stream)
 | 
			
		||||
{
 | 
			
		||||
@@ -146,12 +159,6 @@ g_local_file_output_stream_init (GLocalFileOutputStream *stream)
 | 
			
		||||
  stream->priv->do_close = TRUE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
_g_local_file_output_stream_get_fd (GLocalFileOutputStream *out)
 | 
			
		||||
{
 | 
			
		||||
  return out->priv->fd;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static gssize
 | 
			
		||||
g_local_file_output_stream_write (GOutputStream  *stream,
 | 
			
		||||
				  const void     *buffer,
 | 
			
		||||
@@ -1151,3 +1158,12 @@ _g_local_file_output_stream_replace (const char        *filename,
 | 
			
		||||
  
 | 
			
		||||
  return G_FILE_OUTPUT_STREAM (stream);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int
 | 
			
		||||
g_local_file_output_stream_get_fd (GFileDescriptorBased *fd_based)
 | 
			
		||||
{
 | 
			
		||||
  GLocalFileOutputStream *stream = G_LOCAL_FILE_OUTPUT_STREAM (fd_based);
 | 
			
		||||
 | 
			
		||||
  return stream->priv->fd;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -53,7 +53,6 @@ struct _GLocalFileOutputStreamClass
 | 
			
		||||
 | 
			
		||||
GType               _g_local_file_output_stream_get_type (void) G_GNUC_CONST;
 | 
			
		||||
 | 
			
		||||
int      _g_local_file_output_stream_get_fd       (GLocalFileOutputStream *out);
 | 
			
		||||
void     _g_local_file_output_stream_set_do_close (GLocalFileOutputStream *out,
 | 
			
		||||
						   gboolean do_close);
 | 
			
		||||
gboolean _g_local_file_output_stream_really_close (GLocalFileOutputStream *out,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user