LCOV - code coverage report
Current view: top level - src - data-fd.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 10 15 66.7 %
Date: 2018-11-14 16:53:58 Functions: 3 5 60.0 %

          Line data    Source code
       1             : /* data-fd.c - A file descriptor based data object.
       2             :    Copyright (C) 2002, 2004 g10 Code GmbH
       3             : 
       4             :    This file is part of GPGME.
       5             : 
       6             :    GPGME is free software; you can redistribute it and/or modify it
       7             :    under the terms of the GNU Lesser General Public License as
       8             :    published by the Free Software Foundation; either version 2.1 of
       9             :    the License, or (at your option) any later version.
      10             : 
      11             :    GPGME is distributed in the hope that it will be useful, but
      12             :    WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14             :    Lesser General Public License for more details.
      15             : 
      16             :    You should have received a copy of the GNU Lesser General Public
      17             :    License along with this program; if not, write to the Free Software
      18             :    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
      19             :    02111-1307, USA.  */
      20             : 
      21             : #if HAVE_CONFIG_H
      22             : #include <config.h>
      23             : #endif
      24             : 
      25             : #ifdef HAVE_UNISTD_H
      26             : # include <unistd.h>
      27             : #endif
      28             : #ifdef HAVE_SYS_TYPES_H
      29             : # include <sys/types.h>
      30             : #endif
      31             : 
      32             : #include "debug.h"
      33             : #include "data.h"
      34             : 
      35             : 
      36             : static gpgme_ssize_t
      37          32 : fd_read (gpgme_data_t dh, void *buffer, size_t size)
      38             : {
      39          32 :   return read (dh->data.fd, buffer, size);
      40             : }
      41             : 
      42             : 
      43             : static gpgme_ssize_t
      44           4 : fd_write (gpgme_data_t dh, const void *buffer, size_t size)
      45             : {
      46           4 :   return write (dh->data.fd, buffer, size);
      47             : }
      48             : 
      49             : 
      50             : static gpgme_off_t
      51           0 : fd_seek (gpgme_data_t dh, gpgme_off_t offset, int whence)
      52             : {
      53           0 :   return lseek (dh->data.fd, offset, whence);
      54             : }
      55             : 
      56             : 
      57             : static int
      58           0 : fd_get_fd (gpgme_data_t dh)
      59             : {
      60           0 :   return (dh->data.fd);
      61             : }
      62             : 
      63             : 
      64             : static struct _gpgme_data_cbs fd_cbs =
      65             :   {
      66             :     fd_read,
      67             :     fd_write,
      68             :     fd_seek,
      69             :     NULL,
      70             :     fd_get_fd
      71             :   };
      72             : 
      73             : 
      74             : gpgme_error_t
      75          20 : gpgme_data_new_from_fd (gpgme_data_t *r_dh, int fd)
      76             : {
      77             :   gpgme_error_t err;
      78          20 :   TRACE_BEG1 (DEBUG_DATA, "gpgme_data_new_from_fd", r_dh, "fd=0x%x", fd);
      79             : 
      80          20 :   err = _gpgme_data_new (r_dh, &fd_cbs);
      81          20 :   if (err)
      82           0 :     return TRACE_ERR (err);
      83             : 
      84          20 :   (*r_dh)->data.fd = fd;
      85          20 :   return TRACE_SUC1 ("dh=%p", *r_dh);
      86             : }

Generated by: LCOV version 1.13