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.
This commit is contained in:
Marcus Brinkmann 2010-05-06 13:39:55 +00:00
parent dfefe1b390
commit 749325d6c1
21 changed files with 109 additions and 108 deletions

View File

@ -1,3 +1,7 @@
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Require libgpg-error 1.8.
2010-03-15 Werner Koch <wk@g10code.com> 2010-03-15 Werner Koch <wk@g10code.com>
* configure.ac (emacs_local_vars_begin) * configure.ac (emacs_local_vars_begin)

2
README
View File

@ -41,7 +41,7 @@ Check that you have unmodified sources. See below on how to do this.
Don't skip it - this is an important step! Don't skip it - this is an important step!
To build GPGME, you need to install libgpg-error. You need at least To build GPGME, you need to install libgpg-error. You need at least
libgpg-error 0.5. libgpg-error 1.8.
For support of the OpenPGP protocol (default), you should use the For support of the OpenPGP protocol (default), you should use the
latest version of GnuPG 1.2 or 1.4, available at: latest version of GnuPG 1.2 or 1.4, available at:

View File

@ -283,7 +283,7 @@ if test "$ac_cv_func_timegm" != yes; then
fi fi
# Checking for libgpg-error. # Checking for libgpg-error.
AM_PATH_GPG_ERROR(1.4,, AC_MSG_ERROR([libgpg-error was not found])) AM_PATH_GPG_ERROR(1.8,, AC_MSG_ERROR([libgpg-error was not found]))
AC_DEFINE(GPG_ERR_SOURCE_DEFAULT, GPG_ERR_SOURCE_GPGME, AC_DEFINE(GPG_ERR_SOURCE_DEFAULT, GPG_ERR_SOURCE_GPGME,
[The default error source for GPGME.]) [The default error source for GPGME.])

View File

@ -77,7 +77,7 @@ my_recvmsg (assuan_context_t ctx, assuan_fd_t fd, assuan_msghdr_t msg,
int flags) int flags)
{ {
#ifdef HAVE_W32_SYSTEM #ifdef HAVE_W32_SYSTEM
errno = ENOSYS; gpg_err_set_errno (ENOSYS);
return -1; return -1;
#else #else
return _gpgme_io_recvmsg (fd, msg, flags); return _gpgme_io_recvmsg (fd, msg, flags);
@ -91,7 +91,7 @@ my_sendmsg (assuan_context_t ctx, assuan_fd_t fd, const assuan_msghdr_t msg,
int flags) int flags)
{ {
#ifdef HAVE_W32_SYSTEM #ifdef HAVE_W32_SYSTEM
errno = ENOSYS; gpg_err_set_errno (ENOSYS);
return -1; return -1;
#else #else
return _gpgme_io_sendmsg (fd, msg, flags); return _gpgme_io_sendmsg (fd, msg, flags);
@ -118,7 +118,7 @@ my_spawn (assuan_context_t ctx, pid_t *r_pid, const char *name,
if (! name) if (! name)
{ {
errno = ENOSYS; gpg_err_set_errno (ENOSYS);
return -1; return -1;
} }
@ -203,7 +203,7 @@ my_socketpair (assuan_context_t ctx, int namespace, int style,
int protocol, assuan_fd_t filedes[2]) int protocol, assuan_fd_t filedes[2])
{ {
#ifdef HAVE_W32_SYSTEM #ifdef HAVE_W32_SYSTEM
errno = ENOSYS; gpg_err_set_errno (ENOSYS);
return -1; return -1;
#else #else
/* FIXME: Debug output missing. */ /* FIXME: Debug output missing. */

View File

@ -93,7 +93,7 @@ _gpgme_decode_c_string (const char *src, char **destp, size_t len)
string. */ string. */
dest = malloc (strlen (src) + 1); dest = malloc (strlen (src) + 1);
if (!dest) if (!dest)
return gpg_error_from_errno (errno); return gpg_error_from_syserror ();
*destp = dest; *destp = dest;
} }
@ -198,7 +198,7 @@ _gpgme_decode_percent_string (const char *src, char **destp, size_t len,
string. */ string. */
dest = malloc (strlen (src) + 1); dest = malloc (strlen (src) + 1);
if (!dest) if (!dest)
return gpg_error_from_errno (errno); return gpg_error_from_syserror ();
*destp = dest; *destp = dest;
} }
@ -291,7 +291,7 @@ _gpgme_encode_percent_string (const char *src, char **destp, size_t len)
string. */ string. */
dest = malloc (destlen); dest = malloc (destlen);
if (!dest) if (!dest)
return gpg_error_from_errno (errno); return gpg_error_from_syserror ();
*destp = dest; *destp = dest;
} }

View File

@ -158,7 +158,7 @@ gpgme_error_to_errno (gpgme_error_t err)
TRACE3 (DEBUG_DATA, "gpgme:gpgme_error_to_errno", 0, TRACE3 (DEBUG_DATA, "gpgme:gpgme_error_to_errno", 0,
"mapping %s <%s> to: %s", gpgme_strerror (err), "mapping %s <%s> to: %s", gpgme_strerror (err),
gpgme_strsource (err), strerror (res)); gpgme_strsource (err), strerror (res));
errno = res; gpg_err_set_errno (res);
return res ? -1 : 0; return res ? -1 : 0;
} }
@ -188,7 +188,7 @@ old_user_seek (gpgme_data_t dh, off_t offset, int whence)
if (whence != SEEK_SET || offset) if (whence != SEEK_SET || offset)
{ {
errno = EINVAL; gpg_err_set_errno (EINVAL);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
err = (*dh->data.old_user.cb) (dh->data.old_user.handle, NULL, 0, NULL); err = (*dh->data.old_user.cb) (dh->data.old_user.handle, NULL, 0, NULL);

View File

@ -115,7 +115,7 @@ mem_seek (gpgme_data_t dh, off_t offset, int whence)
case SEEK_SET: case SEEK_SET:
if (offset < 0 || offset > dh->data.mem.length) if (offset < 0 || offset > dh->data.mem.length)
{ {
errno = EINVAL; gpg_err_set_errno (EINVAL);
return -1; return -1;
} }
dh->data.mem.offset = offset; dh->data.mem.offset = offset;
@ -124,7 +124,7 @@ mem_seek (gpgme_data_t dh, off_t offset, int whence)
if ((offset > 0 && dh->data.mem.length - dh->data.mem.offset < offset) if ((offset > 0 && dh->data.mem.length - dh->data.mem.offset < offset)
|| (offset < 0 && dh->data.mem.offset < -offset)) || (offset < 0 && dh->data.mem.offset < -offset))
{ {
errno = EINVAL; gpg_err_set_errno (EINVAL);
return -1; return -1;
} }
dh->data.mem.offset += offset; dh->data.mem.offset += offset;
@ -132,13 +132,13 @@ mem_seek (gpgme_data_t dh, off_t offset, int whence)
case SEEK_END: case SEEK_END:
if (offset > 0 || -offset > dh->data.mem.length) if (offset > 0 || -offset > dh->data.mem.length)
{ {
errno = EINVAL; gpg_err_set_errno (EINVAL);
return -1; return -1;
} }
dh->data.mem.offset = dh->data.mem.length - offset; dh->data.mem.offset = dh->data.mem.length - offset;
break; break;
default: default:
errno = EINVAL; gpg_err_set_errno (EINVAL);
return -1; return -1;
} }
return dh->data.mem.offset; return dh->data.mem.offset;

View File

@ -34,7 +34,7 @@ user_read (gpgme_data_t dh, void *buffer, size_t size)
{ {
if (!dh->data.user.cbs->read) if (!dh->data.user.cbs->read)
{ {
errno = EBADF; gpg_err_set_errno (EBADF);
return -1; return -1;
} }
@ -47,7 +47,7 @@ user_write (gpgme_data_t dh, const void *buffer, size_t size)
{ {
if (!dh->data.user.cbs->write) if (!dh->data.user.cbs->write)
{ {
errno = EBADF; gpg_err_set_errno (EBADF);
return -1; return -1;
} }
@ -60,7 +60,7 @@ user_seek (gpgme_data_t dh, off_t offset, int whence)
{ {
if (!dh->data.user.cbs->seek) if (!dh->data.user.cbs->seek)
{ {
errno = EBADF; gpg_err_set_errno (EBADF);
return -1; return -1;
} }

View File

@ -46,7 +46,7 @@ _gpgme_data_new (gpgme_data_t *r_dh, struct _gpgme_data_cbs *cbs)
*r_dh = NULL; *r_dh = NULL;
dh = calloc (1, sizeof (*dh)); dh = calloc (1, sizeof (*dh));
if (!dh) if (!dh)
return gpg_error_from_errno (errno); return gpg_error_from_syserror ();
dh->cbs = cbs; dh->cbs = cbs;
@ -79,12 +79,12 @@ gpgme_data_read (gpgme_data_t dh, void *buffer, size_t size)
if (!dh) if (!dh)
{ {
errno = EINVAL; gpg_err_set_errno (EINVAL);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
if (!dh->cbs->read) if (!dh->cbs->read)
{ {
errno = ENOSYS; gpg_err_set_errno (ENOSYS);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
do do
@ -107,12 +107,12 @@ gpgme_data_write (gpgme_data_t dh, const void *buffer, size_t size)
if (!dh) if (!dh)
{ {
errno = EINVAL; gpg_err_set_errno (EINVAL);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
if (!dh->cbs->write) if (!dh->cbs->write)
{ {
errno = ENOSYS; gpg_err_set_errno (ENOSYS);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
do do
@ -134,12 +134,12 @@ gpgme_data_seek (gpgme_data_t dh, off_t offset, int whence)
if (!dh) if (!dh)
{ {
errno = EINVAL; gpg_err_set_errno (EINVAL);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
if (!dh->cbs->seek) if (!dh->cbs->seek)
{ {
errno = ENOSYS; gpg_err_set_errno (ENOSYS);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
@ -216,7 +216,7 @@ gpgme_data_set_file_name (gpgme_data_t dh, const char *file_name)
{ {
dh->file_name = strdup (file_name); dh->file_name = strdup (file_name);
if (!dh->file_name) if (!dh->file_name)
return TRACE_ERR (gpg_error_from_errno (errno)); return TRACE_ERR (gpg_error_from_syserror ());
} }
else else
dh->file_name = 0; dh->file_name = 0;
@ -257,7 +257,7 @@ _gpgme_data_inbound_handler (void *opaque, int fd)
buflen = _gpgme_io_read (fd, buffer, BUFFER_SIZE); buflen = _gpgme_io_read (fd, buffer, BUFFER_SIZE);
if (buflen < 0) if (buflen < 0)
return gpg_error_from_errno (errno); return gpg_error_from_syserror ();
if (buflen == 0) if (buflen == 0)
{ {
_gpgme_io_close (fd); _gpgme_io_close (fd);
@ -268,7 +268,7 @@ _gpgme_data_inbound_handler (void *opaque, int fd)
{ {
ssize_t amt = gpgme_data_write (dh, bufp, buflen); ssize_t amt = gpgme_data_write (dh, bufp, buflen);
if (amt == 0 || (amt < 0 && errno != EINTR)) if (amt == 0 || (amt < 0 && errno != EINTR))
return TRACE_ERR (gpg_error_from_errno (errno)); return TRACE_ERR (gpg_error_from_syserror ());
bufp += amt; bufp += amt;
buflen -= amt; buflen -= amt;
} }
@ -290,7 +290,7 @@ _gpgme_data_outbound_handler (void *opaque, int fd)
{ {
ssize_t amt = gpgme_data_read (dh, dh->pending, BUFFER_SIZE); ssize_t amt = gpgme_data_read (dh, dh->pending, BUFFER_SIZE);
if (amt < 0) if (amt < 0)
return TRACE_ERR (gpg_error_from_errno (errno)); return TRACE_ERR (gpg_error_from_syserror ());
if (amt == 0) if (amt == 0)
{ {
_gpgme_io_close (fd); _gpgme_io_close (fd);
@ -314,7 +314,7 @@ _gpgme_data_outbound_handler (void *opaque, int fd)
} }
if (nwritten <= 0) if (nwritten <= 0)
return TRACE_ERR (gpg_error_from_errno (errno)); return TRACE_ERR (gpg_error_from_syserror ());
if (nwritten < dh->pending_len) if (nwritten < dh->pending_len)
memmove (dh->pending, dh->pending + nwritten, dh->pending_len - nwritten); memmove (dh->pending, dh->pending + nwritten, dh->pending_len - nwritten);

View File

@ -231,7 +231,7 @@ _gpgme_debug (int level, const char *format, ...)
UNLOCK (debug_lock); UNLOCK (debug_lock);
fflush (errfp); fflush (errfp);
errno = saved_errno; gpg_err_set_errno (saved_errno);
} }

View File

@ -126,7 +126,7 @@ parse_enc_to (char *args, gpgme_recipient_t *recp)
rec = malloc (sizeof (*rec)); rec = malloc (sizeof (*rec));
if (!rec) if (!rec)
return gpg_error_from_errno (errno); return gpg_error_from_syserror ();
rec->next = NULL; rec->next = NULL;
rec->keyid = rec->_keyid; rec->keyid = rec->_keyid;
@ -153,7 +153,7 @@ parse_enc_to (char *args, gpgme_recipient_t *recp)
if (*args) if (*args)
{ {
errno = 0; gpg_err_set_errno (0);
rec->pubkey_algo = strtol (args, &tail, 0); rec->pubkey_algo = strtol (args, &tail, 0);
if (errno || args == tail || *tail != ' ') if (errno || args == tail || *tail != ' ')
{ {
@ -239,7 +239,7 @@ _gpgme_decrypt_status_handler (void *priv, gpgme_status_code_t code,
{ {
opd->result.unsupported_algorithm = strdup (args); opd->result.unsupported_algorithm = strdup (args);
if (!opd->result.unsupported_algorithm) if (!opd->result.unsupported_algorithm)
return gpg_error_from_errno (errno); return gpg_error_from_syserror ();
} }
} }
} }

View File

@ -45,7 +45,7 @@ delete_status_handler (void *priv, gpgme_status_code_t code, char *args)
long problem; long problem;
char *tail; char *tail;
errno = 0; gpg_err_set_errno (0);
problem = strtol (args, &tail, 0); problem = strtol (args, &tail, 0);
if (errno || (*tail && *tail != ' ')) if (errno || (*tail && *tail != ' '))
return gpg_error (GPG_ERR_INV_ENGINE); return gpg_error (GPG_ERR_INV_ENGINE);

View File

@ -247,7 +247,7 @@ gpgsm_new (void **engine, const char *file_name, const char *home_dir)
gpgsm = calloc (1, sizeof *gpgsm); gpgsm = calloc (1, sizeof *gpgsm);
if (!gpgsm) if (!gpgsm)
return gpg_error_from_errno (errno); return gpg_error_from_syserror ();
gpgsm->status_cb.fd = -1; gpgsm->status_cb.fd = -1;
gpgsm->status_cb.dir = 1; gpgsm->status_cb.dir = 1;
@ -288,7 +288,7 @@ gpgsm_new (void **engine, const char *file_name, const char *home_dir)
#if !USE_DESCRIPTOR_PASSING #if !USE_DESCRIPTOR_PASSING
if (_gpgme_io_pipe (fds, 0) < 0) if (_gpgme_io_pipe (fds, 0) < 0)
{ {
err = gpg_error_from_errno (errno); err = gpg_error_from_syserror ();
goto leave; goto leave;
} }
gpgsm->input_cb.fd = fds[1]; gpgsm->input_cb.fd = fds[1];
@ -296,7 +296,7 @@ gpgsm_new (void **engine, const char *file_name, const char *home_dir)
if (_gpgme_io_pipe (fds, 1) < 0) if (_gpgme_io_pipe (fds, 1) < 0)
{ {
err = gpg_error_from_errno (errno); err = gpg_error_from_syserror ();
goto leave; goto leave;
} }
gpgsm->output_cb.fd = fds[0]; gpgsm->output_cb.fd = fds[0];
@ -304,7 +304,7 @@ gpgsm_new (void **engine, const char *file_name, const char *home_dir)
if (_gpgme_io_pipe (fds, 0) < 0) if (_gpgme_io_pipe (fds, 0) < 0)
{ {
err = gpg_error_from_errno (errno); err = gpg_error_from_syserror ();
goto leave; goto leave;
} }
gpgsm->message_cb.fd = fds[1]; gpgsm->message_cb.fd = fds[1];
@ -372,7 +372,7 @@ gpgsm_new (void **engine, const char *file_name, const char *home_dir)
if (asprintf (&optstr, "OPTION display=%s", dft_display) < 0) if (asprintf (&optstr, "OPTION display=%s", dft_display) < 0)
{ {
free (dft_display); free (dft_display);
err = gpg_error_from_errno (errno); err = gpg_error_from_syserror ();
goto leave; goto leave;
} }
free (dft_display); free (dft_display);
@ -398,7 +398,7 @@ gpgsm_new (void **engine, const char *file_name, const char *home_dir)
{ {
if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0) if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
{ {
err = gpg_error_from_errno (errno); err = gpg_error_from_syserror ();
goto leave; goto leave;
} }
err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL, NULL, err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL, NULL,
@ -415,7 +415,7 @@ gpgsm_new (void **engine, const char *file_name, const char *home_dir)
if (asprintf (&optstr, "OPTION ttytype=%s", dft_ttytype) < 0) if (asprintf (&optstr, "OPTION ttytype=%s", dft_ttytype) < 0)
{ {
free (dft_ttytype); free (dft_ttytype);
err = gpg_error_from_errno (errno); err = gpg_error_from_syserror ();
goto leave; goto leave;
} }
free (dft_ttytype); free (dft_ttytype);
@ -524,7 +524,7 @@ gpgsm_set_locale (void *engine, int category, const char *value)
return 0; return 0;
if (asprintf (&optstr, "OPTION %s=%s", catstr, value) < 0) if (asprintf (&optstr, "OPTION %s=%s", catstr, value) < 0)
err = gpg_error_from_errno (errno); err = gpg_error_from_syserror ();
else else
{ {
err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL, err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL,
@ -660,7 +660,7 @@ gpgsm_set_fd (engine_gpgsm_t gpgsm, fd_type_t fd_type, const char *opt)
int fds[2]; int fds[2];
if (_gpgme_io_pipe (fds, dir) < 0) if (_gpgme_io_pipe (fds, dir) < 0)
return gpg_error_from_errno (errno); return gpg_error_from_syserror ();
iocb_data->fd = dir ? fds[0] : fds[1]; iocb_data->fd = dir ? fds[0] : fds[1];
iocb_data->server_fd = dir ? fds[1] : fds[0]; iocb_data->server_fd = dir ? fds[1] : fds[0];
@ -832,7 +832,7 @@ status_handler (void *opaque, int fd)
{ {
char *newline = realloc (*aline, *alinelen + linelen + 1); char *newline = realloc (*aline, *alinelen + linelen + 1);
if (!newline) if (!newline)
err = gpg_error_from_errno (errno); err = gpg_error_from_syserror ();
else else
{ {
*aline = newline; *aline = newline;
@ -917,7 +917,7 @@ status_handler (void *opaque, int fd)
if (!nwritten || (nwritten < 0 && errno != EINTR) if (!nwritten || (nwritten < 0 && errno != EINTR)
|| nwritten > linelen) || nwritten > linelen)
{ {
err = gpg_error_from_errno (errno); err = gpg_error_from_syserror ();
break; break;
} }
src += nwritten; src += nwritten;
@ -1115,7 +1115,7 @@ gpgsm_delete (void *engine, gpgme_key_t key, int allow_secret)
line = malloc (length); line = malloc (length);
if (!line) if (!line)
return gpg_error_from_errno (errno); return gpg_error_from_syserror ();
strcpy (line, "DELKEYS "); strcpy (line, "DELKEYS ");
linep = &line[8]; linep = &line[8];
@ -1172,7 +1172,7 @@ set_recipients (engine_gpgsm_t gpgsm, gpgme_key_t recp[])
linelen = 10 + 40 + 1; /* "RECIPIENT " + guess + '\0'. */ linelen = 10 + 40 + 1; /* "RECIPIENT " + guess + '\0'. */
line = malloc (10 + 40 + 1); line = malloc (10 + 40 + 1);
if (!line) if (!line)
return gpg_error_from_errno (errno); return gpg_error_from_syserror ();
strcpy (line, "RECIPIENT "); strcpy (line, "RECIPIENT ");
for (i =0; !err && recp[i]; i++) for (i =0; !err && recp[i]; i++)
{ {
@ -1278,7 +1278,7 @@ gpgsm_export (void *engine, const char *pattern, gpgme_export_mode_t mode,
cmd = malloc (7 + strlen (pattern) + 1); cmd = malloc (7 + strlen (pattern) + 1);
if (!cmd) if (!cmd)
return gpg_error_from_errno (errno); return gpg_error_from_syserror ();
strcpy (cmd, "EXPORT "); strcpy (cmd, "EXPORT ");
strcpy (&cmd[7], pattern); strcpy (&cmd[7], pattern);
@ -1335,7 +1335,7 @@ gpgsm_export_ext (void *engine, const char *pattern[], gpgme_export_mode_t mode,
} }
line = malloc (length); line = malloc (length);
if (!line) if (!line)
return gpg_error_from_errno (errno); return gpg_error_from_syserror ();
strcpy (line, "EXPORT "); strcpy (line, "EXPORT ");
linep = &line[7]; linep = &line[7];
@ -1552,7 +1552,7 @@ gpgsm_keylist (void *engine, const char *pattern, int secret_only,
/* Always send list-mode option because RESET does not reset it. */ /* Always send list-mode option because RESET does not reset it. */
if (asprintf (&line, "OPTION list-mode=%d", (list_mode & 3)) < 0) if (asprintf (&line, "OPTION list-mode=%d", (list_mode & 3)) < 0)
return gpg_error_from_errno (errno); return gpg_error_from_syserror ();
err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, line, NULL, NULL); err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, line, NULL, NULL);
free (line); free (line);
if (err) if (err)
@ -1580,7 +1580,7 @@ gpgsm_keylist (void *engine, const char *pattern, int secret_only,
/* Length is "LISTSECRETKEYS " + p + '\0'. */ /* Length is "LISTSECRETKEYS " + p + '\0'. */
line = malloc (15 + strlen (pattern) + 1); line = malloc (15 + strlen (pattern) + 1);
if (!line) if (!line)
return gpg_error_from_errno (errno); return gpg_error_from_syserror ();
if (secret_only) if (secret_only)
{ {
strcpy (line, "LISTSECRETKEYS "); strcpy (line, "LISTSECRETKEYS ");
@ -1626,7 +1626,7 @@ gpgsm_keylist_ext (void *engine, const char *pattern[], int secret_only,
/* Always send list-mode option because RESET does not reset it. */ /* Always send list-mode option because RESET does not reset it. */
if (asprintf (&line, "OPTION list-mode=%d", (list_mode & 3)) < 0) if (asprintf (&line, "OPTION list-mode=%d", (list_mode & 3)) < 0)
return gpg_error_from_errno (errno); return gpg_error_from_syserror ();
err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, line, NULL, NULL); err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, line, NULL, NULL);
free (line); free (line);
if (err) if (err)
@ -1663,7 +1663,7 @@ gpgsm_keylist_ext (void *engine, const char *pattern[], int secret_only,
} }
line = malloc (length); line = malloc (length);
if (!line) if (!line)
return gpg_error_from_errno (errno); return gpg_error_from_syserror ();
if (secret_only) if (secret_only)
{ {
strcpy (line, "LISTSECRETKEYS "); strcpy (line, "LISTSECRETKEYS ");
@ -1749,7 +1749,7 @@ gpgsm_sign (void *engine, gpgme_data_t in, gpgme_data_t out,
requested. */ requested. */
if (asprintf (&assuan_cmd, "OPTION include-certs %i", include_certs) < 0) if (asprintf (&assuan_cmd, "OPTION include-certs %i", include_certs) < 0)
return gpg_error_from_errno (errno); return gpg_error_from_syserror ();
err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, assuan_cmd, err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, assuan_cmd,
NULL, NULL); NULL, NULL);
free (assuan_cmd); free (assuan_cmd);

View File

@ -107,7 +107,7 @@ struct argp_state
void *pstate; void *pstate;
}; };
#define ARGP_ERR_UNKNOWN E2BIG #define ARGP_ERR_UNKNOWN EDEADLOCK
#define ARGP_KEY_ARG 0 #define ARGP_KEY_ARG 0
#define ARGP_KEY_ARGS 0x1000006 #define ARGP_KEY_ARGS 0x1000006
#define ARGP_KEY_END 0x1000001 #define ARGP_KEY_END 0x1000001
@ -1651,7 +1651,7 @@ gt_genkey (gpgme_tool_t gt, const char *parms, gpgme_data_t public,
gpg_error_t gpg_error_t
gt_import_keys (gpgme_tool_t gt, char *fpr[]) gt_import_keys (gpgme_tool_t gt, char *fpr[])
{ {
gpg_error_t err; gpg_error_t err = 0;
int cnt; int cnt;
int idx; int idx;
gpgme_key_t *keys; gpgme_key_t *keys;

View File

@ -121,10 +121,10 @@ parse_import (char *args, gpgme_import_status_t *import_status, int problem)
import = malloc (sizeof (*import)); import = malloc (sizeof (*import));
if (!import) if (!import)
return gpg_error_from_errno (errno); return gpg_error_from_syserror ();
import->next = NULL; import->next = NULL;
errno = 0; gpg_err_set_errno (0);
nr = strtol (args, &tail, 0); nr = strtol (args, &tail, 0);
if (errno || args == tail || *tail != ' ') if (errno || args == tail || *tail != ' ')
{ {
@ -189,7 +189,7 @@ parse_import_res (char *args, gpgme_import_result_t result)
{ {
char *tail; char *tail;
errno = 0; gpg_err_set_errno (0);
#define PARSE_NEXT(x) \ #define PARSE_NEXT(x) \
(x) = strtol (args, &tail, 0); \ (x) = strtol (args, &tail, 0); \

View File

@ -182,7 +182,7 @@ _gpgme_parse_inv_recp (char *args, gpgme_invalid_key_t *key)
if (!inv_key) if (!inv_key)
return gpg_error_from_errno (errno); return gpg_error_from_errno (errno);
inv_key->next = NULL; inv_key->next = NULL;
errno = 0; gpg_err_set_errno (0);
reason = strtol (args, &tail, 0); reason = strtol (args, &tail, 0);
if (errno || args == tail || (*tail && *tail != ' ')) if (errno || args == tail || (*tail && *tail != ' '))
{ {
@ -299,7 +299,7 @@ _gpgme_parse_plaintext (char *args, char **filenamep)
{ {
char *filename = strdup (args); char *filename = strdup (args);
if (!filename) if (!filename)
return gpg_error_from_errno (errno); return gpg_error_from_syserror ();
*filenamep = filename; *filenamep = filename;
} }

View File

@ -20,6 +20,9 @@
# include <config.h> # include <config.h>
#endif #endif
#include <gpg-error.h>
#define __set_errno(ev) (gpg_err_set_errno (ev))
#if HAVE_ASSUAN_H #if HAVE_ASSUAN_H
/* Fixme: Why do we need to include the assuan header and why the /* Fixme: Why do we need to include the assuan header and why the
internal ones? */ internal ones? */
@ -29,12 +32,6 @@
#define __builtin_expect(cond,val) (cond) #define __builtin_expect(cond,val) (cond)
#include <errno.h> #include <errno.h>
#if !_LIBC
# if !defined errno && !defined HAVE_ERRNO_DECL
extern int errno;
# endif
# define __set_errno(ev) ((errno) = (ev))
#endif
#if _LIBC || HAVE_STDLIB_H #if _LIBC || HAVE_STDLIB_H
# include <stdlib.h> # include <stdlib.h>

View File

@ -149,7 +149,7 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp)
sig = malloc (sizeof (*sig)); sig = malloc (sizeof (*sig));
if (!sig) if (!sig)
return gpg_error_from_errno (errno); return gpg_error_from_syserror ();
sig->next = NULL; sig->next = NULL;
switch (*args) switch (*args)
@ -179,7 +179,7 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp)
return gpg_error (GPG_ERR_INV_ENGINE); return gpg_error (GPG_ERR_INV_ENGINE);
} }
errno = 0; gpg_err_set_errno (0);
sig->pubkey_algo = strtol (args, &tail, 0); sig->pubkey_algo = strtol (args, &tail, 0);
if (errno || args == tail || *tail != ' ') if (errno || args == tail || *tail != ' ')
{ {

View File

@ -227,7 +227,7 @@ prepare_new_sig (op_data_t opd)
{ {
sig = calloc (1, sizeof (*sig)); sig = calloc (1, sizeof (*sig));
if (!sig) if (!sig)
return gpg_error_from_errno (errno); return gpg_error_from_syserror ();
if (!opd->result.signatures) if (!opd->result.signatures)
opd->result.signatures = sig; opd->result.signatures = sig;
if (opd->current_sig) if (opd->current_sig)
@ -293,7 +293,7 @@ parse_new_sig (op_data_t opd, gpgme_status_code_t code, char *args)
/* Parse the pubkey algo. */ /* Parse the pubkey algo. */
if (!end) if (!end)
goto parse_err_sig_fail; goto parse_err_sig_fail;
errno = 0; gpg_err_set_errno (0);
sig->pubkey_algo = strtol (end, &tail, 0); sig->pubkey_algo = strtol (end, &tail, 0);
if (errno || end == tail || *tail != ' ') if (errno || end == tail || *tail != ' ')
goto parse_err_sig_fail; goto parse_err_sig_fail;
@ -304,7 +304,7 @@ parse_new_sig (op_data_t opd, gpgme_status_code_t code, char *args)
/* Parse the hash algo. */ /* Parse the hash algo. */
if (!*end) if (!*end)
goto parse_err_sig_fail; goto parse_err_sig_fail;
errno = 0; gpg_err_set_errno (0);
sig->hash_algo = strtol (end, &tail, 0); sig->hash_algo = strtol (end, &tail, 0);
if (errno || end == tail || *tail != ' ') if (errno || end == tail || *tail != ' ')
goto parse_err_sig_fail; goto parse_err_sig_fail;
@ -362,7 +362,7 @@ parse_new_sig (op_data_t opd, gpgme_status_code_t code, char *args)
{ {
sig->fpr = strdup (args); sig->fpr = strdup (args);
if (!sig->fpr) if (!sig->fpr)
return gpg_error_from_errno (errno); return gpg_error_from_syserror ();
} }
return 0; return 0;
} }
@ -386,7 +386,7 @@ parse_valid_sig (gpgme_signature_t sig, char *args)
free (sig->fpr); free (sig->fpr);
sig->fpr = strdup (args); sig->fpr = strdup (args);
if (!sig->fpr) if (!sig->fpr)
return gpg_error_from_errno (errno); return gpg_error_from_syserror ();
/* Skip the creation date. */ /* Skip the creation date. */
end = strchr (end, ' '); end = strchr (end, ' ');
@ -418,7 +418,7 @@ parse_valid_sig (gpgme_signature_t sig, char *args)
if (end) if (end)
{ {
/* Parse the pubkey algo. */ /* Parse the pubkey algo. */
errno = 0; gpg_err_set_errno (0);
sig->pubkey_algo = strtol (end, &tail, 0); sig->pubkey_algo = strtol (end, &tail, 0);
if (errno || end == tail || *tail != ' ') if (errno || end == tail || *tail != ' ')
return gpg_error (GPG_ERR_INV_ENGINE); return gpg_error (GPG_ERR_INV_ENGINE);
@ -431,7 +431,7 @@ parse_valid_sig (gpgme_signature_t sig, char *args)
{ {
/* Parse the hash algo. */ /* Parse the hash algo. */
errno = 0; gpg_err_set_errno (0);
sig->hash_algo = strtol (end, &tail, 0); sig->hash_algo = strtol (end, &tail, 0);
if (errno || end == tail || *tail != ' ') if (errno || end == tail || *tail != ' ')
return gpg_error (GPG_ERR_INV_ENGINE); return gpg_error (GPG_ERR_INV_ENGINE);
@ -526,14 +526,14 @@ parse_notation (gpgme_signature_t sig, gpgme_status_code_t code, char *args)
{ {
dest = notation->value = malloc (len); dest = notation->value = malloc (len);
if (!dest) if (!dest)
return gpg_error_from_errno (errno); return gpg_error_from_syserror ();
} }
else else
{ {
int cur_len = strlen (notation->value); int cur_len = strlen (notation->value);
dest = realloc (notation->value, len + strlen (notation->value)); dest = realloc (notation->value, len + strlen (notation->value));
if (!dest) if (!dest)
return gpg_error_from_errno (errno); return gpg_error_from_syserror ();
notation->value = dest; notation->value = dest;
dest += cur_len; dest += cur_len;
} }

View File

@ -166,7 +166,7 @@ set_synchronize (HANDLE hd)
TRACE1 (DEBUG_SYSIO, "gpgme:set_synchronize", hd, TRACE1 (DEBUG_SYSIO, "gpgme:set_synchronize", hd,
"DuplicateHandle failed: ec=%d", (int) GetLastError ()); "DuplicateHandle failed: ec=%d", (int) GetLastError ());
/* FIXME: Should translate the error code. */ /* FIXME: Should translate the error code. */
errno = EIO; gpg_err_set_errno (EIO);
return INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE;
} }
@ -492,7 +492,7 @@ _gpgme_io_read (int fd, void *buffer, size_t count)
ctx = find_reader (fd, 1); ctx = find_reader (fd, 1);
if (!ctx) if (!ctx)
{ {
errno = EBADF; gpg_err_set_errno (EBADF);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
if (ctx->eof_shortcut) if (ctx->eof_shortcut)
@ -520,7 +520,7 @@ _gpgme_io_read (int fd, void *buffer, size_t count)
TRACE_LOG ("EOF but ctx->eof flag not set"); TRACE_LOG ("EOF but ctx->eof flag not set");
return 0; return 0;
} }
errno = ctx->error_code; gpg_err_set_errno (ctx->error_code);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
@ -538,7 +538,7 @@ _gpgme_io_read (int fd, void *buffer, size_t count)
TRACE_LOG1 ("ResetEvent failed: ec=%d", (int) GetLastError ()); TRACE_LOG1 ("ResetEvent failed: ec=%d", (int) GetLastError ());
UNLOCK (ctx->mutex); UNLOCK (ctx->mutex);
/* FIXME: Should translate the error code. */ /* FIXME: Should translate the error code. */
errno = EIO; gpg_err_set_errno (EIO);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
} }
@ -548,7 +548,7 @@ _gpgme_io_read (int fd, void *buffer, size_t count)
ctx->have_space_ev, (int) GetLastError ()); ctx->have_space_ev, (int) GetLastError ());
UNLOCK (ctx->mutex); UNLOCK (ctx->mutex);
/* FIXME: Should translate the error code. */ /* FIXME: Should translate the error code. */
errno = EIO; gpg_err_set_errno (EIO);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
UNLOCK (ctx->mutex); UNLOCK (ctx->mutex);
@ -837,7 +837,7 @@ _gpgme_io_write (int fd, const void *buffer, size_t count)
TRACE_LOG1 ("ResetEvent failed: ec=%d", (int) GetLastError ()); TRACE_LOG1 ("ResetEvent failed: ec=%d", (int) GetLastError ());
UNLOCK (ctx->mutex); UNLOCK (ctx->mutex);
/* FIXME: Should translate the error code. */ /* FIXME: Should translate the error code. */
errno = EIO; gpg_err_set_errno (EIO);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
UNLOCK (ctx->mutex); UNLOCK (ctx->mutex);
@ -851,9 +851,9 @@ _gpgme_io_write (int fd, const void *buffer, size_t count)
{ {
UNLOCK (ctx->mutex); UNLOCK (ctx->mutex);
if (ctx->error_code == ERROR_NO_DATA) if (ctx->error_code == ERROR_NO_DATA)
errno = EPIPE; gpg_err_set_errno (EPIPE);
else else
errno = EIO; gpg_err_set_errno (EIO);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
@ -873,7 +873,7 @@ _gpgme_io_write (int fd, const void *buffer, size_t count)
TRACE_LOG1 ("ResetEvent failed: ec=%d", (int) GetLastError ()); TRACE_LOG1 ("ResetEvent failed: ec=%d", (int) GetLastError ());
UNLOCK (ctx->mutex); UNLOCK (ctx->mutex);
/* FIXME: Should translate the error code. */ /* FIXME: Should translate the error code. */
errno = EIO; gpg_err_set_errno (EIO);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
if (!SetEvent (ctx->have_data)) if (!SetEvent (ctx->have_data))
@ -881,7 +881,7 @@ _gpgme_io_write (int fd, const void *buffer, size_t count)
TRACE_LOG1 ("SetEvent failed: ec=%d", (int) GetLastError ()); TRACE_LOG1 ("SetEvent failed: ec=%d", (int) GetLastError ());
UNLOCK (ctx->mutex); UNLOCK (ctx->mutex);
/* FIXME: Should translate the error code. */ /* FIXME: Should translate the error code. */
errno = EIO; gpg_err_set_errno (EIO);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
UNLOCK (ctx->mutex); UNLOCK (ctx->mutex);
@ -908,7 +908,7 @@ _gpgme_io_pipe (int filedes[2], int inherit_idx)
{ {
TRACE_LOG1 ("CreatePipe failed: ec=%d", (int) GetLastError ()); TRACE_LOG1 ("CreatePipe failed: ec=%d", (int) GetLastError ());
/* FIXME: Should translate the error code. */ /* FIXME: Should translate the error code. */
errno = EIO; gpg_err_set_errno (EIO);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
@ -926,7 +926,7 @@ _gpgme_io_pipe (int filedes[2], int inherit_idx)
CloseHandle (rh); CloseHandle (rh);
CloseHandle (wh); CloseHandle (wh);
/* FIXME: Should translate the error code. */ /* FIXME: Should translate the error code. */
errno = EIO; gpg_err_set_errno (EIO);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
CloseHandle (rh); CloseHandle (rh);
@ -940,7 +940,7 @@ _gpgme_io_pipe (int filedes[2], int inherit_idx)
CloseHandle (rh); CloseHandle (rh);
CloseHandle (wh); CloseHandle (wh);
/* FIXME: Should translate the error code. */ /* FIXME: Should translate the error code. */
errno = EIO; gpg_err_set_errno (EIO);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
} }
@ -957,7 +957,7 @@ _gpgme_io_pipe (int filedes[2], int inherit_idx)
CloseHandle (rh); CloseHandle (rh);
CloseHandle (wh); CloseHandle (wh);
/* FIXME: Should translate the error code. */ /* FIXME: Should translate the error code. */
errno = EIO; gpg_err_set_errno (EIO);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
CloseHandle (wh); CloseHandle (wh);
@ -971,7 +971,7 @@ _gpgme_io_pipe (int filedes[2], int inherit_idx)
CloseHandle (rh); CloseHandle (rh);
CloseHandle (wh); CloseHandle (wh);
/* FIXME: Should translate the error code. */ /* FIXME: Should translate the error code. */
errno = EIO; gpg_err_set_errno (EIO);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
} }
@ -992,7 +992,7 @@ _gpgme_io_close (int fd)
if (fd == -1) if (fd == -1)
{ {
errno = EBADF; gpg_err_set_errno (EBADF);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
@ -1019,7 +1019,7 @@ _gpgme_io_close (int fd)
{ {
TRACE_LOG1 ("CloseHandle failed: ec=%d", (int) GetLastError ()); TRACE_LOG1 ("CloseHandle failed: ec=%d", (int) GetLastError ());
/* FIXME: Should translate the error code. */ /* FIXME: Should translate the error code. */
errno = EIO; gpg_err_set_errno (EIO);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
@ -1048,7 +1048,7 @@ _gpgme_io_set_close_notify (int fd, _gpgme_close_notify_handler_t handler,
if (i == DIM (notify_table)) if (i == DIM (notify_table))
{ {
UNLOCK (notify_table_lock); UNLOCK (notify_table_lock);
errno = EINVAL; gpg_err_set_errno (EINVAL);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
notify_table[i].fd = fd; notify_table[i].fd = fd;
@ -1215,7 +1215,7 @@ _gpgme_io_spawn (const char *path, char *const argv[], unsigned int flags,
DeleteFile (tmp_name); DeleteFile (tmp_name);
/* FIXME: Should translate the error code. */ /* FIXME: Should translate the error code. */
errno = EIO; gpg_err_set_errno (EIO);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
@ -1245,7 +1245,7 @@ _gpgme_io_spawn (const char *path, char *const argv[], unsigned int flags,
DeleteFile (tmp_name); DeleteFile (tmp_name);
/* FIXME: Should translate the error code. */ /* FIXME: Should translate the error code. */
errno = EIO; gpg_err_set_errno (EIO);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
/* Return the child name of this handle. */ /* Return the child name of this handle. */
@ -1380,7 +1380,7 @@ _gpgme_io_select (struct io_select_fd_s *fds, size_t nfds, int nonblock)
TRACE_END (dbg_help, "oops ]"); TRACE_END (dbg_help, "oops ]");
TRACE_LOG ("Too many objects for WFMO!"); TRACE_LOG ("Too many objects for WFMO!");
/* FIXME: Should translate the error code. */ /* FIXME: Should translate the error code. */
errno = EIO; gpg_err_set_errno (EIO);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
waitidx[nwait] = i; waitidx[nwait] = i;
@ -1403,7 +1403,7 @@ _gpgme_io_select (struct io_select_fd_s *fds, size_t nfds, int nonblock)
TRACE_END (dbg_help, "oops ]"); TRACE_END (dbg_help, "oops ]");
TRACE_LOG ("Too many objects for WFMO!"); TRACE_LOG ("Too many objects for WFMO!");
/* FIXME: Should translate the error code. */ /* FIXME: Should translate the error code. */
errno = EIO; gpg_err_set_errno (EIO);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
waitidx[nwait] = i; waitidx[nwait] = i;
@ -1492,7 +1492,7 @@ _gpgme_io_select (struct io_select_fd_s *fds, size_t nfds, int nonblock)
if (count < 0) if (count < 0)
{ {
/* FIXME: Should determine a proper error code. */ /* FIXME: Should determine a proper error code. */
errno = EIO; gpg_err_set_errno (EIO);
} }
return TRACE_SYSRES (count); return TRACE_SYSRES (count);
@ -1533,7 +1533,7 @@ _gpgme_io_dup (int fd)
{ {
TRACE_LOG1 ("DuplicateHandle failed: ec=%d\n", (int) GetLastError ()); TRACE_LOG1 ("DuplicateHandle failed: ec=%d\n", (int) GetLastError ());
/* FIXME: Translate error code. */ /* FIXME: Translate error code. */
errno = EIO; gpg_err_set_errno (EIO);
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
@ -1627,7 +1627,7 @@ _gpgme_io_socket (int domain, int type, int proto)
res = socket (domain, type, proto); res = socket (domain, type, proto);
if (res == INVALID_SOCKET) if (res == INVALID_SOCKET)
{ {
errno = wsa2errno (WSAGetLastError ()); gpg_err_set_errno (wsa2errno (WSAGetLastError ()));
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }
@ -1648,7 +1648,7 @@ _gpgme_io_connect (int fd, struct sockaddr *addr, int addrlen)
res = connect (fd, addr, addrlen); res = connect (fd, addr, addrlen);
if (res) if (res)
{ {
errno = wsa2errno (WSAGetLastError ()); gpg_err_set_errno (wsa2errno (WSAGetLastError ()));
return TRACE_SYSRES (-1); return TRACE_SYSRES (-1);
} }

View File

@ -524,7 +524,7 @@ mkstemp (char *tmpl)
len = strlen (tmpl); len = strlen (tmpl);
if (len < 6 || strcmp (&tmpl[len - 6], "XXXXXX")) if (len < 6 || strcmp (&tmpl[len - 6], "XXXXXX"))
{ {
errno = EINVAL; gpg_err_set_errno (EINVAL);
return -1; return -1;
} }
@ -561,7 +561,7 @@ mkstemp (char *tmpl)
fd = open (tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); fd = open (tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
if (fd >= 0) if (fd >= 0)
{ {
errno = save_errno; gpg_err_set_errno (save_errno);
return fd; return fd;
} }
else if (errno != EEXIST) else if (errno != EEXIST)
@ -569,7 +569,7 @@ mkstemp (char *tmpl)
} }
/* We got out of the loop because we ran out of combinations to try. */ /* We got out of the loop because we ran out of combinations to try. */
errno = EEXIST; gpg_err_set_errno (EEXIST);
return -1; return -1;
} }