Coverage Report

Created: 2025-07-01 07:09

/src/glib/gio/glocalfileiostream.c
Line
Count
Source (jump to first uncovered line)
1
/* GIO - GLib Input, IO and Streaming Library
2
 * 
3
 * Copyright (C) 2006-2007 Red Hat, Inc.
4
 *
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.1 of the License, or (at your option) any later version.
9
 *
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.
14
 *
15
 * You should have received a copy of the GNU Lesser General
16
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
17
 *
18
 * Author: Alexander Larsson <alexl@redhat.com>
19
 */
20
21
#include "config.h"
22
23
#include <glib.h>
24
#include <glib/gstdio.h>
25
#include "glibintl.h"
26
#include "gioerror.h"
27
#include "gcancellable.h"
28
#include "glocalfileiostream.h"
29
#include "glocalfileinputstream.h"
30
#include "glocalfileinfo.h"
31
32
#ifdef G_OS_UNIX
33
#include "gfiledescriptorbased.h"
34
#endif
35
36
37
#define g_local_file_io_stream_get_type _g_local_file_io_stream_get_type
38
G_DEFINE_TYPE (GLocalFileIOStream, g_local_file_io_stream, G_TYPE_FILE_IO_STREAM)
39
40
static void
41
g_local_file_io_stream_finalize (GObject *object)
42
0
{
43
0
  GLocalFileIOStream *file;
44
45
0
  file = G_LOCAL_FILE_IO_STREAM (object);
46
47
0
  g_object_unref (file->input_stream);
48
0
  g_object_unref (file->output_stream);
49
50
0
  G_OBJECT_CLASS (g_local_file_io_stream_parent_class)->finalize (object);
51
0
}
52
53
GFileIOStream *
54
_g_local_file_io_stream_new (GLocalFileOutputStream *output_stream)
55
0
{
56
0
  GLocalFileIOStream *stream;
57
0
  int fd;
58
59
0
  stream = g_object_new (G_TYPE_LOCAL_FILE_IO_STREAM, NULL);
60
0
  stream->output_stream = g_object_ref (G_OUTPUT_STREAM (output_stream));
61
0
  _g_local_file_output_stream_set_do_close (output_stream, FALSE);
62
0
  fd = _g_local_file_output_stream_get_fd (output_stream);
63
0
  stream->input_stream = (GInputStream *)_g_local_file_input_stream_new (fd);
64
65
0
  _g_local_file_input_stream_set_do_close (G_LOCAL_FILE_INPUT_STREAM (stream->input_stream),
66
0
             FALSE);
67
68
0
  return G_FILE_IO_STREAM (stream);
69
0
}
70
71
static GInputStream *
72
g_local_file_io_stream_get_input_stream (GIOStream *stream)
73
0
{
74
0
  return G_LOCAL_FILE_IO_STREAM (stream)->input_stream;
75
0
}
76
77
static GOutputStream *
78
g_local_file_io_stream_get_output_stream (GIOStream *stream)
79
0
{
80
0
  return G_LOCAL_FILE_IO_STREAM (stream)->output_stream;
81
0
}
82
83
84
static gboolean
85
g_local_file_io_stream_close (GIOStream  *stream,
86
            GCancellable   *cancellable,
87
            GError        **error)
88
0
{
89
0
  GLocalFileIOStream *file = G_LOCAL_FILE_IO_STREAM (stream);
90
91
  /* There are shortcutted and can't fail */
92
0
  g_output_stream_close (file->output_stream, cancellable, NULL);
93
0
  g_input_stream_close (file->input_stream, cancellable, NULL);
94
95
0
  return
96
0
    _g_local_file_output_stream_really_close (G_LOCAL_FILE_OUTPUT_STREAM (file->output_stream),
97
0
                cancellable, error);
98
0
}
99
100
static void
101
g_local_file_io_stream_class_init (GLocalFileIOStreamClass *klass)
102
0
{
103
0
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
104
0
  GIOStreamClass *stream_class = G_IO_STREAM_CLASS (klass);
105
106
0
  gobject_class->finalize = g_local_file_io_stream_finalize;
107
108
0
  stream_class->get_input_stream = g_local_file_io_stream_get_input_stream;
109
0
  stream_class->get_output_stream = g_local_file_io_stream_get_output_stream;
110
0
  stream_class->close_fn = g_local_file_io_stream_close;
111
0
}
112
113
static void
114
g_local_file_io_stream_init (GLocalFileIOStream *stream)
115
0
{
116
0
}