diff options
-rw-r--r-- | configure.ac | 29 | ||||
-rw-r--r-- | src/Makefile.am | 12 | ||||
-rw-r--r-- | src/gpgrt-int.h | 118 | ||||
-rw-r--r-- | src/sysutils.c | 39 |
4 files changed, 187 insertions, 11 deletions
diff --git a/configure.ac b/configure.ac index 84418af..53472b3 100644 --- a/configure.ac +++ b/configure.ac @@ -15,6 +15,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, see <https://www.gnu.org/licenses/>. +# SPDX-License-Identifier: LGPL-2.1+ # (Process this file with autoconf to produce a configure script.) # The following lines are used by ./autogen.sh. @@ -516,6 +517,34 @@ AC_DEFINE_UNQUOTED(HOST_TRIPLET_STRING, "$host", [The host triplet]) # +# gpgrt_log_clock may require linking with extra libaries. As long as +# we don't have a good test for this we require the use of this +# configure option to enabling printing of a timestamp. +# +AC_MSG_CHECKING([whether to enable log_clock]) +AC_ARG_ENABLE(log_clock, + AC_HELP_STRING([--enable-log-clock], + [enable log_clock timestamps]), + enable_log_clock=$enableval, enable_log_clock=no) +AC_MSG_RESULT($enable_log_clock) +if test "$enable_log_clock" = yes ; then + AC_DEFINE(ENABLE_LOG_CLOCK,1,[Defined to use log_clock timestamps]) +fi + + +# +# Add -Werror to CFLAGS. This hack can be used to avoid problems with +# misbehaving autoconf tests in case the user supplied -Werror. +# +AC_ARG_ENABLE(werror, + AC_HELP_STRING([--enable-werror], + [append -Werror to CFLAGS]), + [if test $enableval = yes ; then + CFLAGS="$CFLAGS -Werror" + fi]) + + +# # Provide information about the build. # BUILD_REVISION="mym4_revision" diff --git a/src/Makefile.am b/src/Makefile.am index e4ebb6a..3210a65 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -15,11 +15,14 @@ # # You should have received a copy of the GNU Lesser General Public # License along with this program; if not, see <https://www.gnu.org/licenses/>. +# SPDX-License-Identifier: LGPL-2.1+ + +# # We distribute the generated sources err-sources.h and err-codes.h, # because they are needed to build the po directory, and they don't # depend on the configuration anyway. - +# if HAVE_W32CE_SYSTEM gpg_extra_headers = gpg-extra/errno.h @@ -179,7 +182,12 @@ libgpg_error_la_SOURCES = gettext.h $(arch_sources) \ gpgrt-int.h init.c init.h version.c lock.h thread.h \ estream.c estream-printf.c estream-printf.h \ strsource.c strerror.c code-to-errno.c code-from-errno.c \ - visibility.c visibility.h b64dec.c + visibility.c visibility.h \ + sysutils.c \ + logging.c \ + b64dec.c + + nodist_libgpg_error_la_SOURCES = gpg-error.h # libgpg_error_la_DEPENDENCIES = \ diff --git a/src/gpgrt-int.h b/src/gpgrt-int.h index 701e1d4..02d54c9 100644 --- a/src/gpgrt-int.h +++ b/src/gpgrt-int.h @@ -1,5 +1,5 @@ /* gpgrt-int.h - Internal definitions - * Copyright (C) 2014 g10 Code GmbH + * Copyright (C) 2014, 2017 g10 Code GmbH * * This file is part of libgpg-error. * @@ -15,6 +15,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, see <https://www.gnu.org/licenses/>. + * SPDX-License-Identifier: LGPL-2.1+ */ #ifndef _GPGRT_GPGRT_INT_H @@ -23,7 +24,71 @@ #include "gpg-error.h" #include "visibility.h" -/* Local error function prototypes. */ +/* + * Internal i18n macros. + */ +#ifdef ENABLE_NLS +# ifdef HAVE_W32_SYSTEM +# include "gettext.h" +# else +# include <libintl.h> +# endif +# define _(a) gettext (a) +# ifdef gettext_noop +# define N_(a) gettext_noop (a) +# else +# define N_(a) (a) +# endif +#else /*!ENABLE_NLS*/ +# define _(a) (a) +# define N_(a) (a) +#endif /*!ENABLE_NLS */ + + +/* + * Hacks mainly required for Slowaris. + */ +#ifdef _GPGRT_NEED_AFLOCAL +# ifndef HAVE_W32_SYSTEM +# include <sys/socket.h> +# include <sys/un.h> +# else +# ifdef HAVE_WINSOCK2_H +# include <winsock2.h> +# endif +# include <windows.h> +# endif + +# ifndef PF_LOCAL +# ifdef PF_UNIX +# define PF_LOCAL PF_UNIX +# else +# define PF_LOCAL AF_UNIX +# endif +# endif /*PF_LOCAL*/ +# ifndef AF_LOCAL +# define AF_LOCAL AF_UNIX +# endif /*AF_UNIX*/ + +/* We used to avoid this macro in GnuPG and inlined the AF_LOCAL name + * length computation directly with the little twist of adding 1 extra + * byte. It seems that this was needed once on an old HP/UX box and + * there are also rumours that 4.3 Reno and DEC systems need it. This + * one-off buglet did not harm any current system until it came to Mac + * OS X where the kernel (as of May 2009) exhibited a strange bug: The + * systems basically froze in the connect call if the passed name + * contained an invalid directory part. Ignore the old Unices. */ +# ifndef SUN_LEN +# define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) \ + + strlen ((ptr)->sun_path)) +# endif /*SUN_LEN*/ +#endif /*_GPGRT_NEED_AFLOCAL*/ + + + +/* + * Local error function prototypes. + */ const char *_gpg_strerror (gpg_error_t err); int _gpg_strerror_r (gpg_error_t err, char *buf, size_t buflen); const char *_gpg_strsource (gpg_error_t err); @@ -49,7 +114,11 @@ gpg_err_code_t _gpgrt_lock_unlock (gpgrt_lock_t *lockhd); gpg_err_code_t _gpgrt_lock_destroy (gpgrt_lock_t *lockhd); gpg_err_code_t _gpgrt_yield (void); -/* Trace support. */ + + +/* + * Tracing + */ /* The trace macro is used this way: * trace (("enter - foo=%d bar=%s", foo, bar)); @@ -104,8 +173,10 @@ void _gpgrt_internal_trace_printf (const char *format, void _gpgrt_internal_trace_end (void); - -/* Local definitions for estream. */ + +/* + * Local definitions for estream. + */ #if HAVE_W32_SYSTEM # ifndef O_NONBLOCK @@ -123,7 +194,7 @@ typedef int (*cookie_ioctl_function_t) (void *cookie, int cmd, #define COOKIE_IOCTL_NONBLOCK 2 /* An internal variant of gpgrt_cookie_close_function_t with a slot - for the ioctl function. */ + * for the ioctl function. */ struct cookie_io_functions_s { struct _gpgrt_cookie_io_functions public; @@ -201,7 +272,9 @@ struct _gpgrt_stream_internal typedef struct _gpgrt_stream_internal *estream_internal_t; -/* Local prototypes for estream. */ +/* + * Local prototypes for estream. + */ int _gpgrt_estream_init (void); void _gpgrt_set_syscall_clamp (void (*pre)(void), void (*post)(void)); void _gpgrt_get_syscall_clamp (void (**r_pre)(void), void (**r_post)(void)); @@ -243,6 +316,14 @@ int _gpgrt_syshd_unlocked (gpgrt_stream_t stream, gpgrt_syshd_t *syshd); void _gpgrt__set_std_fd (int no, int fd); gpgrt_stream_t _gpgrt__get_std_stream (int fd); +/* The es_stderr et al macros are pretty common so that we want to use + * them too. This requires that we redefine them. */ +#undef es_stdin +#define es_stdin _gpgrt__get_std_stream (0) +#undef es_stdout +#define es_stdout _gpgrt__get_std_stream (1) +#undef es_stderr +#define es_stderr _gpgrt__get_std_stream (2) void _gpgrt_flockfile (gpgrt_stream_t stream); int _gpgrt_ftrylockfile (gpgrt_stream_t stream); @@ -357,7 +438,11 @@ const char *_gpgrt_fname_get (gpgrt_stream_t stream); #include "estream-printf.h" -#if _WIN32 +/* Make sure we always use our snprintf */ +#define snprintf _gpgrt_estream_snprintf + + +#if HAVE_W32_SYSTEM /* Prototypes for w32-estream.c. */ struct cookie_io_functions_s _gpgrt_functions_w32_pollable; int _gpgrt_w32_pollable_create (void *_GPGRT__RESTRICT *_GPGRT__RESTRICT cookie, @@ -365,7 +450,13 @@ int _gpgrt_w32_pollable_create (void *_GPGRT__RESTRICT *_GPGRT__RESTRICT cookie, struct cookie_io_functions_s next_functions, void *next_cookie); int _gpgrt_w32_poll (gpgrt_poll_t *fds, size_t nfds, int timeout); -#endif +#endif /*HAVE_W32_SYSTEM*/ + + + +/* + * Local prototypes for the encoders. + */ gpgrt_b64state_t _gpgrt_b64dec_start (const char *title); gpg_error_t _gpgrt_b64dec_proc (gpgrt_b64state_t state, void *buffer, @@ -373,4 +464,13 @@ gpg_error_t _gpgrt_b64dec_proc (gpgrt_b64state_t state, void *buffer, gpg_error_t _gpgrt_b64dec_finish (gpgrt_b64state_t state); + +/* + * Internal platform abstraction functions (sysutils.c) + */ + +/* Return true if FD is valid. */ +int _gpgrt_fd_valid_p (int fd); + + #endif /*_GPGRT_GPGRT_INT_H*/ diff --git a/src/sysutils.c b/src/sysutils.c new file mode 100644 index 0000000..1933506 --- /dev/null +++ b/src/sysutils.c @@ -0,0 +1,39 @@ +/* sysutils.c - Platform specific helper functions + * Copyright (C) 2017 g10 Code GmbH + * + * This file is part of libgpg-error. + * + * libgpg-error 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. + * + * libgpg-error 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://www.gnu.org/licenses/>. + * SPDX-License-Identifier: LGPL-2.1+ + */ + +#include <config.h> +#include <stdlib.h> +#include <stdint.h> +#include <unistd.h> + +#include "gpgrt-int.h" + + + +/* Return true if FD is valid. */ +int +_gpgrt_fd_valid_p (int fd) +{ + int d = dup (fd); + if (d < 0) + return 0; + close (d); + return 1; +} |