summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ChangeLog10
-rw-r--r--src/Makefile.am94
-rw-r--r--src/ath-compat.c184
-rw-r--r--src/ath-pth-compat.c124
-rw-r--r--src/ath-pth.c165
-rw-r--r--src/ath-pthread-compat.c105
-rw-r--r--src/ath-pthread.c180
-rw-r--r--src/ath.c182
-rw-r--r--src/ath.h100
-rw-r--r--src/gcrypt.h2
-rw-r--r--src/libgcrypt-config.in197
-rw-r--r--src/secmem.c2
12 files changed, 983 insertions, 362 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index df375166..52ea8ee9 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,13 @@
+2003-08-27 Moritz Schulte <mo@g10code.com>
+
+ * libgcrypt-config.in: Adjusted script for new thread handling.
+
+ * Makefile.am: New version, based on GPGMEs Makefile.am.
+
+ * ath.c, ath-compat.c, ath.h, ath-pth.c, ath-pth-compat.c,
+ ath-pthread.c, ath-pthread-compat.c: New files, merged from GPGME.
+ * ath.c, ath.h, ath-pthread.c, ath-pth.c: Removed files.
+
2003-08-08 Moritz Schulte <moritz@g10code.com>
* global.c (gcry_realloc): Remove FIXME about `clearing out
diff --git a/src/Makefile.am b/src/Makefile.am
index bd97d5c2..fd5cb34b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,5 +1,4 @@
-## Process this file with automake to produce Makefile.in
-# Copyright (C) 1998,1999,2000,2001,2002 Free Software Foundation, Inc.
+# Copyright (C) 1998,1999,2000,2001,2002,2003 Free Software Foundation, Inc.
#
# This file is part of Libgcrypt.
#
@@ -17,63 +16,88 @@
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+## Process this file with automake to produce Makefile.in
-# It seems that we need gcrypt.m4 here too
-EXTRA_DIST = libgcrypt-config.in libgcrypt.m4 libgcrypt.vers
-
-#INCLUDES = -I$(top_srcdir)/intl
-
-#OMIT_DEPENDENCIES = types.h
-
-
-lib_LTLIBRARIES = libgcrypt.la
-
+EXTRA_DIST = libgcrypt-config.in libgcrypt.m4 libgcrypt.vers
bin_SCRIPTS = libgcrypt-config
-
m4datadir = $(datadir)/aclocal
m4data_DATA = libgcrypt.m4
-
include_HEADERS = gcrypt.h gcrypt-module.h
+# Enable thread-library-specific versions of the library.
if HAVE_PTHREAD
-ath_components_pthread = ath-pthread.c
+ ltlib_libgcrypt_pthread = libgcrypt-pthread.la
else
-ath_components_pthread =
+ ltlib_libgcrypt_pthread =
endif
if HAVE_PTH
-ath_components_pth = ath-pth.c
+ ltlib_libgcrypt_pth = libgcrypt-pth.la
else
-ath_components_pth =
+ ltlib_libgcrypt_pth =
endif
-ath_components = ath.h ath.c ${ath_components_pthread} ${ath_components_pth}
+
+noinst_LTLIBRARIES = libgcrypt-real.la
+lib_LTLIBRARIES = libgcrypt.la $(ltlib_libgcrypt_pthread) $(ltlib_libgcrypt_pth)
if HAVE_LD_VERSION_SCRIPT
-libgcrypt_version_script_cmd = -Wl,--version-script=$(srcdir)/libgcrypt.vers
+ libgcrypt_version_script_cmd = -Wl,--version-script=$(srcdir)/libgcrypt.vers
else
-libgcrypt_version_script_cmd =
+ libgcrypt_version_script_cmd =
endif
-libgcrypt_la_LDFLAGS = $(libgcrypt_version_script_cmd) -version-info \
- @LIBGCRYPT_LT_CURRENT@:@LIBGCRYPT_LT_REVISION@:@LIBGCRYPT_LT_AGE@
-
-libgcrypt_la_SOURCES = \
-g10lib.h \
-types.h \
-cipher.h \
+libgcrypt_real_la_SOURCES = \
+g10lib.h types.h cipher.h \
misc.c \
global.c \
sexp.c \
-stdmem.c \
-stdmem.h \
-secmem.c \
-secmem.h \
+stdmem.c stdmem.h \
+secmem.c secmem.h \
mpi.h \
missing-string.c \
module.c \
${ath_components}
+# Include backwards-compatible ath-approaches in the main library.
+if HAVE_PTH
+ ath_pth_src = ath-pth-compat.c
+else
+ ath_pth_src =
+endif
+if HAVE_PTHREAD
+ ath_pthread_src = ath-pthread-compat.c
+else
+ ath_pthread_src =
+endif
+libgcrypt_la_SOURCES = ath.h ath-compat.c $(ath_pth_src) $(ath_pthread_src)
+
+# These are the new ath-approaches.
+libgcrypt_pthread_la_SOURCES = ath.h ath-pthread.c
+libgcrypt_pth_la_SOURCES = ath.h ath-pth.c
+
AM_CFLAGS = @GPG_ERROR_CFLAGS@
-libgcrypt_la_DEPENDENCIES = ../cipher/libcipher.la ../mpi/libmpi.la \
- $(srcdir)/libgcrypt.vers
-libgcrypt_la_LIBADD = ../cipher/libcipher.la ../mpi/libmpi.la @GPG_ERROR_LIBS@
+# The standard version.
+libgcrypt_la_LDFLAGS = $(libgcrypt_version_script_cmd) -version-info \
+ @LIBGCRYPT_LT_CURRENT@:@LIBGCRYPT_LT_REVISION@:@LIBGCRYPT_LT_AGE@
+libgcrypt_la_DEPENDENCIES = libgcrypt-real.la $(assuan_libobjs) \
+ @LTLIBOBJS@ $(srcdir)/libgcrypt.vers
+libgcrypt_la_LIBADD = libgcrypt-real.la $(assuan_libobjs) @LTLIBOBJS@ \
+ @GPG_ERROR_LIBS@
+
+# The pthread version.
+libgcrypt_pthread_la_LDFLAGS = $(libgcrypt_version_script_cmd) -version-info \
+ @LIBGCRYPT_LT_CURRENT@:@LIBGCRYPT_LT_REVISION@:@LIBGCRYPT_LT_AGE@
+libgcrypt_pthread_la_DEPENDENCIES = libgcrypt-real.la $(assuan_libobjs) \
+ @LTLIBOBJS@ $(srcdir)/libgcrypt.vers
+libgcrypt_pthread_la_LIBADD = libgcrypt-real.la $(assuan_libobjs) @LTLIBOBJS@ \
+ -lpthread @GPG_ERROR_LIBS@
+
+# The pth version.
+libgcrypt_pth_la_CPPFLAGS = $(AM_CPPFLAGS) @PTH_CPPFLAGS@
+libgcrypt_pth_la_LDFLAGS = @PTH_LDFLAGS@ \
+ $(libgcrypt_version_script_cmd) -version-info \
+ @LIBGCRYPT_LT_CURRENT@:@LIBGCRYPT_LT_REVISION@:@LIBGCRYPT_LT_AGE@
+libgcrypt_pth_la_DEPENDENCIES = libgcrypt-real.la $(assuan_libobjs) \
+ @LTLIBOBJS@ $(srcdir)/libgcrypt.vers
+libgcrypt_pth_la_LIBADD = libgcrypt-real.la $(assuan_libobjs) @LTLIBOBJS@ \
+ @PTH_LIBS@ @GPG_ERROR_LIBS@
diff --git a/src/ath-compat.c b/src/ath-compat.c
new file mode 100644
index 00000000..94ba2da2
--- /dev/null
+++ b/src/ath-compat.c
@@ -0,0 +1,184 @@
+/* ath.c - self-adapting thread-safeness library
+ * Copyright (C) 2002 g10 Code GmbH
+ *
+ * This file is part of Libgcrypt.
+ *
+ * Libgcrypt 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.
+ *
+ * Libgcrypt 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+ #endif
+
+#include <unistd.h>
+#ifdef HAVE_SYS_SELECT_H
+# include <sys/select.h>
+#else
+# include <sys/time.h>
+#endif
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include "ath.h"
+
+static struct ath_ops *ath_ops;
+
+void
+ath_init (void)
+{
+ if (0)
+ ;
+#ifdef HAVE_PTHREAD
+ else if (!ath_ops)
+ ath_ops = ath_pthread_available ();
+#endif
+#ifdef HAVE_PTH
+ else if (!ath_ops)
+ ath_ops = ath_pth_available ();
+#endif
+}
+
+
+int
+ath_mutex_init (ath_mutex_t *lock)
+{
+ if (!ath_ops)
+ return 0;
+
+ return ath_ops->mutex_init (lock, 0);
+}
+
+
+int
+ath_mutex_destroy (ath_mutex_t *lock)
+{
+ int err;
+ if (!ath_ops)
+ return 0;
+ err = ath_ops->mutex_init (lock, 1);
+ if (!err)
+ err = ath_ops->mutex_destroy (*lock);
+ return err;
+}
+
+
+int
+ath_mutex_lock (ath_mutex_t *lock)
+{
+ int err;
+
+ if (!ath_ops)
+ return 0;
+ err = ath_ops->mutex_init (lock, 1);
+ if (!err)
+ err = ath_ops->mutex_lock (*lock);
+ return err;
+}
+
+
+int
+ath_mutex_unlock (ath_mutex_t *lock)
+{
+ int err;
+
+ if (!ath_ops)
+ return 0;
+ err = ath_ops->mutex_init (lock, 1);
+ if (!err)
+ err = ath_ops->mutex_unlock (*lock);
+ return err;
+}
+
+
+ssize_t
+ath_read (int fd, void *buf, size_t nbytes)
+{
+ if (ath_ops && ath_ops->read)
+ return ath_ops->read (fd, buf, nbytes);
+ else
+ return read (fd, buf, nbytes);
+}
+
+
+ssize_t
+ath_write (int fd, const void *buf, size_t nbytes)
+{
+ if (ath_ops && ath_ops->write)
+ return ath_ops->write (fd, buf, nbytes);
+ else
+ return write (fd, buf, nbytes);
+}
+
+
+ssize_t
+ath_select (int nfd, fd_set *rset, fd_set *wset, fd_set *eset,
+ struct timeval *timeout)
+{
+ if (ath_ops && ath_ops->select)
+ return ath_ops->select (nfd, rset, wset, eset, timeout);
+ else
+ return select (nfd, rset, wset, eset, timeout);
+}
+
+
+ssize_t
+ath_waitpid (pid_t pid, int *status, int options)
+{
+ if (ath_ops && ath_ops->waitpid)
+ return ath_ops->waitpid (pid, status, options);
+ else
+ return waitpid (pid, status, options);
+}
+
+
+int
+ath_accept (int s, struct sockaddr *addr, socklen_t *length_ptr)
+{
+ if (ath_ops && ath_ops->accept)
+ return ath_ops->accept (s, addr, length_ptr);
+ else
+ return accept (s, addr, length_ptr);
+}
+
+
+int
+ath_connect (int s, struct sockaddr *addr, socklen_t length)
+{
+ if (ath_ops && ath_ops->connect)
+ return ath_ops->connect (s, addr, length);
+ else
+ return connect (s, addr, length);
+}
+
+
+int
+ath_sendmsg (int s, const struct msghdr *msg, int flags)
+{
+ if (ath_ops && ath_ops->sendmsg)
+ return ath_ops->sendmsg (s, msg, flags);
+ else
+ return sendmsg (s, msg, flags);
+}
+
+
+int
+ath_recvmsg (int s, struct msghdr *msg, int flags)
+{
+ if (ath_ops && ath_ops->recvmsg)
+ return ath_ops->recvmsg (s, msg, flags);
+ else
+ return recvmsg (s, msg, flags);
+}
diff --git a/src/ath-pth-compat.c b/src/ath-pth-compat.c
new file mode 100644
index 00000000..6506d91d
--- /dev/null
+++ b/src/ath-pth-compat.c
@@ -0,0 +1,124 @@
+/* ath-pth.c - Pth module for self-adapting thread-safeness library
+ * Copyright (C) 2002 g10 Code GmbH
+ *
+ * This file is part of Libgcrypt.
+ *
+ * Libgcrypt 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.
+ *
+ * Libgcrypt 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include <stdlib.h>
+#include <errno.h>
+#include <pth.h>
+
+#include "ath.h"
+
+#pragma weak pth_mutex_init
+#pragma weak pth_mutex_acquire
+#pragma weak pth_mutex_release
+#pragma weak pth_read
+#pragma weak pth_write
+#pragma weak pth_select
+#pragma weak pth_waitpid
+#pragma weak pth_accept
+#pragma weak pth_connect
+
+/* The lock we take while checking for lazy lock initialization. */
+static pth_mutex_t check_init_lock = PTH_MUTEX_INIT;
+
+/* Initialize the mutex *PRIV. If JUST_CHECK is true, only do this if
+ it is not already initialized. */
+static int
+mutex_pth_init (void **priv, int just_check)
+{
+ int err = 0;
+
+ if (just_check)
+ pth_mutex_acquire (&check_init_lock, 0, NULL);
+ if (!*priv || !just_check)
+ {
+ pth_mutex_t *lock = malloc (sizeof (pth_mutex_t));
+ if (!lock)
+ err = ENOMEM;
+ if (!err)
+ {
+ err = pth_mutex_init (lock);
+ if (err == FALSE)
+ err = errno;
+ else
+ err = 0;
+
+ if (err)
+ free (lock);
+ else
+ *priv = lock;
+ }
+ }
+ if (just_check)
+ pth_mutex_release (&check_init_lock);
+ return err;
+}
+
+
+static int
+mutex_pth_destroy (void *priv)
+{
+ free (priv);
+ return 0;
+}
+
+
+static int
+mutex_pth_lock (void *priv)
+{
+ int ret = pth_mutex_acquire ((pth_mutex_t *) priv, 0, NULL);
+ return ret == FALSE ? errno : 0;
+}
+
+
+static int
+mutex_pth_unlock (void *priv)
+{
+ int ret = pth_mutex_release ((pth_mutex_t *) priv);
+ return ret == FALSE ? errno : 0;
+}
+
+
+static struct ath_ops ath_pth_ops =
+ {
+ mutex_pth_init,
+ mutex_pth_destroy,
+ mutex_pth_lock,
+ mutex_pth_unlock,
+ pth_read,
+ pth_write,
+ pth_select,
+ pth_waitpid,
+ pth_accept,
+ pth_connect,
+ NULL, /* FIXME: When GNU PTh has sendmsg. */
+ NULL /* FIXME: When GNU PTh has recvmsg. */
+ };
+
+
+struct ath_ops *
+ath_pth_available (void)
+{
+ if (pth_mutex_init && pth_mutex_acquire && pth_mutex_release
+ && pth_read && pth_write && pth_select && pth_waitpid)
+ return &ath_pth_ops;
+ else
+ return 0;
+}
diff --git a/src/ath-pth.c b/src/ath-pth.c
index df403844..e58d5dec 100644
--- a/src/ath-pth.c
+++ b/src/ath-pth.c
@@ -1,37 +1,34 @@
/* ath-pth.c - Pth module for self-adapting thread-safeness library
- * Copyright (C) 2002 g10 Code GmbH
- * Copyright (C) 2002 Free Software Foundation, Inc.
- *
- * This file is part of Libgcrypt.
- *
- * Libgcrypt 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.
- *
- * Libgcrypt 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
+ Copyright (C) 2002, 2003 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. */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include <stdlib.h>
#include <errno.h>
+
#include <pth.h>
#include "ath.h"
-#pragma weak pth_mutex_init
-#pragma weak pth_mutex_acquire
-#pragma weak pth_mutex_release
-#pragma weak pth_read
-#pragma weak pth_write
-#pragma weak pth_select
-#pragma weak pth_waitpid
/* The lock we take while checking for lazy lock initialization. */
static pth_mutex_t check_init_lock = PTH_MUTEX_INIT;
@@ -39,7 +36,7 @@ static pth_mutex_t check_init_lock = PTH_MUTEX_INIT;
/* Initialize the mutex *PRIV. If JUST_CHECK is true, only do this if
it is not already initialized. */
static int
-mutex_pth_init (void **priv, int just_check)
+mutex_pth_init (ath_mutex_t *priv, int just_check)
{
int err = 0;
@@ -61,7 +58,7 @@ mutex_pth_init (void **priv, int just_check)
if (err)
free (lock);
else
- *priv = lock;
+ *priv = (ath_mutex_t) lock;
}
}
if (just_check)
@@ -70,55 +67,111 @@ mutex_pth_init (void **priv, int just_check)
}
-static int
-mutex_pth_destroy (void *priv)
+void
+ath_init (void)
{
- free (priv);
- return 0;
+ /* Nothing to do. */
}
-static int
-mutex_pth_lock (void *priv)
+int
+ath_mutex_init (ath_mutex_t *lock)
+{
+ return mutex_pth_init (lock, 0);
+}
+
+
+int
+ath_mutex_destroy (ath_mutex_t *lock)
+{
+ int err = mutex_pth_init (lock, 1);
+ if (!err)
+ {
+ /* GNU Pth has no destructor function. */
+ free (*lock);
+ }
+ return err;
+}
+
+
+int
+ath_mutex_lock (ath_mutex_t *lock)
{
- int ret = pth_mutex_acquire ((pth_mutex_t *) priv, 0, NULL);
+ int ret = mutex_pth_init (lock, 1);
+ if (ret)
+ return ret;
+
+ ret = pth_mutex_acquire ((pth_mutex_t *) *lock, 0, NULL);
return ret == FALSE ? errno : 0;
}
-static int
-mutex_pth_unlock (void *priv)
+int
+ath_mutex_unlock (ath_mutex_t *lock)
{
- int ret = pth_mutex_release ((pth_mutex_t *) priv);
+ int ret = mutex_pth_init (lock, 1);
+ if (ret)
+ return ret;
+
+ ret = pth_mutex_release ((pth_mutex_t *) *lock);
return ret == FALSE ? errno : 0;
}
-static struct ath_ops ath_pth_ops =
- {
- mutex_pth_init,
- mutex_pth_destroy,
- mutex_pth_lock,
- mutex_pth_unlock,
- pth_read,
- pth_write,
- pth_select,
- pth_waitpid
- };
+ssize_t
+ath_read (int fd, void *buf, size_t nbytes)
+{
+ return pth_read (fd, buf, nbytes);
+}
+
+
+ssize_t
+ath_write (int fd, const void *buf, size_t nbytes)
+{
+ return pth_write (fd, buf, nbytes);
+}
+
+
+ssize_t
+ath_select (int nfd, fd_set *rset, fd_set *wset, fd_set *eset,
+ struct timeval *timeout)
+{
+ return pth_select (nfd, rset, wset, eset, timeout);
+}
+
+
+ssize_t
+ath_waitpid (pid_t pid, int *status, int options)
+{
+ return pth_waitpid (pid, status, options);
+}
-struct ath_ops *
-ath_pth_available (void)
+int
+ath_accept (int s, struct sockaddr *addr, socklen_t *length_ptr)
{
- if (pth_mutex_init && pth_mutex_acquire && pth_mutex_release
- && pth_read && pth_write && pth_select && pth_waitpid)
- return &ath_pth_ops;
- else
- return 0;
+ return pth_accept (s, addr, length_ptr);
}
+int
+ath_connect (int s, struct sockaddr *addr, socklen_t length)
+{
+ return pth_connect (s, addr, length);
+}
+int
+ath_sendmsg (int s, const struct msghdr *msg, int flags)
+{
+ /* FIXME: GNU Pth is missing pth_sendmsg. */
+ return sendmsg (s, msg, flags);
+}
+int
+ath_recvmsg (int s, struct msghdr *msg, int flags)
+{
+ /* FIXME: GNU Pth is missing pth_recvmsg. */
+ return recvmsg (s, msg, flags);
+}
diff --git a/src/ath-pthread-compat.c b/src/ath-pthread-compat.c
new file mode 100644
index 00000000..0a578658
--- /dev/null
+++ b/src/ath-pthread-compat.c
@@ -0,0 +1,105 @@
+/* ath-pthread.c - pthread module for self-adapting thread-safeness library
+ * Copyright (C) 2002 g10 Code GmbH
+ *
+ * This file is part of Libgcrypt.
+ *
+ * Libgcrypt 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.
+ *
+ * Libgcrypt 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include <stdlib.h>
+#include <errno.h>
+#include <pthread.h>
+
+#include "ath.h"
+
+/* Need to include pthread_create in our check, as the GNU C library
+ has the pthread_mutex_* functions in their public interface. */
+#pragma weak pthread_create
+#pragma weak pthread_mutex_init
+#pragma weak pthread_mutex_destroy
+#pragma weak pthread_mutex_lock
+#pragma weak pthread_mutex_unlock
+
+/* The lock we take while checking for lazy lock initialization. */
+static pthread_mutex_t check_init_lock = PTHREAD_MUTEX_INITIALIZER;
+
+/* Initialize the mutex *PRIV. If JUST_CHECK is true, only do this if
+ it is not already initialized. */
+static int
+mutex_pthread_init (void **priv, int just_check)
+{
+ int err = 0;
+
+ if (just_check)
+ pthread_mutex_lock (&check_init_lock);
+ if (!*priv || !just_check)
+ {
+ pthread_mutex_t *lock = malloc (sizeof (pthread_mutex_t));
+ if (!lock)
+ err = ENOMEM;
+ if (!err)
+ {
+ err = pthread_mutex_init (lock, NULL);
+ if (err)
+ free (lock);
+ else
+ *priv = lock;
+ }
+ }
+ if (just_check)
+ pthread_mutex_unlock (&check_init_lock);
+ return err;
+}
+
+
+static int
+mutex_pthread_destroy (void *priv)
+{
+ int err = pthread_mutex_destroy ((pthread_mutex_t *) priv);
+ free (priv);
+ return err;
+}
+
+
+static struct ath_ops ath_pthread_ops =
+ {
+ mutex_pthread_init,
+ mutex_pthread_destroy,
+ (int (*) (void *)) pthread_mutex_lock,
+ (int (*) (void *)) pthread_mutex_unlock,
+ NULL, /* read */
+ NULL, /* write */
+ NULL, /* select */
+ NULL, /* waitpid */
+ NULL, /* accept */
+ NULL, /* connect */
+ NULL, /* sendmsg */
+ NULL /* recvmsg */
+ };
+
+
+struct ath_ops *
+ath_pthread_available (void)
+{
+ /* Need to include pthread_create in our check, as the GNU C library
+ has the pthread_mutex_* functions in their public interface. */
+ if (pthread_create
+ && pthread_mutex_init && pthread_mutex_destroy
+ && pthread_mutex_lock && pthread_mutex_unlock)
+ return &ath_pthread_ops;
+ else
+ return 0;
+}
diff --git a/src/ath-pthread.c b/src/ath-pthread.c
index 6f62511b..32c1bf2c 100644
--- a/src/ath-pthread.c
+++ b/src/ath-pthread.c
@@ -1,37 +1,42 @@
/* ath-pthread.c - pthread module for self-adapting thread-safeness library
- * Copyright (C) 2002 g10 Code GmbH
- * Copyright (C) 2002 Free Software Foundation, Inc.
- *
- * This file is part of Libgcrypt.
- *
- * Libgcrypt 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.
- *
- * Libgcrypt 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
+ Copyright (C) 2002, 2003 g10 Code GmbH
+
+ This file is part of Libgcrypt.
+
+ Libgcrypt 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.
+
+ Libgcrypt 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 Libgcrypt; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA. */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include <stdlib.h>
#include <errno.h>
+#include <unistd.h>
+#ifdef HAVE_SYS_SELECT_H
+# include <sys/select.h>
+#else
+# include <sys/time.h>
+#endif
+#include <sys/types.h>
+#include <sys/wait.h>
+
#include <pthread.h>
#include "ath.h"
-/* Need to include pthread_create in our check, as the GNU C library
- has the pthread_mutex_* functions in their public interface. */
-#pragma weak pthread_create
-#pragma weak pthread_mutex_init
-#pragma weak pthread_mutex_destroy
-#pragma weak pthread_mutex_lock
-#pragma weak pthread_mutex_unlock
/* The lock we take while checking for lazy lock initialization. */
static pthread_mutex_t check_init_lock = PTHREAD_MUTEX_INITIALIZER;
@@ -39,7 +44,7 @@ static pthread_mutex_t check_init_lock = PTHREAD_MUTEX_INITIALIZER;
/* Initialize the mutex *PRIV. If JUST_CHECK is true, only do this if
it is not already initialized. */
static int
-mutex_pthread_init (void **priv, int just_check)
+mutex_pthread_init (ath_mutex_t *priv, int just_check)
{
int err = 0;
@@ -56,7 +61,7 @@ mutex_pthread_init (void **priv, int just_check)
if (err)
free (lock);
else
- *priv = lock;
+ *priv = (ath_mutex_t) lock;
}
}
if (just_check)
@@ -65,37 +70,106 @@ mutex_pthread_init (void **priv, int just_check)
}
-static int
-mutex_pthread_destroy (void *priv)
+void
+ath_init (void)
+{
+ /* Nothing to do. */
+}
+
+
+int
+ath_mutex_init (ath_mutex_t *lock)
+{
+ return mutex_pthread_init (lock, 0);
+}
+
+
+int
+ath_mutex_destroy (ath_mutex_t *lock)
{
- int err = pthread_mutex_destroy ((pthread_mutex_t *) priv);
- free (priv);
+ int err = mutex_pthread_init (lock, 1);
+ if (!err)
+ {
+ err = pthread_mutex_destroy ((pthread_mutex_t *) *lock);
+ free (*lock);
+ }
return err;
}
-static struct ath_ops ath_pthread_ops =
- {
- mutex_pthread_init,
- mutex_pthread_destroy,
- (int (*) (void *)) pthread_mutex_lock,
- (int (*) (void *)) pthread_mutex_unlock,
- NULL, /* read */
- NULL, /* write */
- NULL, /* select */
- NULL /* waitpid */
- };
+int
+ath_mutex_lock (ath_mutex_t *lock)
+{
+ int ret = mutex_pthread_init (lock, 1);
+ if (ret)
+ return ret;
+
+ return pthread_mutex_lock ((pthread_mutex_t *) *lock);
+}
+
+
+int
+ath_mutex_unlock (ath_mutex_t *lock)
+{
+ int ret = mutex_pthread_init (lock, 1);
+ if (ret)
+ return ret;
+
+ return pthread_mutex_unlock ((pthread_mutex_t *) *lock);
+}
+
+
+ssize_t
+ath_read (int fd, void *buf, size_t nbytes)
+{
+ return read (fd, buf, nbytes);
+}
+
+
+ssize_t
+ath_write (int fd, const void *buf, size_t nbytes)
+{
+ return write (fd, buf, nbytes);
+}
+
+
+ssize_t
+ath_select (int nfd, fd_set *rset, fd_set *wset, fd_set *eset,
+ struct timeval *timeout)
+{
+ return select (nfd, rset, wset, eset, timeout);
+}
+
+
+ssize_t
+ath_waitpid (pid_t pid, int *status, int options)
+{
+ return waitpid (pid, status, options);
+}
+
+
+int
+ath_accept (int s, struct sockaddr *addr, socklen_t *length_ptr)
+{
+ return accept (s, addr, length_ptr);
+}
+
+
+int
+ath_connect (int s, struct sockaddr *addr, socklen_t length)
+{
+ return connect (s, addr, length);
+}
+
+int
+ath_sendmsg (int s, const struct msghdr *msg, int flags)
+{
+ return sendmsg (s, msg, flags);
+}
-struct ath_ops *
-ath_pthread_available (void)
+int
+ath_recvmsg (int s, struct msghdr *msg, int flags)
{
- /* Need to include pthread_create in our check, as the GNU C library
- has the pthread_mutex_* functions in their public interface. */
- if (pthread_create
- && pthread_mutex_init && pthread_mutex_destroy
- && pthread_mutex_lock && pthread_mutex_unlock)
- return &ath_pthread_ops;
- else
- return 0;
+ return recvmsg (s, msg, flags);
}
diff --git a/src/ath.c b/src/ath.c
index 33f82d20..36d896ef 100644
--- a/src/ath.c
+++ b/src/ath.c
@@ -1,140 +1,102 @@
-/* ath.c - self-adapting thread-safeness library
- * Copyright (C) 2002 g10 Code GmbH
- * Copyright (C) 2002 Free Software Foundation, Inc.
- *
- * This file is part of Libgcrypt.
- *
- * Libgcrypt 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.
- *
- * Libgcrypt 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
+/* ath.c - Thread-safeness library.
+ Copyright (C) 2002, 2003 g10 Code GmbH
+
+ This file is part of Libgcrypt.
+
+ Libgcrypt 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.
+
+ Libgcrypt 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 Libgcrypt; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA. */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <assert.h>
#include <unistd.h>
-#ifndef HAVE_DOSISH_SYSTEM
#ifdef HAVE_SYS_SELECT_H
-#include <sys/select.h>
+# include <sys/select.h>
#else
-#include <sys/time.h>
+# include <sys/time.h>
#endif
#include <sys/types.h>
#include <sys/wait.h>
-#endif /*HAVE_DOSISH_SYSTEM*/
#include "ath.h"
-static struct ath_ops *ath_ops;
-void
-ath_init (void)
-{
-#ifdef HAVE_PTHREAD
- if (!ath_ops)
- ath_ops = ath_pthread_available ();
-#endif
-#ifdef HAVE_PTH
- if (!ath_ops)
- ath_ops = ath_pth_available ();
-#endif
-#ifdef HAVE_ATH_DUMMY
- if (!ath_ops)
- ath_ops = ath_dummy_available ();
-#endif
-}
-
-
-/* This function is in general not very useful but due to some
- backward compatibiltiy we need ot for gcry_control
- (GCRYCTL_DISABLE_INTERNAL_LOCKING). */
-void
-ath_deinit (void)
-{
- /* fixme: We should deallocate the resource. */
- ath_ops = NULL;
-}
+#define MUTEX_UNLOCKED ((ath_mutex_t) 0)
+#define MUTEX_LOCKED ((ath_mutex_t) 1)
+#define MUTEX_DESTROYED ((ath_mutex_t) 2)
int
ath_mutex_init (ath_mutex_t *lock)
{
- if (!ath_ops)
- return 0;
-
- return ath_ops->mutex_init (lock, 0);
+#ifndef NDEBUG
+ *lock = MUTEX_UNLOCKED;
+#endif
+ return 0;
}
int
ath_mutex_destroy (ath_mutex_t *lock)
{
- int err;
- if (!ath_ops)
- return 0;
- err = ath_ops->mutex_init (lock, 1);
- if (!err)
- err = ath_ops->mutex_destroy (*lock);
- return err;
+#ifndef NDEBUG
+ assert (*lock == MUTEX_UNLOCKED);
+
+ *lock = MUTEX_DESTROYED;
+#endif
+ return 0;
}
int
ath_mutex_lock (ath_mutex_t *lock)
{
- int err;
-
- if (!ath_ops)
- return 0;
- err = ath_ops->mutex_init (lock, 1);
- if (!err)
- err = ath_ops->mutex_lock (*lock);
- return err;
+#ifndef NDEBUG
+ assert (*lock == MUTEX_UNLOCKED);
+
+ *lock = MUTEX_LOCKED;
+#endif
+ return 0;
}
int
ath_mutex_unlock (ath_mutex_t *lock)
{
- int err;
-
- if (!ath_ops)
- return 0;
- err = ath_ops->mutex_init (lock, 1);
- if (!err)
- err = ath_ops->mutex_unlock (*lock);
- return err;
+#ifndef NDEBUG
+ assert (*lock == MUTEX_LOCKED);
+
+ *lock = MUTEX_UNLOCKED;
+#endif
+ return 0;
}
ssize_t
ath_read (int fd, void *buf, size_t nbytes)
{
- if (ath_ops && ath_ops->read)
- return ath_ops->read (fd, buf, nbytes);
- else
- return read (fd, buf, nbytes);
+ return read (fd, buf, nbytes);
}
ssize_t
ath_write (int fd, const void *buf, size_t nbytes)
{
- if (ath_ops && ath_ops->write)
- return ath_ops->write (fd, buf, nbytes);
- else
- return write (fd, buf, nbytes);
+ return write (fd, buf, nbytes);
}
@@ -142,26 +104,40 @@ ssize_t
ath_select (int nfd, fd_set *rset, fd_set *wset, fd_set *eset,
struct timeval *timeout)
{
-#ifdef HAVE_DOSISH_SYSTEM
- return 0;
-#else
- if (ath_ops && ath_ops->select)
- return ath_ops->select (nfd, rset, wset, eset, timeout);
- else
- return select (nfd, rset, wset, eset, timeout);
-#endif
+ return select (nfd, rset, wset, eset, timeout);
}
ssize_t
ath_waitpid (pid_t pid, int *status, int options)
{
-#ifdef HAVE_DOSISH_SYSTEM
- return 0;
-#else
- if (ath_ops && ath_ops->waitpid)
- return ath_ops->waitpid (pid, status, options);
- else
- return waitpid (pid, status, options);
-#endif
+ return waitpid (pid, status, options);
+}
+
+
+int
+ath_accept (int s, struct sockaddr *addr, socklen_t *length_ptr)
+{
+ return accept (s, addr, length_ptr);
+}
+
+
+int
+ath_connect (int s, struct sockaddr *addr, socklen_t length)
+{
+ return connect (s, addr, length);
+}
+
+
+int
+ath_sendmsg (int s, const struct msghdr *msg, int flags)
+{
+ return sendmsg (s, msg, flags);
+}
+
+
+int
+ath_recvmsg (int s, struct msghdr *msg, int flags)
+{
+ return recvmsg (s, msg, flags);
}
diff --git a/src/ath.h b/src/ath.h
index 37d8c247..9514af86 100644
--- a/src/ath.h
+++ b/src/ath.h
@@ -1,55 +1,50 @@
-/* ath.h - interfaces for self-adapting thread-safeness library
- * Copyright (C) 2002 g10 Code GmbH
- * Copyright (C) 2002 Free Software Foundation, Inc.
- *
- * This file is part of Libgcrypt.
- *
- * Libgcrypt 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.
- *
- * Libgcrypt 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
+/* ath.h - Interfaces for thread-safeness library.
+ Copyright (C) 2002, 2003 g10 Code GmbH
+
+ This file is part of Libgcrypt.
+
+ Libgcrypt 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.
+
+ Libgcrypt 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 Libgcrypt; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA. */
#ifndef ATH_H
#define ATH_H
#include <sys/types.h>
+#include <sys/socket.h>
-#ifdef HAVE_DOSISH_SYSTEM
-#include <windows.h> /* for fd_set */
-#include <process.h> /* for pid_t */
- typedef unsigned int ssize_t;
-#endif
-
-/* Define ATH_EXT_SYM_PREFIX if you want to give all external symbols
+
+/* Define _ATH_EXT_SYM_PREFIX if you want to give all external symbols
a prefix. */
-#define ATH_EXT_SYM_PREFIX _gcry_
+#define _ATH_EXT_SYM_PREFIX _gcry_
-#ifdef ATH_EXT_SYM_PREFIX
-#define ATH_PREFIX1(x,y) x ## y
-#define ATH_PREFIX2(x,y) ATH_PREFIX1(x,y)
-#define ATH_PREFIX(x) ATH_PREFIX2(ATH_EXT_SYM_PREFIX,x)
-#define ath_init ATH_PREFIX(ath_init)
-#define ath_deinit ATH_PREFIX(ath_deinit)
-#define ath_mutex_init ATH_PREFIX(ath_mutex_init)
-#define ath_mutex_destroy ATH_PREFIX(ath_mutex_destroy)
-#define ath_mutex_lock ATH_PREFIX(ath_mutex_lock)
-#define ath_mutex_unlock ATH_PREFIX(ath_mutex_unlock)
-#define ath_read ATH_PREFIX(ath_read)
-#define ath_write ATH_PREFIX(ath_write)
-#define ath_select ATH_PREFIX(ath_select)
-#define ath_waitpid ATH_PREFIX(ath_waitpid)
-#define ath_pthread_available ATH_PREFIX(ath_pthread_available)
-#define ath_pth_available ATH_PREFIX(ath_pth_available)
+#ifdef _ATH_EXT_SYM_PREFIX
+#define _ATH_PREFIX1(x,y) x ## y
+#define _ATH_PREFIX2(x,y) _ATH_PREFIX1(x,y)
+#define _ATH_PREFIX(x) _ATH_PREFIX2(_ATH_EXT_SYM_PREFIX,x)
+#define ath_mutex_init _ATH_PREFIX(ath_mutex_init)
+#define ath_mutex_destroy _ATH_PREFIX(ath_mutex_destroy)
+#define ath_mutex_lock _ATH_PREFIX(ath_mutex_lock)
+#define ath_mutex_unlock _ATH_PREFIX(ath_mutex_unlock)
+#define ath_read _ATH_PREFIX(ath_read)
+#define ath_write _ATH_PREFIX(ath_write)
+#define ath_select _ATH_PREFIX(ath_select)
+#define ath_waitpid _ATH_PREFIX(ath_waitpid)
+#define ath_connect _ATH_PREFIX(ath_connect)
+#define ath_accept _ATH_PREFIX(ath_accept)
+#define ath_sendmsg _ATH_PREFIX(ath_sendmsg)
+#define ath_recvmsg _ATH_PREFIX(ath_recvmsg)
#endif
@@ -69,8 +64,13 @@ ssize_t ath_write (int fd, const void *buf, size_t nbytes);
ssize_t ath_select (int nfd, fd_set *rset, fd_set *wset, fd_set *eset,
struct timeval *timeout);
ssize_t ath_waitpid (pid_t pid, int *status, int options);
+int ath_accept (int s, struct sockaddr *addr, socklen_t *length_ptr);
+int ath_connect (int s, struct sockaddr *addr, socklen_t length);
+int ath_sendmsg (int s, const struct msghdr *msg, int flags);
+int ath_recvmsg (int s, struct msghdr *msg, int flags);
-
+#define _ATH_COMPAT
+#ifdef _ATH_COMPAT
struct ath_ops
{
int (*mutex_init) (void **priv, int just_check);
@@ -82,15 +82,21 @@ struct ath_ops
ssize_t (*select) (int nfd, fd_set *rset, fd_set *wset, fd_set *eset,
struct timeval *timeout);
ssize_t (*waitpid) (pid_t pid, int *status, int options);
+ int (*accept) (int s, struct sockaddr *addr, socklen_t *length_ptr);
+ int (*connect) (int s, struct sockaddr *addr, socklen_t length);
+ int (*sendmsg) (int s, const struct msghdr *msg, int flags);
+ int (*recvmsg) (int s, struct msghdr *msg, int flags);
};
/* Initialize the any-thread package. */
+#define ath_init _ATH_PREFIX(ath_init)
void ath_init (void);
-void ath_deinit (void);
/* Used by ath_pkg_init. */
+#define ath_pthread_available _ATH_PREFIX(ath_pthread_available)
struct ath_ops *ath_pthread_available (void);
+#define ath_pth_available _ATH_PREFIX(ath_pth_available)
struct ath_ops *ath_pth_available (void);
-struct ath_ops *ath_dummy_available (void);
+#endif
#endif /* ATH_H */
diff --git a/src/gcrypt.h b/src/gcrypt.h
index ec5f860d..b3f8d3ff 100644
--- a/src/gcrypt.h
+++ b/src/gcrypt.h
@@ -42,7 +42,7 @@ extern "C" {
autoconf (using the AM_PATH_GCRYPT macro) check that this header
matches the installed library. Note: Do not edit the next line as
configure may fix the string here. */
-#define GCRYPT_VERSION "1.1.42"
+#define GCRYPT_VERSION "1.1.43-cvs"
/* Internal: We can't use the convenience macros for the multi
precision integer functions when building this library. */
diff --git a/src/libgcrypt-config.in b/src/libgcrypt-config.in
index 5e1acbad..07713a6e 100644
--- a/src/libgcrypt-config.in
+++ b/src/libgcrypt-config.in
@@ -9,30 +9,46 @@
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-PGM=libgcrypt-config
+# General.
+prefix="@prefix@"
+exec_prefix="@exec_prefix@"
+thread_module=""
+version="@VERSION@"
+gpg_error_libs="@GPG_ERROR_LIBS@"
+gpg_error_cflags="@GPG_ERROR_CFLAGS@"
+
+# LIBS values.
libs="@LIBGCRYPT_CONFIG_LIBS@"
+libs_pthread="@LIBGCRYPT_CONFIG_LIBS_PTHREAD@"
+libs_pth="@LIBGCRYPT_CONFIG_LIBS_PTH@"
+
+# CFLAGS values.
cflags="@LIBGCRYPT_CONFIG_CFLAGS@"
-ciphers="@LIBGCRYPT_CIPHERS@"
-pubkey_ciphers="@LIBGCRYPT_PUBKEY_CIPHERS@"
+cflags_pthread="@LIBGCRYPT_CONFIG_CFLAGS_PTHREAD@"
+cflags_pth="@LIBGCRYPT_CONFIG_CFLAGS_PTH@"
+
+# Misc information.
+symmetric_ciphers="@LIBGCRYPT_CIPHERS@"
+asymmetric_ciphers="@LIBGCRYPT_PUBKEY_CIPHERS@"
digests="@LIBGCRYPT_DIGESTS@"
+thread_modules="@LIBGCRYPT_THREAD_MODULES@"
-prefix=@prefix@
-exec_prefix=@exec_prefix@
-includes=""
-libdirs=""
+# State variables.
exec_prefix_set=no
echo_libs=no
echo_cflags=no
echo_prefix=no
echo_algorithms=no
echo_exec_prefix=no
+echo_version=no
-
+# Prints usage information.
usage()
{
- cat <<EOF
-Usage: $PGM [OPTIONS]
+ cat <<EOF
+Usage: $0 [OPTIONS]
Options:
+ [--thread={${thread_modules}}]
[--prefix[=DIR]]
[--exec-prefix[=DIR]]
[--version]
@@ -40,54 +56,69 @@ Options:
[--cflags]
[--algorithms]
EOF
- exit $1
+ exit $1
}
if test $# -eq 0; then
- usage 1 1>&2
+ # Nothing to do.
+ usage 1 1>&2
fi
while test $# -gt 0; do
- case "$1" in
- -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
- *) optarg= ;;
- esac
-
- case $1 in
- --prefix=*)
- prefix=$optarg
- if test $exec_prefix_set = no ; then
- exec_prefix=$optarg
- fi
- ;;
- --prefix)
- echo_prefix=yes
- ;;
- --exec-prefix=*)
- exec_prefix=$optarg
- exec_prefix_set=yes
- ;;
- --exec-prefix)
- echo_exec_prefix=yes
- ;;
- --version)
- echo "@VERSION@"
- exit 0
- ;;
- --cflags)
- echo_cflags=yes
- ;;
- --libs)
- echo_libs=yes
- ;;
- --algorithms)
- echo_algorithms=yes
- ;;
- *)
- usage 1 1>&2
- ;;
- esac
- shift
+ case "$1" in
+ # Set up `optarg'.
+ --*=*)
+ optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'`
+ ;;
+ *)
+ optarg=""
+ ;;
+ esac
+
+ case $1 in
+ --thread=*)
+ for thread_mod in $thread_modules; do
+ if test "$thread_mod" = "$optarg"; then
+ thread_module="$optarg";
+ fi
+ done
+ if test "x$thread_module" = "x"; then
+ usage 1 1>&2
+ fi
+ ;;
+ --prefix=*)
+ prefix=$optarg
+ if test $exec_prefix_set = no ; then
+ exec_prefix=$optarg
+ fi
+ ;;
+ --prefix)
+ echo_prefix=yes
+ ;;
+ --exec-prefix=*)
+ exec_prefix=$optarg
+ exec_prefix_set=yes
+ ;;
+ --exec-prefix)
+ echo_exec_prefix=yes
+ ;;
+ --version)
+ echo_version=yes
+ ;;
+ --cflags)
+ echo_cflags=yes
+ ;;
+ --libs)
+ echo_libs=yes
+ ;;
+ --algorithms)
+ echo_algorithms=yes
+ ;;
+ *)
+ usage 1 1>&2
+ ;;
+ esac
+ shift
done
if test "$echo_prefix" = "yes"; then
@@ -99,27 +130,61 @@ if test "$echo_exec_prefix" = "yes"; then
fi
if test "$echo_cflags" = "yes"; then
+ includes=""
+ cflags_final="$cflags"
+
+ # Set up `includes'.
if test "@includedir@" != "/usr/include" ; then
- includes="-I@includedir@"
- for i in $cflags ; do
- if test "$i" = "-I@includedir@" ; then
- includes=""
- fi
- done
+ includes="-I@includedir@"
+ for i in $cflags ; do
+ if test "$i" = "-I@includedir@" ; then
+ includes=""
+ fi
+ done
fi
- echo $includes $cflags
+
+ # Set up `cflags_final'.
+ case "$thread_module" in
+ pthread)
+ cflags_final=$cflags_pthread
+ ;;
+ pth)
+ cflags_final=$cflags_pth
+ ;;
+ esac
+
+ echo "$includes" "$cflags_final"
fi
if test "$echo_libs" = "yes"; then
+ libdirs=""
+ libs_final="$libs"
+
+ # Set up `libdirs'.
if test "@libdir@" != "/usr/lib" ; then
- libdirs="-L@libdir@"
- for i in $libs ; do
- if test "$i" = "-L@libdir@" ; then
- libdirs=""
- fi
- done
+ libdirs="-L@libdir@"
+ for i in $libs ; do
+ if test "$i" = "-L@libdir@" ; then
+ libdirs=""
+ fi
+ done
fi
- echo $libdirs $libs
+
+ # Set up `libs_final'.
+ case "$thread_module" in
+ pthread)
+ libs_final=$libs_pthread
+ ;;
+ pth)
+ libs_final=$libs_pth
+ ;;
+ esac
+
+ echo $libdirs $libs_final
+fi
+
+if test "$echo_version" = "yes"; then
+ echo $version
fi
if test "$echo_algorithms" = "yes"; then
diff --git a/src/secmem.c b/src/secmem.c
index 00e1565c..0d038ae3 100644
--- a/src/secmem.c
+++ b/src/secmem.c
@@ -539,7 +539,7 @@ _gcry_secmem_realloc (void *p, size_t newsize)
SECMEM_LOCK;
- mb = (memblock_t *) ((char *) p - ((size_t) & ((memblock_t *) 0)->aligned.c));
+ mb = (memblock_t *) ((char *) p - ((size_t) &((memblock_t *) 0)->aligned.c));
size = mb->size;
if (newsize < size)
return p; /* it is easier not to shrink the memory */