Blame src/data-fd.c

Packit Service 0ef63b
/* data-fd.c - A file descriptor based data object.
Packit Service 0ef63b
 * Copyright (C) 2002, 2004 g10 Code GmbH
Packit Service 0ef63b
 *
Packit Service 0ef63b
 * This file is part of GPGME.
Packit Service 0ef63b
 *
Packit Service 0ef63b
 * GPGME is free software; you can redistribute it and/or modify it
Packit Service 0ef63b
 * under the terms of the GNU Lesser General Public License as
Packit Service 0ef63b
 * published by the Free Software Foundation; either version 2.1 of
Packit Service 0ef63b
 * the License, or (at your option) any later version.
Packit Service 0ef63b
 *
Packit Service 0ef63b
 * GPGME is distributed in the hope that it will be useful, but
Packit Service 0ef63b
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 0ef63b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 0ef63b
 * Lesser General Public License for more details.
Packit Service 0ef63b
 *
Packit Service 0ef63b
 * You should have received a copy of the GNU Lesser General Public
Packit Service 0ef63b
 * License along with this program; if not, see <https://gnu.org/licenses/>.
Packit Service 0ef63b
 * SPDX-License-Identifier: LGPL-2.1-or-later
Packit Service 0ef63b
 */
Packit Service 672cf4
Packit Service 672cf4
#if HAVE_CONFIG_H
Packit Service 672cf4
#include <config.h>
Packit Service 672cf4
#endif
Packit Service 672cf4
Packit Service 672cf4
#ifdef HAVE_UNISTD_H
Packit Service 672cf4
# include <unistd.h>
Packit Service 672cf4
#endif
Packit Service 672cf4
#ifdef HAVE_SYS_TYPES_H
Packit Service 672cf4
# include <sys/types.h>
Packit Service 672cf4
#endif
Packit Service 672cf4
Packit Service 672cf4
#include "debug.h"
Packit Service 672cf4
#include "data.h"
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
static gpgme_ssize_t
Packit Service 672cf4
fd_read (gpgme_data_t dh, void *buffer, size_t size)
Packit Service 672cf4
{
Packit Service 672cf4
  return read (dh->data.fd, buffer, size);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
static gpgme_ssize_t
Packit Service 672cf4
fd_write (gpgme_data_t dh, const void *buffer, size_t size)
Packit Service 672cf4
{
Packit Service 672cf4
  return write (dh->data.fd, buffer, size);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
static gpgme_off_t
Packit Service 672cf4
fd_seek (gpgme_data_t dh, gpgme_off_t offset, int whence)
Packit Service 672cf4
{
Packit Service 672cf4
  return lseek (dh->data.fd, offset, whence);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
static int
Packit Service 672cf4
fd_get_fd (gpgme_data_t dh)
Packit Service 672cf4
{
Packit Service 672cf4
  return (dh->data.fd);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
static struct _gpgme_data_cbs fd_cbs =
Packit Service 672cf4
  {
Packit Service 672cf4
    fd_read,
Packit Service 672cf4
    fd_write,
Packit Service 672cf4
    fd_seek,
Packit Service 672cf4
    NULL,
Packit Service 672cf4
    fd_get_fd
Packit Service 672cf4
  };
Packit Service 672cf4
Packit Service 672cf4

Packit Service 672cf4
gpgme_error_t
Packit Service 672cf4
gpgme_data_new_from_fd (gpgme_data_t *r_dh, int fd)
Packit Service 672cf4
{
Packit Service 672cf4
  gpgme_error_t err;
Packit Service 0ef63b
  TRACE_BEG  (DEBUG_DATA, "gpgme_data_new_from_fd", r_dh, "fd=%d", fd);
Packit Service 672cf4
Packit Service 672cf4
  err = _gpgme_data_new (r_dh, &fd_cbs);
Packit Service 672cf4
  if (err)
Packit Service 672cf4
    return TRACE_ERR (err);
Packit Service 672cf4
Packit Service 672cf4
  (*r_dh)->data.fd = fd;
Packit Service 0ef63b
  TRACE_SUC ("dh=%p", *r_dh);
Packit Service 0ef63b
  return 0;
Packit Service 672cf4
}