gpgme/trunk/gpgme/data-stream.c
Marcus Brinkmann 20a0d5bab8 2004-01-31 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Add invocation of AC_SYS_LARGEFILE, AC_TYPE_OFF_T
	and AC_FUNC_FSEEKO.

doc/
2004-02-01  Marcus Brinkmann  <marcus@g10code.de>

	* gpgme.texi (Largefile Support): New section.

gpgme/
2004-02-01  Marcus Brinkmann  <marcus@g10code.de>

	* data-compat.c (gpgme_data_new_from_filepart): Call fseeko if
	available.
	* data-stream.c (stream_seek): Likewise.
2004-02-01 13:39:45 +00:00

81 lines
1.9 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* data-stream.c - A stream based data object.
Copyright (C) 2002, 2004 g10 Code GmbH
This file is part of GPGME.
GPGME is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
GPGME is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GPGME; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#if HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <sys/types.h>
#include "data.h"
static ssize_t
stream_read (gpgme_data_t dh, void *buffer, size_t size)
{
size_t amt = fread (buffer, 1, size, dh->data.stream);
if (amt > 0)
return amt;
return ferror (dh->data.stream) ? -1 : 0;
}
static ssize_t
stream_write (gpgme_data_t dh, const void *buffer, size_t size)
{
size_t amt = fwrite (buffer, 1, size, dh->data.stream);
if (amt > 0)
return amt;
return ferror (dh->data.stream) ? -1 : 0;
}
static off_t
stream_seek (gpgme_data_t dh, off_t offset, int whence)
{
#ifdef HAVE_FSEEKO
return fseeko (dh->data.stream, offset, whence);
#else
/* FIXME: Check for overflow, or at least bail at compilation. */
return fseek (dh->data.stream, offset, whence);
#endif
}
static struct _gpgme_data_cbs stream_cbs =
{
stream_read,
stream_write,
stream_seek,
NULL
};
gpgme_error_t
gpgme_data_new_from_stream (gpgme_data_t *dh, FILE *stream)
{
gpgme_error_t err = _gpgme_data_new (dh, &stream_cbs);
if (err)
return err;
(*dh)->data.stream = stream;
return 0;
}