LCOV - code coverage report
Current view: top level - glib/gio - glocalfileiostream.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 34 34 100.0 %
Date: 2024-04-23 05:16:05 Functions: 10 10 100.0 %
Branches: 5 6 83.3 %

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

Generated by: LCOV version 1.14