2002-12-06 22:06:25 +00:00
|
|
|
|
/* data-compat.c - Compatibility interfaces for data objects.
|
2018-11-16 12:27:33 +00:00
|
|
|
|
* Copyright (C) 2002, 2003, 2004, 2007 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 Lesser General Public License as
|
|
|
|
|
* published by the Free Software Foundation; either version 2.1 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
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this program; if not, see <https://gnu.org/licenses/>.
|
|
|
|
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
|
*/
|
2002-10-09 12:26:00 +00:00
|
|
|
|
|
|
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <errno.h>
|
2010-11-02 16:27:46 +00:00
|
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
|
# include <sys/time.h>
|
|
|
|
|
#endif
|
2010-11-03 09:56:27 +00:00
|
|
|
|
#ifdef HAVE_SYS_STAT_H
|
|
|
|
|
# include <sys/stat.h>
|
|
|
|
|
#endif
|
2002-10-09 12:26:00 +00:00
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
#include "data.h"
|
|
|
|
|
#include "util.h"
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
#include "debug.h"
|
2002-10-09 12:26:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Create a new data buffer filled with LENGTH bytes starting from
|
|
|
|
|
OFFSET within the file FNAME or stream STREAM (exactly one must be
|
|
|
|
|
non-zero). */
|
2003-05-18 20:45:24 +00:00
|
|
|
|
gpgme_error_t
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
gpgme_data_new_from_filepart (gpgme_data_t *r_dh, const char *fname,
|
Make definition of off_t robust against misbehaving w32 toolchains.
* configure.ac (NEED__FILE_OFFSET_BITS): Change to define gpgme_off_t
and gpgme_ssize_t.
(API__OFF_T, API__SSIZE_T): New ac_subst.
* src/gpgme.h.in: Replace all ssize_t and off_t by ac_subst macros.
* src/assuan-support.c, src/ath-pthread.c, src/ath.c, src/ath.h
* src/data-compat.c, src/data-fd.c, src/data-mem.c, src/data-stream.c
* src/data-user.c, src/data.c, src/data.h, src/engine-gpgsm.c
* src/engine-uiserver.c, src/gpgme-tool.c, src/gpgme.c: Replace off_t
by gpgme_off_t and sszie_t by gpgme_ssize_t.
* src/ath-pthread.c, src/ath.h: Include gpgme.h.
--
For a detailed description, see the gpgme.texi diff.
2013-04-25 11:00:16 +00:00
|
|
|
|
FILE *stream, gpgme_off_t offset, size_t length)
|
2002-10-09 12:26:00 +00:00
|
|
|
|
{
|
2003-05-18 20:45:24 +00:00
|
|
|
|
gpgme_error_t err;
|
2002-10-09 12:26:00 +00:00
|
|
|
|
char *buf = NULL;
|
2004-02-01 13:39:45 +00:00
|
|
|
|
int res;
|
2002-10-09 12:26:00 +00:00
|
|
|
|
|
2018-11-16 15:25:49 +00:00
|
|
|
|
TRACE_BEG (DEBUG_DATA, "gpgme_data_new_from_filepart", r_dh,
|
2018-11-16 15:57:09 +00:00
|
|
|
|
"file_name=%s, stream=%p, offset=%lli, length=%zu",
|
|
|
|
|
fname, stream, (long long int)offset, length);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
|
2002-10-09 12:26:00 +00:00
|
|
|
|
if (stream && fname)
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
|
2002-10-09 12:26:00 +00:00
|
|
|
|
|
|
|
|
|
if (fname)
|
|
|
|
|
stream = fopen (fname, "rb");
|
|
|
|
|
if (!stream)
|
2013-02-06 16:35:40 +00:00
|
|
|
|
return TRACE_ERR (gpg_error_from_syserror ());
|
2002-10-09 12:26:00 +00:00
|
|
|
|
|
2004-02-01 13:39:45 +00:00
|
|
|
|
#ifdef HAVE_FSEEKO
|
|
|
|
|
res = fseeko (stream, offset, SEEK_SET);
|
|
|
|
|
#else
|
|
|
|
|
/* FIXME: Check for overflow, or at least bail at compilation. */
|
|
|
|
|
res = fseek (stream, offset, SEEK_SET);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (res)
|
2003-06-05 23:20:29 +00:00
|
|
|
|
{
|
2013-02-06 16:35:40 +00:00
|
|
|
|
int saved_err = gpg_error_from_syserror ();
|
2003-06-05 23:20:29 +00:00
|
|
|
|
if (fname)
|
|
|
|
|
fclose (stream);
|
2013-02-06 16:35:40 +00:00
|
|
|
|
return TRACE_ERR (saved_err);
|
2003-06-05 23:20:29 +00:00
|
|
|
|
}
|
2002-10-09 12:26:00 +00:00
|
|
|
|
|
|
|
|
|
buf = malloc (length);
|
|
|
|
|
if (!buf)
|
2003-06-05 23:20:29 +00:00
|
|
|
|
{
|
2013-02-06 16:35:40 +00:00
|
|
|
|
int saved_err = gpg_error_from_syserror ();
|
2003-06-05 23:20:29 +00:00
|
|
|
|
if (fname)
|
|
|
|
|
fclose (stream);
|
2013-02-06 16:35:40 +00:00
|
|
|
|
return TRACE_ERR (saved_err);
|
2003-06-05 23:20:29 +00:00
|
|
|
|
}
|
2002-10-09 12:26:00 +00:00
|
|
|
|
|
|
|
|
|
while (fread (buf, length, 1, stream) < 1
|
|
|
|
|
&& ferror (stream) && errno == EINTR);
|
|
|
|
|
if (ferror (stream))
|
|
|
|
|
{
|
2013-02-06 16:35:40 +00:00
|
|
|
|
int saved_err = gpg_error_from_syserror ();
|
2002-10-09 12:26:00 +00:00
|
|
|
|
if (buf)
|
|
|
|
|
free (buf);
|
2003-06-05 23:20:29 +00:00
|
|
|
|
if (fname)
|
|
|
|
|
fclose (stream);
|
2013-02-06 16:35:40 +00:00
|
|
|
|
return TRACE_ERR (saved_err);
|
2002-10-09 12:26:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fname)
|
|
|
|
|
fclose (stream);
|
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
err = gpgme_data_new (r_dh);
|
2002-10-09 12:26:00 +00:00
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
if (buf)
|
|
|
|
|
free (buf);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
(*r_dh)->data.mem.buffer = buf;
|
|
|
|
|
(*r_dh)->data.mem.size = length;
|
|
|
|
|
(*r_dh)->data.mem.length = length;
|
|
|
|
|
|
2018-11-16 17:17:22 +00:00
|
|
|
|
TRACE_SUC ("r_dh=%p", *r_dh);
|
|
|
|
|
return 0;
|
2002-10-09 12:26:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Create a new data buffer filled with the content of file FNAME.
|
|
|
|
|
COPY must be non-zero (delayed reads are not supported yet). */
|
2003-05-18 20:45:24 +00:00
|
|
|
|
gpgme_error_t
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
gpgme_data_new_from_file (gpgme_data_t *r_dh, const char *fname, int copy)
|
2002-10-09 12:26:00 +00:00
|
|
|
|
{
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
gpgme_error_t err;
|
2002-10-09 12:26:00 +00:00
|
|
|
|
struct stat statbuf;
|
2018-11-16 15:25:49 +00:00
|
|
|
|
TRACE_BEG (DEBUG_DATA, "gpgme_data_new_from_file", r_dh,
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
"file_name=%s, copy=%i (%s)", fname, copy, copy ? "yes" : "no");
|
2002-10-09 12:26:00 +00:00
|
|
|
|
|
|
|
|
|
if (!fname || !copy)
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
|
2002-10-09 12:26:00 +00:00
|
|
|
|
|
|
|
|
|
if (stat (fname, &statbuf) < 0)
|
2013-02-06 16:35:40 +00:00
|
|
|
|
return TRACE_ERR (gpg_error_from_syserror ());
|
2002-10-09 12:26:00 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
err = gpgme_data_new_from_filepart (r_dh, fname, NULL, 0, statbuf.st_size);
|
|
|
|
|
return TRACE_ERR (err);
|
2002-10-09 12:26:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2003-05-18 20:45:24 +00:00
|
|
|
|
gpgme_error_to_errno (gpgme_error_t err)
|
2002-10-09 12:26:00 +00:00
|
|
|
|
{
|
2015-10-16 00:51:42 +00:00
|
|
|
|
int res = gpg_err_code_to_errno (gpg_err_code (err));
|
2003-06-05 23:20:29 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
if (!err)
|
2002-10-09 12:26:00 +00:00
|
|
|
|
{
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
switch (gpg_err_code (err))
|
|
|
|
|
{
|
|
|
|
|
case GPG_ERR_EOF:
|
|
|
|
|
res = 0;
|
|
|
|
|
break;
|
|
|
|
|
case GPG_ERR_INV_VALUE:
|
|
|
|
|
res = EINVAL;
|
|
|
|
|
break;
|
|
|
|
|
case GPG_ERR_NOT_SUPPORTED:
|
|
|
|
|
res = ENOSYS;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
/* FIXME: Yeah, well. */
|
|
|
|
|
res = EINVAL;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2002-10-09 12:26:00 +00:00
|
|
|
|
}
|
2019-06-05 13:48:33 +00:00
|
|
|
|
TRACE (DEBUG_DATA, "gpgme:gpgme_error_to_errno", NULL,
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
"mapping %s <%s> to: %s", gpgme_strerror (err),
|
|
|
|
|
gpgme_strsource (err), strerror (res));
|
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Require libgpg-error 1.8.
src/
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* sign.c, data-user.c, conversion.c, debug.c, verify.c, data.c,
decrypt.c, delete.c, assuan-support.c, import.c, engine-gpgsm.c,
data-mem.c, op-support.c, w32-io.c, w32-util.c, data-compat.c: Use
gpg_error_from_syserror instead gpg_error_from_errno, and use
gpg_err_set_errno to set error number.
* setenv.c: Include <gpg-error.h> and define __set_errno to use
gpg_err_set_errno.
* gpgme-tool.c (ARGP_ERR_UNKNOWN): Define to EDEADLOCK (which is
mapped in Windows CE) instead of E2BIG (which is not).
(gt_import_keys): Initialize err.
2010-05-06 13:39:55 +00:00
|
|
|
|
gpg_err_set_errno (res);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return res ? -1 : 0;
|
2002-10-09 12:26:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-06-05 23:20:29 +00:00
|
|
|
|
|
Make definition of off_t robust against misbehaving w32 toolchains.
* configure.ac (NEED__FILE_OFFSET_BITS): Change to define gpgme_off_t
and gpgme_ssize_t.
(API__OFF_T, API__SSIZE_T): New ac_subst.
* src/gpgme.h.in: Replace all ssize_t and off_t by ac_subst macros.
* src/assuan-support.c, src/ath-pthread.c, src/ath.c, src/ath.h
* src/data-compat.c, src/data-fd.c, src/data-mem.c, src/data-stream.c
* src/data-user.c, src/data.c, src/data.h, src/engine-gpgsm.c
* src/engine-uiserver.c, src/gpgme-tool.c, src/gpgme.c: Replace off_t
by gpgme_off_t and sszie_t by gpgme_ssize_t.
* src/ath-pthread.c, src/ath.h: Include gpgme.h.
--
For a detailed description, see the gpgme.texi diff.
2013-04-25 11:00:16 +00:00
|
|
|
|
static gpgme_ssize_t
|
2003-05-18 20:45:24 +00:00
|
|
|
|
old_user_read (gpgme_data_t dh, void *buffer, size_t size)
|
2002-10-09 12:26:00 +00:00
|
|
|
|
{
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
gpgme_error_t err;
|
2002-10-09 12:26:00 +00:00
|
|
|
|
size_t amt;
|
2018-11-16 15:25:49 +00:00
|
|
|
|
TRACE_BEG (DEBUG_DATA, "gpgme:old_user_read", dh,
|
2018-11-16 15:57:09 +00:00
|
|
|
|
"buffer=%p, size=%zu", buffer, size);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
|
|
|
|
|
err = (*dh->data.old_user.cb) (dh->data.old_user.handle,
|
|
|
|
|
buffer, size, &amt);
|
2002-10-09 12:26:00 +00:00
|
|
|
|
if (err)
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_SYSRES (gpgme_error_to_errno (err));
|
2018-11-16 15:57:09 +00:00
|
|
|
|
return TRACE_SYSRES ((int)amt);
|
2002-10-09 12:26:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
Make definition of off_t robust against misbehaving w32 toolchains.
* configure.ac (NEED__FILE_OFFSET_BITS): Change to define gpgme_off_t
and gpgme_ssize_t.
(API__OFF_T, API__SSIZE_T): New ac_subst.
* src/gpgme.h.in: Replace all ssize_t and off_t by ac_subst macros.
* src/assuan-support.c, src/ath-pthread.c, src/ath.c, src/ath.h
* src/data-compat.c, src/data-fd.c, src/data-mem.c, src/data-stream.c
* src/data-user.c, src/data.c, src/data.h, src/engine-gpgsm.c
* src/engine-uiserver.c, src/gpgme-tool.c, src/gpgme.c: Replace off_t
by gpgme_off_t and sszie_t by gpgme_ssize_t.
* src/ath-pthread.c, src/ath.h: Include gpgme.h.
--
For a detailed description, see the gpgme.texi diff.
2013-04-25 11:00:16 +00:00
|
|
|
|
static gpgme_off_t
|
|
|
|
|
old_user_seek (gpgme_data_t dh, gpgme_off_t offset, int whence)
|
2002-10-09 12:26:00 +00:00
|
|
|
|
{
|
2003-05-18 20:45:24 +00:00
|
|
|
|
gpgme_error_t err;
|
2018-11-16 15:25:49 +00:00
|
|
|
|
TRACE_BEG (DEBUG_DATA, "gpgme:old_user_seek", dh,
|
2018-11-16 15:57:09 +00:00
|
|
|
|
"offset=%llu, whence=%i", (long long int)offset, whence);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
|
2002-10-09 12:26:00 +00:00
|
|
|
|
if (whence != SEEK_SET || offset)
|
2007-07-13 14:47:07 +00:00
|
|
|
|
{
|
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Require libgpg-error 1.8.
src/
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* sign.c, data-user.c, conversion.c, debug.c, verify.c, data.c,
decrypt.c, delete.c, assuan-support.c, import.c, engine-gpgsm.c,
data-mem.c, op-support.c, w32-io.c, w32-util.c, data-compat.c: Use
gpg_error_from_syserror instead gpg_error_from_errno, and use
gpg_err_set_errno to set error number.
* setenv.c: Include <gpg-error.h> and define __set_errno to use
gpg_err_set_errno.
* gpgme-tool.c (ARGP_ERR_UNKNOWN): Define to EDEADLOCK (which is
mapped in Windows CE) instead of E2BIG (which is not).
(gt_import_keys): Initialize err.
2010-05-06 13:39:55 +00:00
|
|
|
|
gpg_err_set_errno (EINVAL);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_SYSRES (-1);
|
2007-07-13 14:47:07 +00:00
|
|
|
|
}
|
2002-10-09 12:26:00 +00:00
|
|
|
|
err = (*dh->data.old_user.cb) (dh->data.old_user.handle, NULL, 0, NULL);
|
|
|
|
|
if (err)
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_SYSRES (gpgme_error_to_errno (err));
|
|
|
|
|
return TRACE_SYSRES (0);
|
2002-10-09 12:26:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-18 20:45:24 +00:00
|
|
|
|
static struct _gpgme_data_cbs old_user_cbs =
|
2002-10-09 12:26:00 +00:00
|
|
|
|
{
|
|
|
|
|
old_user_read,
|
|
|
|
|
NULL,
|
|
|
|
|
old_user_seek,
|
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Create a new data buffer which retrieves the data from the callback
|
|
|
|
|
function READ_CB. */
|
2003-05-18 20:45:24 +00:00
|
|
|
|
gpgme_error_t
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
gpgme_data_new_with_read_cb (gpgme_data_t *r_dh,
|
2002-10-09 12:26:00 +00:00
|
|
|
|
int (*read_cb) (void *, char *, size_t, size_t *),
|
|
|
|
|
void *read_cb_value)
|
|
|
|
|
{
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
gpgme_error_t err;
|
2018-11-16 15:25:49 +00:00
|
|
|
|
TRACE_BEG (DEBUG_DATA, "gpgme_data_new_with_read_cb", r_dh,
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
"read_cb=%p/%p", read_cb, read_cb_value);
|
|
|
|
|
|
|
|
|
|
err = _gpgme_data_new (r_dh, &old_user_cbs);
|
|
|
|
|
|
2002-10-09 12:26:00 +00:00
|
|
|
|
if (err)
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_ERR (err);
|
2002-10-09 12:26:00 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
(*r_dh)->data.old_user.cb = read_cb;
|
|
|
|
|
(*r_dh)->data.old_user.handle = read_cb_value;
|
|
|
|
|
return TRACE_ERR (0);
|
2002-10-09 12:26:00 +00:00
|
|
|
|
}
|