diff options
author | Werner Koch <wk@gnupg.org> | 2007-06-06 20:12:30 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2007-06-06 20:12:30 +0200 |
commit | 2c9791db555cc571eaedfa71444da05454bd052a (patch) | |
tree | 9566d22f85e562e0c7b35dacc1697c9a58fcff1a | |
parent | Print passphrase encoding info only in PEM mode. (diff) | |
download | gnupg2-2c9791db555cc571eaedfa71444da05454bd052a.tar.xz gnupg2-2c9791db555cc571eaedfa71444da05454bd052a.zip |
First steps towards supporting W32.
This is mainly source code reorganization.
Update gnulib.
g10/ does currently not build.
116 files changed, 2720 insertions, 5563 deletions
@@ -1,3 +1,22 @@ +2007-06-06 Werner Koch <wk@g10code.com> + + * configure.ac: Add a few notices message so make browsing of the + log file easier. + (CC_FOR_BUILD): New. + +2007-05-30 Werner Koch <wk@g10code.com> + + * configure.ac [W32]: Do not create a symlink to w32-pth.h. + Require the installation of the w32pth package. + +2007-05-29 Werner Koch <wk@g10code.com> + + * gl/: Updated to a newer version. + +2007-05-24 Werner Koch <wk@g10code.com> + + * configure.ac: Use -Wpointer-arith is possible. + 2007-05-15 Werner Koch <wk@g10code.com> * configure.ac: Renamed the estream macros. Remove -Wformat-nonliteral. @@ -79,6 +79,8 @@ * sm/ ** check that we issue NO_SECKEY xxx if a -u key was not found We don't. The messages returned are also wrong (recipient vs. signer). +** gpgsm_format_name2 + Replace by an estream based implementation. * jnlib/ ** provide jnlib_malloc and try to remove all jnlib_xmalloc. diff --git a/agent/ChangeLog b/agent/ChangeLog index cab775385..94b7c5a3b 100644 --- a/agent/ChangeLog +++ b/agent/ChangeLog @@ -1,3 +1,15 @@ +2007-06-06 Werner Koch <wk@g10code.com> + + * minip12.c (enum): Rename CONTEXT to ASNCONTEXT as winnt.h + defines such a symbol to access the process context. + + * call-pinentry.c (dump_mutex_state) [W32]: Handle the W32Pth case. + * call-scd.c (dump_mutex_state): Ditto. + + * protect-tool.c (i18n_init): Remove. + * preset-passphrase.c (i18n_init): Remove. + * gpg-agent.c (i18n_init): Remove. + 2007-05-19 Marcus Brinkmann <marcus@g10code.de> * protect-tool.c (get_passphrase): Free ORIG_CODESET on error. diff --git a/agent/call-pinentry.c b/agent/call-pinentry.c index 14e6476d8..099171c5e 100644 --- a/agent/call-pinentry.c +++ b/agent/call-pinentry.c @@ -103,12 +103,16 @@ initialize_module_query (void) static void dump_mutex_state (pth_mutex_t *m) { +#ifdef _W32_PTH_H + log_printf ("unknown under W32"); +#else if (!(m->mx_state & PTH_MUTEX_INITIALIZED)) log_printf ("not_initialized"); else if (!(m->mx_state & PTH_MUTEX_LOCKED)) log_printf ("not_locked"); else log_printf ("locked tid=0x%lx count=%lu", (long)m->mx_owner, m->mx_count); +#endif } diff --git a/agent/call-scd.c b/agent/call-scd.c index 53e4ced4d..a2067a2cb 100644 --- a/agent/call-scd.c +++ b/agent/call-scd.c @@ -135,12 +135,16 @@ initialize_module_call_scd (void) static void dump_mutex_state (pth_mutex_t *m) { +#ifdef _W32_PTH_H + log_printf ("unknown under W32"); +#else if (!(m->mx_state & PTH_MUTEX_INITIALIZED)) log_printf ("not_initialized"); else if (!(m->mx_state & PTH_MUTEX_LOCKED)) log_printf ("not_locked"); else log_printf ("locked tid=0x%lx count=%lu", (long)m->mx_owner, m->mx_count); +#endif } diff --git a/agent/gpg-agent.c b/agent/gpg-agent.c index 1d73dfcd6..66b048815 100644 --- a/agent/gpg-agent.c +++ b/agent/gpg-agent.c @@ -260,22 +260,6 @@ my_strusage (int level) -static void -i18n_init (void) -{ -#ifdef USE_SIMPLE_GETTEXT - set_gettext_file( PACKAGE_GT ); -#else -#ifdef ENABLE_NLS - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE_GT, LOCALEDIR); - textdomain (PACKAGE_GT); -#endif -#endif -} - - - /* Setup the debugging. With the global variable DEBUG_LEVEL set to NULL only the active debug flags are propagated to the subsystems. With DEBUG_LEVEL set, a specific set of debug flags is set; thus overriding diff --git a/agent/minip12.c b/agent/minip12.c index 6958e5e1d..ec51aee85 100644 --- a/agent/minip12.c +++ b/agent/minip12.c @@ -52,7 +52,7 @@ enum { UNIVERSAL = 0, APPLICATION = 1, - CONTEXT = 2, + ASNCONTEXT = 2, PRIVATE = 3 }; @@ -638,7 +638,7 @@ parse_bag_encrypted_data (const unsigned char *buffer, size_t length, where = "start"; if (parse_tag (&p, &n, &ti)) goto bailout; - if (ti.class != CONTEXT || ti.tag) + if (ti.class != ASNCONTEXT || ti.tag) goto bailout; if (parse_tag (&p, &n, &ti)) goto bailout; @@ -722,7 +722,7 @@ parse_bag_encrypted_data (const unsigned char *buffer, size_t length, goto bailout; consumed = p - p_start; - if (ti.class == CONTEXT && ti.tag == 0 && ti.is_constructed && ti.ndef) + if (ti.class == ASNCONTEXT && ti.tag == 0 && ti.is_constructed && ti.ndef) { /* Mozilla exported certs now come with single byte chunks of octect strings. (Mozilla Firefox 1.0.4). Arghh. */ @@ -736,7 +736,7 @@ parse_bag_encrypted_data (const unsigned char *buffer, size_t length, r_consumed = NULL; /* Ugly hack to not update that value any further. */ ti.length = n; } - else if (ti.class == CONTEXT && ti.tag == 0 && ti.length ) + else if (ti.class == ASNCONTEXT && ti.tag == 0 && ti.length ) ; else goto bailout; @@ -818,7 +818,7 @@ parse_bag_encrypted_data (const unsigned char *buffer, size_t length, where = "certbag.before.certheader"; if (parse_tag (&p, &n, &ti)) goto bailout; - if (ti.class != CONTEXT || ti.tag) + if (ti.class != ASNCONTEXT || ti.tag) goto bailout; if (iscrlbag) { @@ -937,7 +937,7 @@ parse_bag_encrypted_data (const unsigned char *buffer, size_t length, where = "certbag.before.octetstring"; if (parse_tag (&p, &n, &ti)) goto bailout; - if (ti.class != CONTEXT || ti.tag) + if (ti.class != ASNCONTEXT || ti.tag) goto bailout; if (parse_tag (&p, &n, &ti)) goto bailout; @@ -1065,7 +1065,7 @@ parse_bag_data (const unsigned char *buffer, size_t length, int startoffset, where = "start"; if (parse_tag (&p, &n, &ti)) goto bailout; - if (ti.class != CONTEXT || ti.tag) + if (ti.class != ASNCONTEXT || ti.tag) goto bailout; if (parse_tag (&p, &n, &ti)) goto bailout; @@ -1112,7 +1112,7 @@ parse_bag_data (const unsigned char *buffer, size_t length, int startoffset, where = "shrouded,outerseqs"; if (parse_tag (&p, &n, &ti)) goto bailout; - if (ti.class != CONTEXT || ti.tag) + if (ti.class != ASNCONTEXT || ti.tag) goto bailout; if (parse_tag (&p, &n, &ti)) goto bailout; @@ -1324,7 +1324,7 @@ p12_parse (const unsigned char *buffer, size_t length, const char *pw, if (parse_tag (&p, &n, &ti)) goto bailout; - if (ti.class != CONTEXT || ti.tag) + if (ti.class != ASNCONTEXT || ti.tag) goto bailout; if (parse_tag (&p, &n, &ti)) goto bailout; diff --git a/agent/preset-passphrase.c b/agent/preset-passphrase.c index dc6a9057f..362591171 100644 --- a/agent/preset-passphrase.c +++ b/agent/preset-passphrase.c @@ -110,21 +110,6 @@ my_strusage (int level) } - -static void -i18n_init (void) -{ -#ifdef USE_SIMPLE_GETTEXT - set_gettext_file( PACKAGE_GT ); -#else -#ifdef ENABLE_NLS - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE_GT, LOCALEDIR); - textdomain (PACKAGE_GT); -#endif -#endif -} - static gpg_error_t map_spwq_error (int err) diff --git a/agent/protect-tool.c b/agent/protect-tool.c index f7e2d603b..d3bcc00b8 100644 --- a/agent/protect-tool.c +++ b/agent/protect-tool.c @@ -161,22 +161,6 @@ my_strusage (int level) -static void -i18n_init (void) -{ -#ifdef USE_SIMPLE_GETTEXT - set_gettext_file( PACKAGE_GT ); -#else -#ifdef ENABLE_NLS - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE_GT, LOCALEDIR); - textdomain (PACKAGE_GT); -#endif -#endif -} - - - /* static void */ /* print_mpi (const char *text, gcry_mpi_t a) */ /* { */ diff --git a/autogen.sh b/autogen.sh index 5cd909beb..0470ad0d2 100755 --- a/autogen.sh +++ b/autogen.sh @@ -92,7 +92,7 @@ if test "$1" = "--build-w32"; then --with-libassuan-prefix=${w32root} \ --with-zlib=${w32root} \ --with-pth-prefix=${w32root} \ - --disable-gpg + --without-included-gettext rc=$? exit $rc fi diff --git a/common/ChangeLog b/common/ChangeLog index 5c7697327..3f4675de1 100644 --- a/common/ChangeLog +++ b/common/ChangeLog @@ -1,3 +1,40 @@ +2007-06-06 Werner Koch <wk@g10code.com> + + * Makefile.am: Include am/cmacros.am. + + * sysutils.h [W32]: Remove prototypes for the registry access. + * w32reg.c: Move to ../jnlib/w32-reg.c. + + * i18n.c (i18n_init): New. + + * simple-gettext.c: Remove. + + * iobuf.c (iobuf_get_filelength): Rename SIZE to EXSIZE to silent + shadowing warning. + +2007-06-04 Werner Koch <wk@g10code.com> + + * http.c [W32]: Include unistd.h also in this case. + (write_server) [W32]: Fixed error code. + (init_sockets): Fixed syntax error. + (cookie_close): Replace close by sock_close macro. + + * estream.c [w32]: Do not init Mutex. + + * Makefile.am (common_sources) [USE_SNS_SRV]: Build srv.c only + when needed. + + * ttyio.c (init_ttyfp) [W32]: Do not use TTYFP. + + * util.h: Include ../jnlib/dynload.h. + + * dynload.h: Move to ../jnlib. + +2007-05-30 Werner Koch <wk@g10code.com> + + * estream.c (MEM_FREE, MEM_ALLOC, MEM_REALLOC): Prefix with ES_ as + windows.h also has such definitions, + 2007-05-15 Werner Koch <wk@g10code.com> * util.h: Do not include gnulib's vasprintf. Redefine asprintf diff --git a/common/Makefile.am b/common/Makefile.am index 237c8996e..8f70cdc28 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -28,9 +28,11 @@ AM_CPPFLAGS = -I$(top_srcdir)/gl -I$(top_srcdir)/intl AM_CFLAGS = $(LIBGCRYPT_CFLAGS) $(KSBA_CFLAGS) +include $(top_srcdir)/am/cmacros.am + common_sources = \ common-defs.h \ - util.h i18n.h \ + util.h i18n.c i18n.h \ errors.h \ openpgpdefs.h \ keyserver.h \ @@ -50,20 +52,23 @@ common_sources = \ ttyio.c ttyio.h \ asshelp.c asshelp.h \ exechelp.c exechelp.h \ - simple-gettext.c \ - w32reg.c \ signal.c \ - dynload.h \ estream.c estream.h estream-printf.c estream-printf.h \ - srv.c srv.h \ + srv.h \ dns-cert.c dns-cert.h \ pka.c pka.h \ http.c http.h libcommon_a_SOURCES = $(common_sources) +if USE_DNS_SRV +libcommon_a_SOURCES += srv.c +endif libcommon_a_CFLAGS = $(AM_CFLAGS) $(LIBASSUAN_CFLAGS) -DWITHOUT_GNU_PTH=1 libcommonpth_a_SOURCES = $(common_sources) +if USE_DNS_SRV +libcommonpth_a_SOURCES += srv.c +endif libcommonpth_a_CFLAGS = $(AM_CFLAGS) $(LIBASSUAN_PTH_CFLAGS) $(PTH_CFLAGS) libsimple_pwquery_a_SOURCES = \ diff --git a/common/dynload.h b/common/dynload.h deleted file mode 100644 index 9b67fa9ed..000000000 --- a/common/dynload.h +++ /dev/null @@ -1,72 +0,0 @@ -/* dlfcn.h - W32 functions for run-time dynamic loading - * Copyright (C) 2003 Free Software Foundation, Inc. - * - * This file is part of GnuPG. - * - * GnuPG 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. - * - * GnuPG 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - */ - -#ifndef GNUPG_DYNLOAD_H -#define GNUPG_DYNLOAD_H -#ifndef __MINGW32__ -#include <dlfcn.h> -#else -#include <windows.h> - -#define RTLD_LAZY 0 - -static inline void * -dlopen (const char * name, int flag) -{ - void * hd = LoadLibrary (name); - return hd; -} - -static inline void * -dlsym (void *hd, const char *sym) -{ - if (hd && sym) - { - void * fnc = GetProcAddress (hd, sym); - if (!fnc) - return NULL; - return fnc; - } - return NULL; -} - - -static inline const char * -dlerror (void) -{ - static char buf[32]; - sprintf (buf, "ec=%lu", GetLastError ()); - return buf; -} - - -static inline int -dlclose (void * hd) -{ - if (hd) - { - CloseHandle (hd); - return 0; - } - return -1; -} -#endif /*__MINGW32__*/ -#endif /*GNUPG_DYNLOAD_H*/ diff --git a/common/estream.c b/common/estream.c index 65c566489..05b1230ad 100644 --- a/common/estream.c +++ b/common/estream.c @@ -125,9 +125,9 @@ typedef void *estream_mutex_t; /* Memory allocator functions. */ -#define MEM_ALLOC malloc -#define MEM_REALLOC realloc -#define MEM_FREE free +#define ES_MEM_ALLOC malloc +#define ES_MEM_REALLOC realloc +#define ES_MEM_FREE free /* Primitive system I/O. */ @@ -194,7 +194,13 @@ struct estream_list static estream_list_t estream_list; #ifdef HAVE_PTH -static estream_mutex_t estream_list_lock = ESTREAM_MUTEX_INITIALIZER; +/* Note that we can't use a static initialization with W32Pth; however + W32Pth does an implicit initialization anyway. */ +static estream_mutex_t estream_list_lock +# ifndef _W32_PTH_H + = ESTREAM_MUTEX_INITIALIZER +# endif + ; #endif #define ESTREAM_LIST_LOCK ESTREAM_MUTEX_LOCK (estream_list_lock) @@ -236,7 +242,7 @@ es_list_add (estream_t stream) estream_list_t list_obj; int ret; - list_obj = MEM_ALLOC (sizeof (*list_obj)); + list_obj = ES_MEM_ALLOC (sizeof (*list_obj)); if (! list_obj) ret = -1; else @@ -268,7 +274,7 @@ es_list_remove (estream_t stream) *list_obj->prev_cdr = list_obj->cdr; if (list_obj->cdr) list_obj->cdr->prev_cdr = list_obj->prev_cdr; - MEM_FREE (list_obj); + ES_MEM_FREE (list_obj); break; } ESTREAM_LIST_UNLOCK; @@ -349,7 +355,7 @@ es_func_mem_create (void *ES__RESTRICT *ES__RESTRICT cookie, estream_cookie_mem_t mem_cookie; int err; - mem_cookie = MEM_ALLOC (sizeof (*mem_cookie)); + mem_cookie = ES_MEM_ALLOC (sizeof (*mem_cookie)); if (! mem_cookie) err = -1; else @@ -365,8 +371,8 @@ es_func_mem_create (void *ES__RESTRICT *ES__RESTRICT cookie, mem_cookie->dont_free = dont_free ? 1 : 0; mem_cookie->ptr = ptr; mem_cookie->size = size; - mem_cookie->func_realloc = func_realloc ? func_realloc : MEM_REALLOC; - mem_cookie->func_free = func_free ? func_free : MEM_FREE; + mem_cookie->func_realloc = func_realloc ? func_realloc : ES_MEM_REALLOC; + mem_cookie->func_free = func_free ? func_free : ES_MEM_FREE; mem_cookie->offset = 0; *cookie = mem_cookie; err = 0; @@ -575,7 +581,7 @@ es_func_mem_destroy (void *cookie) if (! mem_cookie->dont_free) (*func_free) (mem_cookie->memory); - MEM_FREE (mem_cookie); + ES_MEM_FREE (mem_cookie); return 0; } @@ -603,7 +609,7 @@ es_func_fd_create (void **cookie, int fd, unsigned int flags) estream_cookie_fd_t fd_cookie; int err; - fd_cookie = MEM_ALLOC (sizeof (*fd_cookie)); + fd_cookie = ES_MEM_ALLOC (sizeof (*fd_cookie)); if (! fd_cookie) err = -1; else @@ -676,7 +682,7 @@ es_func_fd_destroy (void *cookie) if (fd_cookie) { err = close (fd_cookie->fd); - MEM_FREE (fd_cookie); + ES_MEM_FREE (fd_cookie); } else err = 0; @@ -706,7 +712,7 @@ es_func_file_create (void **cookie, int *filedes, err = 0; fd = -1; - file_cookie = MEM_ALLOC (sizeof (*file_cookie)); + file_cookie = ES_MEM_ALLOC (sizeof (*file_cookie)); if (! file_cookie) { err = -1; @@ -727,7 +733,7 @@ es_func_file_create (void **cookie, int *filedes, out: if (err) - MEM_FREE (file_cookie); + ES_MEM_FREE (file_cookie); return err; } @@ -1004,14 +1010,14 @@ es_create (estream_t *stream, void *cookie, int fd, stream_new = NULL; stream_internal_new = NULL; - stream_new = MEM_ALLOC (sizeof (*stream_new)); + stream_new = ES_MEM_ALLOC (sizeof (*stream_new)); if (! stream_new) { err = -1; goto out; } - stream_internal_new = MEM_ALLOC (sizeof (*stream_internal_new)); + stream_internal_new = ES_MEM_ALLOC (sizeof (*stream_internal_new)); if (! stream_internal_new) { err = -1; @@ -1040,7 +1046,7 @@ es_create (estream_t *stream, void *cookie, int fd, if (stream_new) { es_deinitialize (stream_new); - MEM_FREE (stream_new); + ES_MEM_FREE (stream_new); } } @@ -1057,8 +1063,8 @@ es_destroy (estream_t stream) { es_list_remove (stream); err = es_deinitialize (stream); - MEM_FREE (stream->intern); - MEM_FREE (stream); + ES_MEM_FREE (stream->intern); + ES_MEM_FREE (stream); } return err; @@ -1567,7 +1573,7 @@ doreadline (estream_t ES__RESTRICT stream, size_t max_length, line_stream_cookie = NULL; err = es_func_mem_create (&line_stream_cookie, NULL, 0, 0, BUFFER_BLOCK_SIZE, - 1, 0, 0, NULL, 0, MEM_REALLOC, MEM_FREE, O_RDWR); + 1, 0, 0, NULL, 0, ES_MEM_REALLOC, ES_MEM_FREE, O_RDWR); if (err) goto out; @@ -1633,7 +1639,7 @@ doreadline (estream_t ES__RESTRICT stream, size_t max_length, if (! *line) { - line_new = MEM_ALLOC (line_size + 1); + line_new = ES_MEM_ALLOC (line_size + 1); if (! line_new) { err = -1; @@ -1664,7 +1670,7 @@ doreadline (estream_t ES__RESTRICT stream, size_t max_length, if (err) { if (! *line) - MEM_FREE (line_new); + ES_MEM_FREE (line_new); stream->intern->indicators.err = 1; } @@ -1748,7 +1754,7 @@ es_set_buffering (estream_t ES__RESTRICT stream, if (stream->intern->deallocate_buffer) { stream->intern->deallocate_buffer = 0; - MEM_FREE (stream->buffer); + ES_MEM_FREE (stream->buffer); stream->buffer = NULL; } @@ -1762,7 +1768,7 @@ es_set_buffering (estream_t ES__RESTRICT stream, buffer_new = buffer; else { - buffer_new = MEM_ALLOC (size); + buffer_new = ES_MEM_ALLOC (size); if (! buffer_new) { err = -1; @@ -1921,7 +1927,7 @@ es_open_memstream (char **ptr, size_t *size) err = es_func_mem_create (&cookie, NULL, 0, 0, BUFFER_BLOCK_SIZE, 1, 1, 1, - ptr, size, MEM_REALLOC, MEM_FREE, flags); + ptr, size, ES_MEM_REALLOC, ES_MEM_FREE, flags); if (err) goto out; @@ -2454,7 +2460,7 @@ es_getline (char *ES__RESTRICT *ES__RESTRICT lineptr, size_t *ES__RESTRICT n, void *p; - p = MEM_REALLOC (*lineptr, line_n + 1); + p = ES_MEM_REALLOC (*lineptr, line_n + 1); if (! p) err = -1; else @@ -2470,7 +2476,7 @@ es_getline (char *ES__RESTRICT *ES__RESTRICT lineptr, size_t *ES__RESTRICT n, if (*n != line_n) *n = line_n; } - MEM_FREE (line); + ES_MEM_FREE (line); } else { @@ -2530,7 +2536,7 @@ es_read_line (estream_t stream, { /* No buffer given - allocate a new one. */ length = 256; - buffer = MEM_ALLOC (length); + buffer = ES_MEM_ALLOC (length); *addr_of_buffer = buffer; if (!buffer) { @@ -2571,11 +2577,11 @@ es_read_line (estream_t stream, } length += 3; /* Adjust for the reserved bytes. */ length += length < 1024? 256 : 1024; - *addr_of_buffer = MEM_REALLOC (buffer, length); + *addr_of_buffer = ES_MEM_REALLOC (buffer, length); if (!*addr_of_buffer) { int save_errno = errno; - MEM_FREE (buffer); + ES_MEM_FREE (buffer); *length_of_buffer = *max_length = 0; ESTREAM_UNLOCK (stream); errno = save_errno; @@ -2604,7 +2610,7 @@ void es_free (void *a) { if (a) - MEM_FREE (a); + ES_MEM_FREE (a); } diff --git a/common/http.c b/common/http.c index 15f00b9ae..4693c33e2 100644 --- a/common/http.c +++ b/common/http.c @@ -41,11 +41,11 @@ #include <string.h> #include <ctype.h> #include <errno.h> +#include <unistd.h> #ifdef HAVE_W32_SYSTEM # include <windows.h> #else /*!HAVE_W32_SYSTEM*/ -# include <unistd.h> # include <sys/types.h> # include <sys/socket.h> # include <sys/time.h> @@ -236,7 +236,7 @@ init_sockets (void) || HIBYTE(wsdata.wVersion) != REQ_WINSOCK_MINOR ) { log_error ("socket library version is %x.%x - but %d.%d needed\n", - LOBYTE(wsdata.wVersion), HIBYTE(wsdata.wVersion) + LOBYTE(wsdata.wVersion), HIBYTE(wsdata.wVersion), REQ_WINSOCK_MAJOR, REQ_WINSOCK_MINOR); WSACleanup(); return; @@ -1693,7 +1693,7 @@ write_server (int sock, const char *data, size_t length) if ( nwritten == SOCKET_ERROR ) { log_info ("network write failed: ec=%d\n", (int)WSAGetLastError ()); - return G10ERR_NETWORK; + return gpg_error (GPG_ERR_NETWORK); } #else /*!HAVE_W32_SYSTEM*/ int nwritten = write (sock, data, nleft); @@ -1829,14 +1829,14 @@ cookie_close (void *cookie) if (!c) return 0; - #ifdef HTTP_USE_GNUTLS +#ifdef HTTP_USE_GNUTLS if (c->tls_session && !c->keep_socket) { gnutls_bye (c->tls_session, GNUTLS_SHUT_RDWR); } #endif /*HTTP_USE_GNUTLS*/ if (c->fd != -1 && !c->keep_socket) - close (c->fd); + sock_close (c->fd); xfree (c); return 0; diff --git a/common/i18n.c b/common/i18n.c new file mode 100644 index 000000000..d4a98d0e0 --- /dev/null +++ b/common/i18n.c @@ -0,0 +1,39 @@ +/* i18n.c - gettext initialization + * Copyright (C) 2007 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG 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. + * + * GnuPG 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + */ + +#include <config.h> + +#include "i18n.h" + +void +i18n_init (void) +{ +#ifdef USE_SIMPLE_GETTEXT + set_gettext_file (PACKAGE_GT, "Software\\GNU\\GnuPG"); +#else +# ifdef ENABLE_NLS + setlocale (LC_ALL, "" ); + bindtextdomain (PACKAGE_GT, LOCALEDIR); + textdomain (PACKAGE_GT); +# endif +#endif +} + diff --git a/common/i18n.h b/common/i18n.h index 56c00abf6..b692feaa7 100644 --- a/common/i18n.h +++ b/common/i18n.h @@ -14,11 +14,9 @@ #ifndef GNUPG_COMMON_I18N_H #define GNUPG_COMMON_I18N_H + #ifdef USE_SIMPLE_GETTEXT - int set_gettext_file( const char *filename ); - const char *gettext( const char *msgid ); - const char *ngettext(const char *msgid1, const char *msgid2, - unsigned long int n); +# include "../jnlib/w32help.h" # define _(a) gettext (a) # define N_(a) (a) #else @@ -40,4 +38,7 @@ # endif #endif /*!USE_SIMPLE_GETTEXT*/ +void i18n_init (void); + + #endif /*GNUPG_COMMON_I18N_H*/ diff --git a/common/iobuf.c b/common/iobuf.c index c01702696..40af196da 100644 --- a/common/iobuf.c +++ b/common/iobuf.c @@ -271,7 +271,7 @@ fd_cache_close (const char *fname, FILEP_OR_FD fp) close (fp); #endif if (DBG_IOBUF) - log_debug ("fd_cache_close (%d) real\n", fp); + log_debug ("fd_cache_close (%d) real\n", (int)fp); return; } /* try to reuse a slot */ @@ -2006,78 +2006,79 @@ iobuf_set_limit (iobuf_t a, off_t nlimit) off_t iobuf_get_filelength (iobuf_t a, int *overflow) { - struct stat st; + struct stat st; - if (overflow) - *overflow = 0; - - if( a->directfp ) { - FILE *fp = a->directfp; - - if( !fstat(fileno(fp), &st) ) - return st.st_size; - log_error("fstat() failed: %s\n", strerror(errno) ); - return 0; + if (overflow) + *overflow = 0; + + if ( a->directfp ) + { + FILE *fp = a->directfp; + + if ( !fstat(fileno(fp), &st) ) + return st.st_size; + log_error("fstat() failed: %s\n", strerror(errno) ); + return 0; } - - /* Hmmm: file_filter may have already been removed */ - for( ; a; a = a->chain ) - if( !a->chain && a->filter == file_filter ) { - file_filter_ctx_t *b = a->filter_ov; - FILEP_OR_FD fp = b->fp; - + + /* Hmmm: file_filter may have already been removed */ + for ( ; a; a = a->chain ) + if ( !a->chain && a->filter == file_filter ) + { + file_filter_ctx_t *b = a->filter_ov; + FILEP_OR_FD fp = b->fp; + #if defined(HAVE_DOSISH_SYSTEM) && !defined(FILE_FILTER_USES_STDIO) - ulong size; - static int (* __stdcall get_file_size_ex) - (void *handle, LARGE_INTEGER *size); - static int get_file_size_ex_initialized; - - if (!get_file_size_ex_initialized) + ulong size; + static int (* __stdcall get_file_size_ex) (void *handle, + LARGE_INTEGER *r_size); + static int get_file_size_ex_initialized; + + if (!get_file_size_ex_initialized) + { + void *handle; + + handle = dlopen ("kernel32.dll", RTLD_LAZY); + if (handle) { - void *handle; - - handle = dlopen ("kernel32.dll", RTLD_LAZY); - if (handle) - { - get_file_size_ex = dlsym (handle, "GetFileSizeEx"); - if (!get_file_size_ex) - dlclose (handle); - } - get_file_size_ex_initialized = 1; + get_file_size_ex = dlsym (handle, "GetFileSizeEx"); + if (!get_file_size_ex) + dlclose (handle); } - - if (get_file_size_ex) + get_file_size_ex_initialized = 1; + } + + if (get_file_size_ex) + { + /* This is a newer system with GetFileSizeEx; we use this + then because it seem that GetFileSize won't return a + proper error in case a file is larger than 4GB. */ + LARGE_INTEGER exsize; + + if (get_file_size_ex (fp, &exsize)) { - /* This is a newer system with GetFileSizeEx; we use - this then becuase it seem that GetFileSize won't - return a proper error in case a file is larger than - 4GB. */ - LARGE_INTEGER size; - - if (get_file_size_ex (fp, &size)) - { - if (!size.u.HighPart) - return size.u.LowPart; - if (overflow) - *overflow = 1; - return 0; - } + if (!exsize.u.HighPart) + return exsize.u.LowPart; + if (overflow) + *overflow = 1; + return 0; } - else - { - if ((size=GetFileSize (fp, NULL)) != 0xffffffff) - return size; - } - log_error ("GetFileSize for handle %p failed: %s\n", - fp, w32_strerror (0)); + } + else + { + if ((size=GetFileSize (fp, NULL)) != 0xffffffff) + return size; + } + log_error ("GetFileSize for handle %p failed: %s\n", + fp, w32_strerror (0)); #else - if( !fstat(my_fileno(fp), &st) ) - return st.st_size; - log_error("fstat() failed: %s\n", strerror(errno) ); + if ( !fstat(my_fileno(fp), &st) ) + return st.st_size; + log_error("fstat() failed: %s\n", strerror(errno) ); #endif - break; - } - + break/*the for loop*/; + } + return 0; } diff --git a/common/simple-gettext.c b/common/simple-gettext.c deleted file mode 100644 index 6661b2d12..000000000 --- a/common/simple-gettext.c +++ /dev/null @@ -1,447 +0,0 @@ -/* simple-gettext.c - a simplified version of gettext. - * Copyright (C) 1995, 1996, 1997, 1999 Free Software Foundation, Inc. - * - * This file is part of GnuPG. - * - * GnuPG 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. - * - * GnuPG 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - */ - -/* This is a simplified version of gettext written by Ulrich Drepper. - * It is used for the Win32 version of GnuPG beucase all the overhead - * of gettext is not needed and we have to do some special Win32 stuff. - * I decided that this is far easier than to tweak gettext for the special - * cases (I tried it but it is a lot of code). wk 15.09.99 - */ - -#include <config.h> -#ifdef USE_SIMPLE_GETTEXT -#if !defined (_WIN32) && !defined (__CYGWIN32__) -#error This file can only be used under Windows or Cygwin32 -#endif - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <ctype.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/stat.h> - -#include "util.h" -#include "sysutils.h" - -/* The magic number of the GNU message catalog format. */ -#define MAGIC 0x950412de -#define MAGIC_SWAPPED 0xde120495 - -/* Revision number of the currently used .mo (binary) file format. */ -#define MO_REVISION_NUMBER 0 - - -/* Header for binary .mo file format. */ -struct mo_file_header -{ - /* The magic number. */ - u32 magic; - /* The revision number of the file format. */ - u32 revision; - /* The number of strings pairs. */ - u32 nstrings; - /* Offset of table with start offsets of original strings. */ - u32 orig_tab_offset; - /* Offset of table with start offsets of translation strings. */ - u32 trans_tab_offset; - /* Size of hashing table. */ - u32 hash_tab_size; - /* Offset of first hashing entry. */ - u32 hash_tab_offset; -}; - -struct string_desc -{ - /* Length of addressed string. */ - u32 length; - /* Offset of string in file. */ - u32 offset; -}; - - -struct overflow_space_s -{ - struct overflow_space_s *next; - u32 idx; - char d[1]; -}; - -struct loaded_domain -{ - char *data; - int must_swap; - u32 nstrings; - char *mapped; /* 0 = not yet mapped, 1 = mapped, - 2 = mapped to - overflow space */ - struct overflow_space_s *overflow_space; - struct string_desc *orig_tab; - struct string_desc *trans_tab; - u32 hash_size; - u32 *hash_tab; -}; - - -static struct loaded_domain *the_domain; - -static __inline__ u32 -do_swap_u32( u32 i ) -{ - return (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24); -} - -#define SWAPIT(flag, data) ((flag) ? do_swap_u32(data) : (data) ) - - -/* We assume to have `unsigned long int' value with at least 32 bits. */ -#define HASHWORDBITS 32 - -/* The so called `hashpjw' function by P.J. Weinberger - [see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools, - 1986, 1987 Bell Telephone Laboratories, Inc.] */ - -static __inline__ ulong -hash_string( const char *str_param ) -{ - unsigned long int hval, g; - const char *str = str_param; - - hval = 0; - while (*str != '\0') - { - hval <<= 4; - hval += (unsigned long int) *str++; - g = hval & ((unsigned long int) 0xf << (HASHWORDBITS - 4)); - if (g != 0) - { - hval ^= g >> (HASHWORDBITS - 8); - hval ^= g; - } - } - return hval; -} - - -static struct loaded_domain * -load_domain( const char *filename ) -{ - FILE *fp; - size_t size; - struct stat st; - struct mo_file_header *data = NULL; - struct loaded_domain *domain = NULL; - size_t to_read; - char *read_ptr; - - fp = fopen( filename, "rb" ); - if( !fp ) - return NULL; /* can't open the file */ - /* we must know about the size of the file */ - if( fstat( fileno(fp ), &st ) - || (size = (size_t)st.st_size) != st.st_size - || size < sizeof (struct mo_file_header) ) { - fclose( fp ); - return NULL; - } - - data = malloc( size ); - if( !data ) { - fclose( fp ); - return NULL; /* out of memory */ - } - - to_read = size; - read_ptr = (char *) data; - do { - long int nb = fread( read_ptr, 1, to_read, fp ); - if( nb < to_read ) { - fclose (fp); - free(data); - return NULL; /* read error */ - } - read_ptr += nb; - to_read -= nb; - } while( to_read > 0 ); - fclose (fp); - - /* Using the magic number we can test whether it really is a message - * catalog file. */ - if( data->magic != MAGIC && data->magic != MAGIC_SWAPPED ) { - /* The magic number is wrong: not a message catalog file. */ - free( data ); - return NULL; - } - - domain = calloc( 1, sizeof *domain ); - if( !domain ) { - free( data ); - return NULL; - } - domain->data = (char *) data; - domain->must_swap = data->magic != MAGIC; - - /* Fill in the information about the available tables. */ - switch( SWAPIT(domain->must_swap, data->revision) ) { - case 0: - domain->nstrings = SWAPIT(domain->must_swap, data->nstrings); - domain->orig_tab = (struct string_desc *) - ((char *) data + SWAPIT(domain->must_swap, data->orig_tab_offset)); - domain->trans_tab = (struct string_desc *) - ((char *) data + SWAPIT(domain->must_swap, data->trans_tab_offset)); - domain->hash_size = SWAPIT(domain->must_swap, data->hash_tab_size); - domain->hash_tab = (u32 *) - ((char *) data + SWAPIT(domain->must_swap, data->hash_tab_offset)); - break; - - default: /* This is an invalid revision. */ - free( data ); - free( domain ); - return NULL; - } - - /* Allocate an array to keep track of code page mappings. */ - domain->mapped = calloc( 1, domain->nstrings ); - if( !domain->mapped ) { - free( data ); - free( domain ); - return NULL; - } - - return domain; -} - - -/**************** - * Set the file used for translations. Pass a NULL to disable - * translation. A new filename may be set at anytime. - * WARNING: After changing the filename you should not access any data - * retrieved by gettext(). - */ -int -set_gettext_file( const char *filename ) -{ - struct loaded_domain *domain = NULL; - - if( filename && *filename ) { - if( filename[0] == '/' -#ifdef HAVE_DRIVE_LETTERS - || ( isalpha(filename[0]) - && filename[1] == ':' - && (filename[2] == '/' || filename[2] == '\\') ) -#endif - ) { - /* absolute path - use it as is */ - domain = load_domain( filename ); - } - else { /* relative path - append ".mo" and get dir from the environment */ - char *buf = NULL; - char *dir; - char *p; - - dir = read_w32_registry_string( NULL, - "Control Panel\\Mingw32\\NLS", - "MODir" ); - if( dir && (buf=malloc(strlen(dir)+strlen(filename)+1+3+1)) ) { - strcpy(stpcpy(stpcpy(stpcpy( buf, dir),"\\"), filename),".mo"); - /* Better make sure that we don't mix forward and - backward slashes. It seems that some Windoze - versions don't accept this. */ - for (p=buf; *p; p++) - { - if (*p == '/') - *p = '\\'; - } - domain = load_domain( buf ); - free(buf); - } - free(dir); - } - if( !domain ) - return -1; - } - - if( the_domain ) { - struct overflow_space_s *os, *os2; - free( the_domain->data ); - free( the_domain->mapped ); - for (os=the_domain->overflow_space; os; os = os2) { - os2 = os->next; - free (os); - } - free( the_domain ); - the_domain = NULL; - } - the_domain = domain; - return 0; -} - - -static const char* -get_string( struct loaded_domain *domain, u32 idx ) -{ - struct overflow_space_s *os; - char *p; - - p = domain->data + SWAPIT(domain->must_swap, domain->trans_tab[idx].offset); - if (!domain->mapped[idx]) - { - size_t plen, buflen; - char *buf; - - domain->mapped[idx] = 1; - - plen = strlen (p); - buf = utf8_to_native (p, plen, -1); - buflen = strlen (buf); - if (buflen <= plen) - strcpy (p, buf); - else - { - /* There is not enough space for the translation - store it - in the overflow_space else and mark that in the mapped - array. Because we expect that this won't happen too - often, we use a simple linked list. */ - os = malloc (sizeof *os + buflen); - if (os) - { - os->idx = idx; - strcpy (os->d, buf); - os->next = domain->overflow_space; - domain->overflow_space = os; - p = os->d; - } - else - p = "ERROR in GETTEXT MALLOC"; - } - xfree (buf); - } - else if (domain->mapped[idx] == 2) - { /* We need to get the string from the overflow_space. */ - for (os=domain->overflow_space; os; os = os->next) - if (os->idx == idx) - return (const char*)os->d; - p = "ERROR in GETTEXT\n"; - } - return (const char*)p; -} - - - -const char * -gettext( const char *msgid ) -{ - struct loaded_domain *domain; - size_t act = 0; - size_t top, bottom; - - if( !(domain = the_domain) ) - goto not_found; - - /* Locate the MSGID and its translation. */ - if( domain->hash_size > 2 && domain->hash_tab ) { - /* Use the hashing table. */ - u32 len = strlen (msgid); - u32 hash_val = hash_string (msgid); - u32 idx = hash_val % domain->hash_size; - u32 incr = 1 + (hash_val % (domain->hash_size - 2)); - u32 nstr = SWAPIT (domain->must_swap, domain->hash_tab[idx]); - - if ( !nstr ) /* Hash table entry is empty. */ - goto not_found; - - if( SWAPIT(domain->must_swap, - domain->orig_tab[nstr - 1].length) == len - && !strcmp( msgid, - domain->data + SWAPIT(domain->must_swap, - domain->orig_tab[nstr - 1].offset)) ) - return get_string( domain, nstr - 1 ); - - for(;;) { - if (idx >= domain->hash_size - incr) - idx -= domain->hash_size - incr; - else - idx += incr; - - nstr = SWAPIT(domain->must_swap, domain->hash_tab[idx]); - if( !nstr ) - goto not_found; /* Hash table entry is empty. */ - - if ( SWAPIT(domain->must_swap, - domain->orig_tab[nstr - 1].length) == len - && !strcmp (msgid, - domain->data + SWAPIT(domain->must_swap, - domain->orig_tab[nstr - 1].offset))) - return get_string( domain, nstr-1 ); - } - /* NOTREACHED */ - } - - /* Now we try the default method: binary search in the sorted - array of messages. */ - bottom = 0; - top = domain->nstrings; - while( bottom < top ) { - int cmp_val; - - act = (bottom + top) / 2; - cmp_val = strcmp(msgid, domain->data - + SWAPIT(domain->must_swap, - domain->orig_tab[act].offset)); - if (cmp_val < 0) - top = act; - else if (cmp_val > 0) - bottom = act + 1; - else - return get_string( domain, act ); - } - - not_found: - return msgid; -} - - -const char * -ngettext (const char *msgid1, const char *msgid2, unsigned long int n) -{ - /* We use the simple Germanic plural rule. */ - return gettext (n==1? msgid1 : msgid2); -} - - -#if 0 - unsigned int cp1, cp2; - - cp1 = GetConsoleCP(); - cp2 = GetConsoleOutputCP(); - - log_info("InputCP=%u OutputCP=%u\n", cp1, cp2 ); - - if( !SetConsoleOutputCP( 1252 ) ) - log_info("SetConsoleOutputCP failed: %s\n", w32_strerror (0)); - - cp1 = GetConsoleCP(); - cp2 = GetConsoleOutputCP(); - log_info("InputCP=%u OutputCP=%u after switch1\n", cp1, cp2 ); -#endif - -#endif /* USE_SIMPLE_GETTEXT */ diff --git a/common/srv.h b/common/srv.h index 55906eb00..e8ea6952c 100644 --- a/common/srv.h +++ b/common/srv.h @@ -23,13 +23,13 @@ #define GNUPG_COMMON_SRV_H #ifdef USE_DNS_SRV -#ifdef _WIN32 -#include <windows.h> -#else -#include <netinet/in.h> -#include <arpa/nameser.h> -#include <resolv.h> -#endif /* !_WIN32 */ +# ifdef _WIN32 +# include <windows.h> +# else +# include <netinet/in.h> +# include <arpa/nameser.h> +# include <resolv.h> +# endif /* !_WIN32 */ #endif /* USE_DNS_SRV */ diff --git a/common/sysutils.c b/common/sysutils.c index 3e52cdaa3..d044f222b 100644 --- a/common/sysutils.c +++ b/common/sysutils.c @@ -125,7 +125,7 @@ get_session_marker( size_t *rlen ) ulong a, b; initialized = 1; - /* also this marker is guessable it is not easy to use this + /* Although this marker is guessable it is not easy to use * for a faked control packet because an attacker does not * have enough control about the time the verification does * take place. Of course, we can add just more random but diff --git a/common/sysutils.h b/common/sysutils.h index c40dbfaa9..712991599 100644 --- a/common/sysutils.h +++ b/common/sysutils.h @@ -33,11 +33,7 @@ int check_permissions (const char *path,int extension,int checkonly); _sleep but non for the still existing sleep. */ #define sleep(a) _sleep ((a)) -/*-- w32reg.c --*/ -char *read_w32_registry_string( const char *root, - const char *dir, const char *name ); -int write_w32_registry_string(const char *root, const char *dir, - const char *name, const char *value); +#include "../jnlib/w32help.h" #endif /*HAVE_W32_SYSTEM*/ diff --git a/common/ttyio.c b/common/ttyio.c index 8f1e7b35c..831ad9048 100644 --- a/common/ttyio.c +++ b/common/ttyio.c @@ -168,6 +168,8 @@ init_ttyfp(void) #elif defined(__EMX__) ttyfp = stdout; /* Fixme: replace by the real functions: see wklib */ + if (my_rl_init_stream) + my_rl_init_stream (ttyfp); #else ttyfp = batchmode? stderr : fopen (tty_get_ttyname (), "r+"); if( !ttyfp ) { @@ -175,10 +177,10 @@ init_ttyfp(void) strerror(errno) ); exit(2); } -#endif - if (my_rl_init_stream) my_rl_init_stream (ttyfp); +#endif + #ifdef HAVE_TCGETATTR atexit( cleanup ); diff --git a/common/util.h b/common/util.h index 5aeb7917c..3b7050132 100644 --- a/common/util.h +++ b/common/util.h @@ -38,6 +38,7 @@ #include "../jnlib/strlist.h" #include "../jnlib/dotlock.h" #include "../jnlib/utf8conv.h" +#include "../jnlib/dynload.h" /* Redefine asprintf by our estream version which uses our own memory allocator.. */ @@ -204,8 +205,8 @@ int match_multistr (const char *multistr,const char *match); static inline char * ttyname (int fd) { - return NULL -}; + return NULL; +} #endif /* !HAVE_TTYNAME */ diff --git a/common/w32reg.c b/common/w32reg.c deleted file mode 100644 index 84308e916..000000000 --- a/common/w32reg.c +++ /dev/null @@ -1,174 +0,0 @@ -/* w32reg.c - MS-Windows Registry access - * Copyright (C) 1999, 2002 Free Software Foundation, Inc. - * - * This file is part of GnuPG. - * - * GnuPG 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. - * - * GnuPG 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - */ - -#include <config.h> -#ifdef HAVE_W32_SYSTEM - /* This module is only used in this environment */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdarg.h> -#include <windows.h> - -#include "util.h" -#include "sysutils.h" - -static HKEY -get_root_key(const char *root) -{ - HKEY root_key; - - if( !root ) - root_key = HKEY_CURRENT_USER; - else if( !strcmp( root, "HKEY_CLASSES_ROOT" ) ) - root_key = HKEY_CLASSES_ROOT; - else if( !strcmp( root, "HKEY_CURRENT_USER" ) ) - root_key = HKEY_CURRENT_USER; - else if( !strcmp( root, "HKEY_LOCAL_MACHINE" ) ) - root_key = HKEY_LOCAL_MACHINE; - else if( !strcmp( root, "HKEY_USERS" ) ) - root_key = HKEY_USERS; - else if( !strcmp( root, "HKEY_PERFORMANCE_DATA" ) ) - root_key = HKEY_PERFORMANCE_DATA; - else if( !strcmp( root, "HKEY_CURRENT_CONFIG" ) ) - root_key = HKEY_CURRENT_CONFIG; - else - return NULL; - - return root_key; -} - - -/**************** - * Return a string from the Win32 Registry or NULL in case of - * error. Caller must release the return value. A NULL for root - * is an alias for HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE in turn. - * NOTE: The value is allocated with a plain malloc() - use free() and not - * the usual m_free()!!! - */ -char * -read_w32_registry_string( const char *root, const char *dir, const char *name ) -{ - HKEY root_key, key_handle; - DWORD n1, nbytes, type; - char *result = NULL; - - if ( !(root_key = get_root_key(root) ) ) - return NULL; - - if( RegOpenKeyEx( root_key, dir, 0, KEY_READ, &key_handle ) ) - { - if (root) - return NULL; /* no need for a RegClose, so return direct */ - /* It seems to be common practise to fall back to HLM. */ - if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, dir, 0, KEY_READ, &key_handle) ) - return NULL; /* still no need for a RegClose, so return direct */ - } - - nbytes = 1; - if( RegQueryValueEx( key_handle, name, 0, NULL, NULL, &nbytes ) ) - goto leave; - result = malloc( (n1=nbytes+1) ); - if( !result ) - goto leave; - if( RegQueryValueEx( key_handle, name, 0, &type, result, &n1 ) ) { - free(result); result = NULL; - goto leave; - } - result[nbytes] = 0; /* make sure it is really a string */ - if (type == REG_EXPAND_SZ && strchr (result, '%')) { - char *tmp; - - n1 += 1000; - tmp = malloc (n1+1); - if (!tmp) - goto leave; - nbytes = ExpandEnvironmentStrings (result, tmp, n1); - if (nbytes && nbytes > n1) { - free (tmp); - n1 = nbytes; - tmp = malloc (n1 + 1); - if (!tmp) - goto leave; - nbytes = ExpandEnvironmentStrings (result, tmp, n1); - if (nbytes && nbytes > n1) { - free (tmp); /* oops - truncated, better don't expand at all */ - goto leave; - } - tmp[nbytes] = 0; - free (result); - result = tmp; - } - else if (nbytes) { /* okay, reduce the length */ - tmp[nbytes] = 0; - free (result); - result = malloc (strlen (tmp)+1); - if (!result) - result = tmp; - else { - strcpy (result, tmp); - free (tmp); - } - } - else { /* error - don't expand */ - free (tmp); - } - } - - leave: - RegCloseKey( key_handle ); - return result; -} - - -int -write_w32_registry_string(const char *root, const char *dir, - const char *name, const char *value) -{ - HKEY root_key, reg_key; - - if ( !(root_key = get_root_key(root) ) ) - return -1; - - if ( RegOpenKeyEx( root_key, dir, 0, KEY_WRITE, ®_key ) - != ERROR_SUCCESS ) - return -1; - - if ( RegSetValueEx( reg_key, name, 0, REG_SZ, (BYTE *)value, - strlen( value ) ) != ERROR_SUCCESS ) { - if ( RegCreateKey( root_key, name, ®_key ) != ERROR_SUCCESS ) { - RegCloseKey(reg_key); - return -1; - } - if ( RegSetValueEx( reg_key, name, 0, REG_SZ, (BYTE *)value, - strlen( value ) ) != ERROR_SUCCESS ) { - RegCloseKey(reg_key); - return -1; - } - } - - RegCloseKey( reg_key ); - - return 0; -} - -#endif /*HAVE_W32_SYSTEM*/ diff --git a/configure.ac b/configure.ac index d4b039af4..3db35c170 100644 --- a/configure.ac +++ b/configure.ac @@ -439,6 +439,7 @@ AH_BOTTOM([ AM_MAINTAINER_MODE # Checks for programs. +AC_MSG_NOTICE([checking for programs]) AC_PROG_MAKE_SET AM_SANITY_CHECK missing_dir=`cd $ac_aux_dir && pwd` @@ -465,6 +466,22 @@ AC_SYS_LARGEFILE GNUPG_CHECK_FAQPROG GNUPG_CHECK_USTAR +# We need to compile and run a program on the build machine. A +# comment in libgpg-error says that the AC_PROG_CC_FOR_BUILD macro in +# the AC archive is broken for autoconf 2.57. Given that tehre is no +# newer version of that macro, we assume that it is also broken for +# autoconf 2.61 and thus we use a simple but usually sufficient +# approach. +AC_MSG_CHECKING(for cc for build) +if test "$cross_compiling" = "yes"; then + CC_FOR_BUILD="${CC_FOR_BUILD-cc}" +else + CC_FOR_BUILD="${CC_FOR_BUILD-$CC}" +fi +AC_MSG_RESULT($CC_FOR_BUILD) +AC_ARG_VAR(CC_FOR_BUILD,[build system C compiler]) + + try_gettext=yes have_dosish_system=no @@ -573,6 +590,7 @@ fi # # Checks for libraries. # +AC_MSG_NOTICE([checking for libraries]) # @@ -674,6 +692,7 @@ else fi +AC_MSG_NOTICE([checking for networking options]) # # Must check for network library requirements before doing link tests @@ -863,6 +882,7 @@ AC_DEFINE_UNQUOTED(PRINTABLE_OS_NAME, "$PRINTABLE_OS_NAME", # # Check for gettext # +AC_MSG_NOTICE([checking for gettext]) AM_GNU_GETTEXT_VERSION([0.16.1]) if test "$try_gettext" = yes; then AM_GNU_GETTEXT(,[need-ngettext]) @@ -893,6 +913,7 @@ fi # # Checks for header files. # +AC_MSG_NOTICE([checking for header files]) AC_HEADER_STDC AC_CHECK_HEADERS([string.h unistd.h langinfo.h termio.h locale.h getopt.h]) AC_CHECK_HEADERS([pty.h pwd.h inttypes.h]) @@ -902,6 +923,7 @@ AC_HEADER_TIME # # Checks for typedefs, structures, and compiler characteristics. # +AC_MSG_NOTICE([checking for system characteristics]) AC_C_CONST AC_C_INLINE AC_C_VOLATILE @@ -965,6 +987,7 @@ fi # # Checks for library functions. # +AC_MSG_NOTICE([checking for library functions]) AC_CHECK_DECLS(getpagesize) AC_FUNC_FSEEKO AC_FUNC_VPRINTF @@ -991,11 +1014,10 @@ AC_CHECK_FUNCS([flockfile funlockfile fopencookie funopen]) # gl_SOURCE_BASE([gl]) gl_M4_BASE([gl/m4]) -gl_MODULES([setenv mkdtemp xsize]) +gl_MODULES([setenv mkdtemp xsize strpbrk]) gl_INIT - # # W32 specific test # @@ -1151,6 +1173,7 @@ AC_SUBST(NETLIBS) # # Setup gcc specific options # +AC_MSG_NOTICE([checking for cc features]) if test "$GCC" = yes; then # Note that it is okay to use CFLAGS here because this are just # warning options and the user should have a chance of overriding @@ -1171,6 +1194,16 @@ if test "$GCC" = yes; then if test x"$_gcc_psign" = xyes ; then CFLAGS="$CFLAGS -Wno-pointer-sign" fi + + AC_MSG_CHECKING([if gcc supports -Wpointer-arith]) + _gcc_cflags_save=$CFLAGS + CFLAGS="-Wpointer-arith" + AC_COMPILE_IFELSE(AC_LANG_PROGRAM([]),_gcc_psign=yes,_gcc_psign=no) + AC_MSG_RESULT($_gcc_psign) + CFLAGS=$_gcc_cflags_save; + if test x"$_gcc_psign" = xyes ; then + CFLAGS="$CFLAGS -Wpointer-arith" + fi fi @@ -1186,14 +1219,6 @@ AC_ARG_ENABLE(optimization, fi]) # -# For W32 we need to use our Pth emulation code -# -if test "$have_w32_system" = yes; then - AC_CONFIG_LINKS(pth.h:jnlib/w32-pth.h) -fi - - -# # Prepare building of estream # estream_INIT @@ -1308,6 +1333,9 @@ if test "$missing_pth" = "yes"; then *** ftp://ftp.gnu.org/gnu/pth/ *** On a Debian GNU/Linux system you can install it using *** apt-get install libpth-dev +*** To build GnuPG for Windows you need to use the W32PTH +*** package; available at: +*** ftp://ftp.g10code.com/g10code/w32pth/ ***]]) die=yes fi diff --git a/doc/ChangeLog b/doc/ChangeLog index 8811a8824..9dfcb86b4 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,10 @@ +2007-06-06 Werner Koch <wk@g10code.com> + + * Makefile.am (yat2m): Use a plain rule to build it for the sake + of cross-compiling. + + * yat2m.c (finish_page): Init SECT to NULL. + 2007-05-11 Werner Koch <wk@g10code.com> * gpgsm.texi (--export): Enhanced description. diff --git a/doc/Makefile.am b/doc/Makefile.am index feb3b7713..a3e019e95 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -28,13 +28,11 @@ EXTRA_DIST = DETAILS HACKING TRANSLATE OpenPGP KEYSERVER samplekeys.asc \ gnupg-card-architecture.pdf \ faq.raw FAQ faq.html gnupg7.texi \ opt-homedir.texi see-also-note.texi specify-user-id.texi \ - gpgv.texi texi.css $(examples) + gpgv.texi texi.css $(examples) yat2m.c BUILT_SOURCES = gnupg-card-architecture.eps gnupg-card-architecture.png \ gnupg-card-architecture.pdf FAQ faq.html -noinst_PROGRAMS = yat2m - info_TEXINFOS = gnupg.texi dist_pkgdata_DATA = qualified.txt FAQ faq.html com-certs.pem @@ -65,13 +63,13 @@ noinst_MANS = gnupg.7 watchgnupg_SOURCE = gnupg.texi -CLEANFILES = faq.raw.xref +CLEANFILES = faq.raw.xref yat2m DISTCLEANFILES = gnupg.tmp gnupg.ops yat2m-stamp.tmp yat2m-stamp \ $(myman_pages) gnupg.7 -yat2m_SOURCES = yat2m.c - +yat2m: yat2m.c + $(CC_FOR_BUILD) -o $@ $(srcdir)/yat2m.c .fig.png: diff --git a/doc/tools.texi b/doc/tools.texi index 4187293c6..cce773d9b 100644 --- a/doc/tools.texi +++ b/doc/tools.texi @@ -229,7 +229,7 @@ Update all configuration files with values taken from the global configuration file (usually @file{/etc/gnupg/gpgconf.conf}). @item --check-config [@var{filename}] -Run a syntax check ion the global configuration file. If @var{filename} +Run a syntax check on the global configuration file. If @var{filename} is given, check that file instead. @end table diff --git a/doc/yat2m.c b/doc/yat2m.c index e250db4d5..4ead165ae 100644 --- a/doc/yat2m.c +++ b/doc/yat2m.c @@ -755,7 +755,7 @@ static void finish_page (void) { FILE *fp; - section_buffer_t sect; + section_buffer_t sect = NULL; int idx; const char *s; int i; diff --git a/g10/ChangeLog b/g10/ChangeLog index fb22ca0c6..192897ae6 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,21 @@ +2007-06-06 Werner Koch <wk@g10code.com> + + * passphrase.c (passphrase_get) [!ENABLE_NLS]: Do not define + orig_codeset. + + * Makefile.am (gpgv2_LDADD, gpg2_LDADD): Include LDADD before + libgcrypt. + + * plaintext.c (handle_plaintext): Replace eof by eof_seen as W32's + io.h has a symbol with that name. + + * misc.c: Do not include dynload.h. + (w32_shgetfolderpath): Remove. It is now in common/homedir.c. + + * gpgv.c (i18n_init): Remove. + * gpg.c (i18n_init): Remove. + (main): Make --load-extension a dummy + 2007-05-19 Marcus Brinkmann <marcus@g10code.de> * passphrase.c (passphrase_get): Use PACKAGE_GT, not PACKAGE. diff --git a/g10/Makefile.am b/g10/Makefile.am index fdca1405c..8f310fc83 100644 --- a/g10/Makefile.am +++ b/g10/Makefile.am @@ -119,9 +119,9 @@ gpgv2_SOURCES = gpgv.c \ LDADD = $(needed_libs) ../common/libgpgrl.a \ $(ZLIBS) $(DNSLIBS) $(LIBREADLINE) \ $(LIBINTL) $(CAPLIBS) $(NETLIBS) -gpg2_LDADD = $(LIBGCRYPT_LIBS) $(LDADD) $(LIBASSUAN_LIBS) $(GPG_ERROR_LIBS) \ +gpg2_LDADD = $(LDADD) $(LIBGCRYPT_LIBS)$(LIBASSUAN_LIBS) $(GPG_ERROR_LIBS) \ $(LIBICONV) -gpgv2_LDADD = $(LIBGCRYPT_LIBS) $(LDADD) $(LIBASSUAN_LIBS) $(GPG_ERROR_LIBS) \ +gpgv2_LDADD = $(LDADD) $(LIBGCRYPT_LIBS) $(LIBASSUAN_LIBS) $(GPG_ERROR_LIBS) \ $(LIBICONV) $(PROGRAMS): $(needed_libs) ../common/libgpgrl.a @@ -871,20 +871,6 @@ build_list( const char *text, char letter, static void -i18n_init(void) -{ -#ifdef USE_SIMPLE_GETTEXT - set_gettext_file (PACKAGE_GT, "Software\\GNU\\GnuPG"); -#else -#ifdef ENABLE_NLS - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE_GT, LOCALEDIR); - textdomain (PACKAGE_GT); -#endif -#endif -} - -static void wrong_args( const char *text) { fputs(_("usage: gpg [options] "),stderr); @@ -2260,18 +2246,8 @@ main (int argc, char **argv ) } break; case oLoadExtension: -#ifndef __riscos__ -#if defined(USE_DYNAMIC_LINKING) || defined(_WIN32) - if(check_permissions(pargs.r.ret_str,2)) - log_info(_("cipher extension `%s' not loaded due to" - " unsafe permissions\n"),pargs.r.ret_str); - else - register_cipher_extension(orig_argc? *orig_argv:NULL, - pargs.r.ret_str); -#endif -#else /* __riscos__ */ - riscos_not_implemented("load-extension"); -#endif /* __riscos__ */ + /* Dummy so that gpg 1.4 conf files can work. Should + eventually be removed. */ break; case oRFC1991: opt.compliance = CO_RFC1991; diff --git a/g10/gpgv.c b/g10/gpgv.c index b4730f459..6734ee2f7 100644 --- a/g10/gpgv.c +++ b/g10/gpgv.c @@ -110,21 +110,6 @@ my_strusage( int level ) } -static void -i18n_init(void) -{ -#ifdef USE_SIMPLE_GETTEXT - set_gettext_file (PACKAGE_GT, "Software\\GNU\\GnuPG"); -#else -#ifdef ENABLE_NLS - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE_GT, LOCALEDIR); - textdomain (PACKAGE_GT); -#endif -#endif -} - - int main( int argc, char **argv ) diff --git a/g10/misc.c b/g10/misc.c index 50bb6af13..89ad92643 100644 --- a/g10/misc.c +++ b/g10/misc.c @@ -58,7 +58,6 @@ #include "gpg.h" #ifdef HAVE_W32_SYSTEM # include "errors.h" -# include "dynload.h" #endif /*HAVE_W32_SYSTEM*/ #include "util.h" #include "main.h" @@ -1225,46 +1224,6 @@ is_valid_mailbox (const char *name) } -/* This is a helper function to load a Windows function from either of - one DLLs. */ -#ifdef HAVE_W32_SYSTEM -static HRESULT -w32_shgetfolderpath (HWND a, int b, HANDLE c, DWORD d, LPSTR e) -{ - static int initialized; - static HRESULT (WINAPI * func)(HWND,int,HANDLE,DWORD,LPSTR); - - if (!initialized) - { - static char *dllnames[] = { "shell32.dll", "shfolder.dll", NULL }; - void *handle; - int i; - - initialized = 1; - - for (i=0, handle = NULL; !handle && dllnames[i]; i++) - { - handle = dlopen (dllnames[i], RTLD_LAZY); - if (handle) - { - func = dlsym (handle, "SHGetFolderPathA"); - if (!func) - { - dlclose (handle); - handle = NULL; - } - } - } - } - - if (func) - return func (a,b,c,d,e); - else - return -1; -} -#endif /*HAVE_W32_SYSTEM*/ - - /* Return the name of the libexec directory. The name is allocated in a static area on the first use. This function won't fail. */ const char * diff --git a/g10/passphrase.c b/g10/passphrase.c index 970e4d9a3..2d904e5e1 100644 --- a/g10/passphrase.c +++ b/g10/passphrase.c @@ -259,7 +259,9 @@ passphrase_get ( u32 *keyid, int mode, const char *cacheid, PKT_public_key *pk = xmalloc_clear( sizeof *pk ); byte fpr[MAX_FINGERPRINT_LEN]; int have_fpr = 0; +#ifdef ENABLE_NLS char *orig_codeset = NULL; +#endif char *my_prompt; char hexfprbuf[20*2+1]; const char *my_cacheid; diff --git a/g10/plaintext.c b/g10/plaintext.c index fd165237e..4e48ddfbb 100644 --- a/g10/plaintext.c +++ b/g10/plaintext.c @@ -297,8 +297,9 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx, } else { /* binary mode */ byte *buffer = xmalloc( 32768 ); - int eof; - for( eof=0; !eof; ) { + int eof_seen = 0; + + while ( !eof_seen ) { /* Why do we check for len < 32768: * If we won't, we would practically read 2 EOFs but * the first one has already popped the block_filter @@ -309,7 +310,7 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx, if( len == -1 ) break; if( len < 32768 ) - eof = 1; + eof_seen = 1; if( mfx->md ) gcry_md_write ( mfx->md, buffer, len ); if( fp ) diff --git a/gl/Makefile.am b/gl/Makefile.am index 5fdb926d2..59667db7b 100644 --- a/gl/Makefile.am +++ b/gl/Makefile.am @@ -1,41 +1,46 @@ +## DO NOT EDIT! GENERATED AUTOMATICALLY! ## Process this file with automake to produce Makefile.in. -# Copyright (C) 2004 Free Software Foundation, Inc. +# Copyright (C) 2004-2006 Free Software Foundation, Inc. # # This file is free software, distributed under the terms of the GNU # General Public License. As a special exception to the GNU General # Public License, this file may be distributed as part of a program -# that contains a configuration script generated by Automake, under +# that contains a configuration script generated by Autoconf, under # the same distribution terms as the rest of that program. # # Generated by gnulib-tool. -# Invoked as: gnulib-tool --import -# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --aux-dir=scripts alloca-opt allocsa mkdtemp setenv strpbrk vasnprintf vasprintf xsize +# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --aux-dir=scripts --no-libtool --macro-prefix=gl alloca-opt allocsa mkdtemp setenv strpbrk xsize -AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies +AUTOMAKE_OPTIONS = 1.5 gnits noinst_LIBRARIES = libgnu.a libgnu_a_SOURCES = -libgnu_a_LIBADD = @LIBOBJS@ +libgnu_a_LIBADD = $(LIBOBJS) +noinst_HEADERS = EXTRA_DIST = BUILT_SOURCES = SUFFIXES = -MOSTLYCLEANFILES = +MOSTLYCLEANFILES = core *.stackdump +MOSTLYCLEANDIRS = CLEANFILES = DISTCLEANFILES = MAINTAINERCLEANFILES = +AM_CPPFLAGS = + ## begin gnulib module alloca-opt BUILT_SOURCES += $(ALLOCA_H) EXTRA_DIST += alloca_.h -# We need the following in order to create an <alloca.h> when the system +# We need the following in order to create <alloca.h> when the system # doesn't have one that works with the given compiler. -all-local $(libgnu_a_OBJECTS): $(ALLOCA_H) alloca.h: alloca_.h - cp $(srcdir)/alloca_.h $@-t - mv $@-t $@ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + cat $(srcdir)/alloca_.h; \ + } > $@-t + mv -f $@-t $@ MOSTLYCLEANFILES += alloca.h alloca.h-t ## end gnulib module alloca-opt @@ -59,6 +64,71 @@ libgnu_a_SOURCES += setenv.h ## end gnulib module setenv +## begin gnulib module size_max + +libgnu_a_SOURCES += size_max.h + +## end gnulib module size_max + +## begin gnulib module stdint + +BUILT_SOURCES += $(STDINT_H) +EXTRA_DIST += stdint_.h + +# We need the following in order to create <stdint.h> when the system +# doesn't have one that works with the given compiler. +stdint.h: stdint_.h + rm -f $@-t $@ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + sed -e 's/@''HAVE_WCHAR_H''@/$(HAVE_WCHAR_H)/g' \ + -e 's/@''HAVE_STDINT_H''@/$(HAVE_STDINT_H)/g' \ + -e 's|@''ABSOLUTE_STDINT_H''@|$(ABSOLUTE_STDINT_H)|g' \ + -e 's/@''HAVE_SYS_TYPES_H''@/$(HAVE_SYS_TYPES_H)/g' \ + -e 's/@''HAVE_INTTYPES_H''@/$(HAVE_INTTYPES_H)/g' \ + -e 's/@''HAVE_SYS_INTTYPES_H''@/$(HAVE_SYS_INTTYPES_H)/g' \ + -e 's/@''HAVE_SYS_BITYPES_H''@/$(HAVE_SYS_BITYPES_H)/g' \ + -e 's/@''HAVE_LONG_LONG_INT''@/$(HAVE_LONG_LONG_INT)/g' \ + -e 's/@''HAVE_UNSIGNED_LONG_LONG_INT''@/$(HAVE_UNSIGNED_LONG_LONG_INT)/g' \ + -e 's/@''BITSIZEOF_PTRDIFF_T''@/$(BITSIZEOF_PTRDIFF_T)/g' \ + -e 's/@''PTRDIFF_T_SUFFIX''@/$(PTRDIFF_T_SUFFIX)/g' \ + -e 's/@''BITSIZEOF_SIG_ATOMIC_T''@/$(BITSIZEOF_SIG_ATOMIC_T)/g' \ + -e 's/@''HAVE_SIGNED_SIG_ATOMIC_T''@/$(HAVE_SIGNED_SIG_ATOMIC_T)/g' \ + -e 's/@''SIG_ATOMIC_T_SUFFIX''@/$(SIG_ATOMIC_T_SUFFIX)/g' \ + -e 's/@''BITSIZEOF_SIZE_T''@/$(BITSIZEOF_SIZE_T)/g' \ + -e 's/@''SIZE_T_SUFFIX''@/$(SIZE_T_SUFFIX)/g' \ + -e 's/@''BITSIZEOF_WCHAR_T''@/$(BITSIZEOF_WCHAR_T)/g' \ + -e 's/@''HAVE_SIGNED_WCHAR_T''@/$(HAVE_SIGNED_WCHAR_T)/g' \ + -e 's/@''WCHAR_T_SUFFIX''@/$(WCHAR_T_SUFFIX)/g' \ + -e 's/@''BITSIZEOF_WINT_T''@/$(BITSIZEOF_WINT_T)/g' \ + -e 's/@''HAVE_SIGNED_WINT_T''@/$(HAVE_SIGNED_WINT_T)/g' \ + -e 's/@''WINT_T_SUFFIX''@/$(WINT_T_SUFFIX)/g' \ + < $(srcdir)/stdint_.h; \ + } > $@-t + mv $@-t $@ +MOSTLYCLEANFILES += stdint.h stdint.h-t + +## end gnulib module stdint + +## begin gnulib module strpbrk + +libgnu_a_SOURCES += strpbrk.h + +## end gnulib module strpbrk + +## begin gnulib module unistd + +BUILT_SOURCES += $(UNISTD_H) + +# We need the following in order to create an empty placeholder for +# <unistd.h> when the system doesn't have one. +unistd.h: + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + echo '/* Empty placeholder for $@. */'; \ + } > $@ +MOSTLYCLEANFILES += unistd.h + +## end gnulib module unistd + ## begin gnulib module xsize libgnu_a_SOURCES += xsize.h @@ -66,4 +136,10 @@ libgnu_a_SOURCES += xsize.h ## end gnulib module xsize -# Makefile.am ends here +mostlyclean-local: mostlyclean-generic + @test -z "$(MOSTLYCLEANDIRS)" || \ + for dir in $(MOSTLYCLEANDIRS); do \ + if test -d $$dir; then \ + echo "rmdir $$dir"; rmdir $$dir; \ + fi; \ + done diff --git a/gl/alloca_.h b/gl/alloca_.h index 3e3fdf43f..dd0b3e98f 100644 --- a/gl/alloca_.h +++ b/gl/alloca_.h @@ -1,6 +1,6 @@ /* Memory allocation on the stack. - Copyright (C) 1995, 1999, 2001, 2002, 2003, 2004 Free Software + Copyright (C) 1995, 1999, 2001, 2002, 2003, 2004, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it @@ -34,19 +34,21 @@ request, the program just crashes. */ -#ifdef __GNUC__ -# define alloca __builtin_alloca -#elif defined _AIX -# define alloca __alloca -#elif defined _MSC_VER -# include <malloc.h> -# define alloca _alloca -#else -# include <stddef.h> -# ifdef __cplusplus +#ifndef alloca +# ifdef __GNUC__ +# define alloca __builtin_alloca +# elif defined _AIX +# define alloca __alloca +# elif defined _MSC_VER +# include <malloc.h> +# define alloca _alloca +# else +# include <stddef.h> +# ifdef __cplusplus extern "C" -# endif +# endif void *alloca (size_t); +# endif #endif #endif /* _GNULIB_ALLOCA_H */ diff --git a/gl/allocsa.c b/gl/allocsa.c index a54e2d0ca..97652e688 100644 --- a/gl/allocsa.c +++ b/gl/allocsa.c @@ -1,5 +1,5 @@ /* Safe automatic memory allocation. - Copyright (C) 2003 Free Software Foundation, Inc. + Copyright (C) 2003, 2006 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2003. This program is free software; you can redistribute it and/or modify @@ -16,9 +16,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif +#include <config.h> /* Specification. */ #include "allocsa.h" diff --git a/gl/allocsa.h b/gl/allocsa.h index cb6893ad1..f8c0bc0bd 100644 --- a/gl/allocsa.h +++ b/gl/allocsa.h @@ -1,5 +1,5 @@ /* Safe automatic memory allocation. - Copyright (C) 2003-2004 Free Software Foundation, Inc. + Copyright (C) 2003-2006 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2003. This program is free software; you can redistribute it and/or modify @@ -23,6 +23,12 @@ #include <stddef.h> #include <stdlib.h> + +#ifdef __cplusplus +extern "C" { +#endif + + /* safe_alloca(N) is equivalent to alloca(N) when it is safe to call alloca(N); otherwise it returns NULL. It either returns N bytes of memory allocated on the stack, that lasts until the function returns, @@ -69,6 +75,11 @@ extern void freesa (void *p); If this would be useful in your application. please speak up. */ +#ifdef __cplusplus +} +#endif + + /* ------------------- Auxiliary, non-public definitions ------------------- */ /* Determine the alignment of a type at compile time. */ @@ -81,6 +92,10 @@ extern void freesa (void *p); /* Work around a HP-UX 10.20 cc bug with enums constants defined as offsetof values. */ # define sa_alignof(type) (sizeof (type) <= 4 ? 4 : 8) +#elif defined _AIX + /* Work around an AIX 3.2.5 xlc bug with enums constants defined as offsetof + values. */ +# define sa_alignof(type) (sizeof (type) <= 4 ? 4 : 8) #else # define sa_alignof(type) offsetof (struct { char __slot1; type __slot2; }, __slot2) #endif diff --git a/gl/m4/absolute-header.m4 b/gl/m4/absolute-header.m4 new file mode 100644 index 000000000..c649df084 --- /dev/null +++ b/gl/m4/absolute-header.m4 @@ -0,0 +1,44 @@ +# absolute-header.m4 serial 6 +dnl Copyright (C) 2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Derek Price. + +# gl_ABSOLUTE_HEADER(HEADER1 HEADER2 ...) +# --------------------------------------- +# Find the absolute name of a header file, assuming the header exists. +# If the header were sys/inttypes.h, this macro would define +# ABSOLUTE_SYS_INTTYPES_H to the `""' quoted absolute name of sys/inttypes.h +# in config.h +# (e.g. `#define ABSOLUTE_SYS_INTTYPES_H "///usr/include/sys/inttypes.h"'). +# The three "///" are to pacify Sun C 5.8, which otherwise would say +# "warning: #include of /usr/include/... may be non-portable". +# Use `""', not `<>', so that the /// cannot be confused with a C99 comment. +AC_DEFUN([gl_ABSOLUTE_HEADER], +[AC_LANG_PREPROC_REQUIRE()dnl +AC_FOREACH([gl_HEADER_NAME], [$1], + [AS_VAR_PUSHDEF([gl_absolute_header], + [gl_cv_absolute_]m4_quote(m4_defn([gl_HEADER_NAME])))dnl + AC_CACHE_CHECK([absolute name of <]m4_quote(m4_defn([gl_HEADER_NAME]))[>], + m4_quote(m4_defn([gl_absolute_header])), + [AS_VAR_PUSHDEF([ac_header_exists], + [ac_cv_header_]m4_quote(m4_defn([gl_HEADER_NAME])))dnl + AC_CHECK_HEADERS_ONCE(m4_quote(m4_defn([gl_HEADER_NAME])))dnl + if test AS_VAR_GET(ac_header_exists) = yes; then + AC_LANG_CONFTEST([AC_LANG_SOURCE([[#include <]]m4_dquote(m4_defn([gl_HEADER_NAME]))[[>]])]) +dnl eval is necessary to expand ac_cpp. +dnl Ultrix and Pyramid sh refuse to redirect output of eval, so use subshell. + AS_VAR_SET(gl_absolute_header, +[`(eval "$ac_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD | +sed -n '\#/]m4_quote(m4_defn([gl_HEADER_NAME]))[#{s#.*"\(.*/]m4_quote(m4_defn([gl_HEADER_NAME]))[\)".*#\1#;s#^/[^/]#//&#;p;q;}'`]) + fi + AS_VAR_POPDEF([ac_header_exists])dnl + ])dnl + AC_DEFINE_UNQUOTED(AS_TR_CPP([ABSOLUTE_]m4_quote(m4_defn([gl_HEADER_NAME]))), + ["AS_VAR_GET(gl_absolute_header)"], + [Define this to an absolute name of <]m4_quote(m4_defn([gl_HEADER_NAME]))[>.]) + AS_VAR_POPDEF([gl_absolute_header])dnl +])dnl +])# gl_ABSOLUTE_HEADER diff --git a/gl/m4/eoverflow.m4 b/gl/m4/eoverflow.m4 deleted file mode 100644 index 8c28ca305..000000000 --- a/gl/m4/eoverflow.m4 +++ /dev/null @@ -1,64 +0,0 @@ -# eoverflow.m4 serial 1 -dnl Copyright (C) 2004 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Bruno Haible. - -# The EOVERFLOW errno value ought to be defined in <errno.h>, according to -# POSIX. But some systems (like AIX 3) don't define it, and some systems -# (like OSF/1) define it when _XOPEN_SOURCE_EXTENDED is defined. - -# Define EOVERFLOW as a C macro and as a substituted macro in such a way that -# 1. on all systems, after inclusion of <errno.h>, EOVERFLOW is usable, -# 2. on systems where EOVERFLOW is defined elsewhere, we use the same numeric -# value. - -AC_DEFUN([gl_EOVERFLOW], -[ - AC_REQUIRE([AC_PROG_CC])dnl - - AC_CACHE_CHECK([for EOVERFLOW], ac_cv_decl_EOVERFLOW, [ - AC_EGREP_CPP(yes,[ -#include <errno.h> -#ifdef EOVERFLOW -yes -#endif - ], have_eoverflow=1) - if test -n "$have_eoverflow"; then - dnl EOVERFLOW exists in <errno.h>. Don't need to define EOVERFLOW ourselves. - ac_cv_decl_EOVERFLOW=yes - else - AC_EGREP_CPP(yes,[ -#define _XOPEN_SOURCE_EXTENDED 1 -#include <errno.h> -#ifdef EOVERFLOW -yes -#endif - ], have_eoverflow=1) - if test -n "$have_eoverflow"; then - dnl EOVERFLOW exists but is hidden. - dnl Define it to the same value. - _AC_COMPUTE_INT([EOVERFLOW], ac_cv_decl_EOVERFLOW, [ -#define _XOPEN_SOURCE_EXTENDED 1 -#include <errno.h> -/* The following two lines are a workaround against an autoconf-2.52 bug. */ -#include <stdio.h> -#include <stdlib.h> -]) - else - dnl EOVERFLOW isn't defined by the system. Define EOVERFLOW ourselves, but - dnl don't define it as EINVAL, because snprintf() callers want to - dnl distinguish EINVAL and EOVERFLOW. - ac_cv_decl_EOVERFLOW=E2BIG - fi - fi - ]) - if test "$ac_cv_decl_EOVERFLOW" != yes; then - AC_DEFINE_UNQUOTED([EOVERFLOW], [$ac_cv_decl_EOVERFLOW], - [Define as good substitute value for EOVERFLOW.]) - EOVERFLOW="$ac_cv_decl_EOVERFLOW" - AC_SUBST(EOVERFLOW) - fi -]) diff --git a/gl/m4/gnulib-cache.m4 b/gl/m4/gnulib-cache.m4 new file mode 100644 index 000000000..7277b1b33 --- /dev/null +++ b/gl/m4/gnulib-cache.m4 @@ -0,0 +1,30 @@ +# Copyright (C) 2004-2006 Free Software Foundation, Inc. +# +# This file is free software, distributed under the terms of the GNU +# General Public License. As a special exception to the GNU General +# Public License, this file may be distributed as part of a program +# that contains a configuration script generated by Autoconf, under +# the same distribution terms as the rest of that program. +# +# Generated by gnulib-tool. +# +# This file represents the specification of how gnulib-tool is used. +# It acts as a cache: It is written and read by gnulib-tool. +# In projects using CVS, this file is meant to be stored in CVS, +# like the configure.ac and various Makefile.am files. + + +# Specification in the form of a command-line invocation: +# gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --aux-dir=scripts --no-libtool --macro-prefix=gl alloca-opt allocsa mkdtemp setenv strpbrk xsize + +# Specification in the form of a few gnulib-tool.m4 macro invocations: +gl_LOCAL_DIR([]) +gl_MODULES([alloca-opt allocsa mkdtemp setenv strpbrk xsize]) +gl_AVOID([]) +gl_SOURCE_BASE([gl]) +gl_M4_BASE([gl/m4]) +gl_DOC_BASE([doc]) +gl_TESTS_BASE([tests]) +gl_LIB([libgnu]) +gl_MAKEFILE_NAME([]) +gl_MACRO_PREFIX([gl]) diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4 new file mode 100644 index 000000000..c23621bb6 --- /dev/null +++ b/gl/m4/gnulib-comp.m4 @@ -0,0 +1,83 @@ +# DO NOT EDIT! GENERATED AUTOMATICALLY! +# Copyright (C) 2004-2006 Free Software Foundation, Inc. +# +# This file is free software, distributed under the terms of the GNU +# General Public License. As a special exception to the GNU General +# Public License, this file may be distributed as part of a program +# that contains a configuration script generated by Autoconf, under +# the same distribution terms as the rest of that program. +# +# Generated by gnulib-tool. +# +# This file represents the compiled summary of the specification in +# gnulib-cache.m4. It lists the computed macro invocations that need +# to be invoked from configure.ac. +# In projects using CVS, this file can be treated like other built files. + + +# This macro should be invoked from ./configure.ac, in the section +# "Checks for programs", right after AC_PROG_CC, and certainly before +# any checks for libraries, header files, types and library functions. +AC_DEFUN([gl_EARLY], +[ + m4_pattern_forbid([^gl_[A-Z]])dnl the gnulib macro namespace + m4_pattern_allow([^gl_ES$])dnl a valid locale name + AC_REQUIRE([AC_PROG_RANLIB]) +]) + +# This macro should be invoked from ./configure.ac, in the section +# "Check for header files, types and library functions". +AC_DEFUN([gl_INIT], +[ + AM_CONDITIONAL([GL_COND_LIBTOOL], [false]) + gl_cond_libtool=false + gl_libdeps= + gl_ltlibdeps= + gl_source_base='gl' + gl_FUNC_ALLOCA + gl_ALLOCSA + gt_FUNC_MKDTEMP + gt_FUNC_SETENV + gl_SIZE_MAX + gl_STDINT_H + gl_FUNC_STRPBRK + gl_HEADER_UNISTD + gl_XSIZE + LIBGNU_LIBDEPS="$gl_libdeps" + AC_SUBST([LIBGNU_LIBDEPS]) + LIBGNU_LTLIBDEPS="$gl_ltlibdeps" + AC_SUBST([LIBGNU_LTLIBDEPS]) +]) + +# This macro records the list of files which have been installed by +# gnulib-tool and may be removed by future gnulib-tool invocations. +AC_DEFUN([gl_FILE_LIST], [ + lib/alloca_.h + lib/allocsa.c + lib/allocsa.h + lib/allocsa.valgrind + lib/mkdtemp.c + lib/mkdtemp.h + lib/setenv.c + lib/setenv.h + lib/size_max.h + lib/stdint_.h + lib/strpbrk.c + lib/strpbrk.h + lib/unsetenv.c + lib/xsize.h + m4/absolute-header.m4 + m4/alloca.m4 + m4/allocsa.m4 + m4/eealloc.m4 + m4/longdouble.m4 + m4/longlong.m4 + m4/mkdtemp.m4 + m4/setenv.m4 + m4/size_max.m4 + m4/stdint.m4 + m4/strpbrk.m4 + m4/ulonglong.m4 + m4/unistd_h.m4 + m4/xsize.m4 +]) diff --git a/gl/m4/gnulib-tool.m4 b/gl/m4/gnulib-tool.m4 new file mode 100644 index 000000000..ef5932031 --- /dev/null +++ b/gl/m4/gnulib-tool.m4 @@ -0,0 +1,33 @@ +# gnulib-tool.m4 serial 1 +dnl Copyright (C) 2004-2005 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl The following macros need not be invoked explicitly. +dnl Invoking them does nothing except to declare default arguments +dnl for "gnulib-tool --import". + +dnl Usage: gl_MODULES([module1 module2 ...]) +AC_DEFUN([gl_MODULES], []) + +dnl Usage: gl_AVOID([module1 module2 ...]) +AC_DEFUN([gl_AVOID], []) + +dnl Usage: gl_SOURCE_BASE([DIR]) +AC_DEFUN([gl_SOURCE_BASE], []) + +dnl Usage: gl_M4_BASE([DIR]) +AC_DEFUN([gl_M4_BASE], []) + +dnl Usage: gl_LIB([LIBNAME]) +AC_DEFUN([gl_LIB], []) + +dnl Usage: gl_LGPL +AC_DEFUN([gl_LGPL], []) + +dnl Usage: gl_LIBTOOL +AC_DEFUN([gl_LIBTOOL], []) + +dnl Usage: gl_MACRO_PREFIX([PREFIX]) +AC_DEFUN([gl_MACRO_PREFIX], []) diff --git a/gl/m4/gnulib.m4 b/gl/m4/gnulib.m4 deleted file mode 100644 index a17d49dbd..000000000 --- a/gl/m4/gnulib.m4 +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright (C) 2004 Free Software Foundation, Inc. -# This file is free software, distributed under the terms of the GNU -# General Public License. As a special exception to the GNU General -# Public License, this file may be distributed as part of a program -# that contains a configuration script generated by Autoconf, under -# the same distribution terms as the rest of that program. -# -# Generated by gnulib-tool. -# -# Invoked as: gnulib-tool --import -# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --aux-dir=scripts alloca-opt allocsa mkdtemp setenv strpbrk vasnprintf vasprintf xsize - -AC_DEFUN([gl_EARLY], -[ - AC_GNU_SOURCE -]) - -AC_DEFUN([gl_INIT], -[ - gl_FUNC_ALLOCA - gl_ALLOCSA - gt_FUNC_MKDTEMP - gt_FUNC_SETENV - gl_FUNC_VASNPRINTF - gl_FUNC_VASPRINTF - gl_XSIZE -]) - -dnl Usage: gl_MODULES(module1 module2 ...) -AC_DEFUN([gl_MODULES], []) - -dnl Usage: gl_SOURCE_BASE(DIR) -AC_DEFUN([gl_SOURCE_BASE], []) - -dnl Usage: gl_M4_BASE(DIR) -AC_DEFUN([gl_M4_BASE], []) - -dnl Usage: gl_LIB(LIBNAME) -AC_DEFUN([gl_LIB], []) - -dnl Usage: gl_LGPL -AC_DEFUN([gl_LGPL], []) - -# gnulib.m4 ends here diff --git a/gl/m4/intmax_t.m4 b/gl/m4/intmax_t.m4 deleted file mode 100644 index 44b16523c..000000000 --- a/gl/m4/intmax_t.m4 +++ /dev/null @@ -1,61 +0,0 @@ -# intmax_t.m4 serial 4 -dnl Copyright (C) 1997-2004 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Paul Eggert. - -AC_PREREQ(2.13) - -# Define intmax_t to 'long' or 'long long' -# if it is not already defined in <stdint.h> or <inttypes.h>. - -AC_DEFUN([gl_AC_TYPE_INTMAX_T], -[ - dnl For simplicity, we assume that a header file defines 'intmax_t' if and - dnl only if it defines 'uintmax_t'. - AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) - AC_REQUIRE([gl_AC_HEADER_STDINT_H]) - if test $gl_cv_header_inttypes_h = no && test $gl_cv_header_stdint_h = no; then - AC_REQUIRE([gl_AC_TYPE_LONG_LONG]) - test $ac_cv_type_long_long = yes \ - && ac_type='long long' \ - || ac_type='long' - AC_DEFINE_UNQUOTED(intmax_t, $ac_type, - [Define to long or long long if <inttypes.h> and <stdint.h> don't define.]) - else - AC_DEFINE(HAVE_INTMAX_T, 1, - [Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>.]) - fi -]) - -dnl An alternative would be to explicitly test for 'intmax_t'. - -AC_DEFUN([gt_AC_TYPE_INTMAX_T], -[ - AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) - AC_REQUIRE([gl_AC_HEADER_STDINT_H]) - AC_CACHE_CHECK(for intmax_t, gt_cv_c_intmax_t, - [AC_TRY_COMPILE([ -#include <stddef.h> -#include <stdlib.h> -#if HAVE_STDINT_H_WITH_UINTMAX -#include <stdint.h> -#endif -#if HAVE_INTTYPES_H_WITH_UINTMAX -#include <inttypes.h> -#endif -], [intmax_t x = -1;], gt_cv_c_intmax_t=yes, gt_cv_c_intmax_t=no)]) - if test $gt_cv_c_intmax_t = yes; then - AC_DEFINE(HAVE_INTMAX_T, 1, - [Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>.]) - else - AC_REQUIRE([gl_AC_TYPE_LONG_LONG]) - test $ac_cv_type_long_long = yes \ - && ac_type='long long' \ - || ac_type='long' - AC_DEFINE_UNQUOTED(intmax_t, $ac_type, - [Define to long or long long if <stdint.h> and <inttypes.h> don't define.]) - fi -]) diff --git a/gl/m4/inttypes_h.m4 b/gl/m4/inttypes_h.m4 deleted file mode 100644 index a5d075d96..000000000 --- a/gl/m4/inttypes_h.m4 +++ /dev/null @@ -1,26 +0,0 @@ -# inttypes_h.m4 serial 6 -dnl Copyright (C) 1997-2004 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Paul Eggert. - -# Define HAVE_INTTYPES_H_WITH_UINTMAX if <inttypes.h> exists, -# doesn't clash with <sys/types.h>, and declares uintmax_t. - -AC_DEFUN([gl_AC_HEADER_INTTYPES_H], -[ - AC_CACHE_CHECK([for inttypes.h], gl_cv_header_inttypes_h, - [AC_TRY_COMPILE( - [#include <sys/types.h> -#include <inttypes.h>], - [uintmax_t i = (uintmax_t) -1;], - gl_cv_header_inttypes_h=yes, - gl_cv_header_inttypes_h=no)]) - if test $gl_cv_header_inttypes_h = yes; then - AC_DEFINE_UNQUOTED(HAVE_INTTYPES_H_WITH_UINTMAX, 1, - [Define if <inttypes.h> exists, doesn't clash with <sys/types.h>, - and declares uintmax_t. ]) - fi -]) diff --git a/gl/m4/longdouble.m4 b/gl/m4/longdouble.m4 index 40cd7ce02..25590f470 100644 --- a/gl/m4/longdouble.m4 +++ b/gl/m4/longdouble.m4 @@ -1,5 +1,5 @@ -# longdouble.m4 serial 1 (gettext-0.12) -dnl Copyright (C) 2002-2003 Free Software Foundation, Inc. +# longdouble.m4 serial 2 (gettext-0.15) +dnl Copyright (C) 2002-2003, 2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -8,6 +8,9 @@ dnl From Bruno Haible. dnl Test whether the compiler supports the 'long double' type. dnl Prerequisite: AC_PROG_CC +dnl This file is only needed in autoconf <= 2.59. Newer versions of autoconf +dnl have a macro AC_TYPE_LONG_DOUBLE with identical semantics. + AC_DEFUN([gt_TYPE_LONGDOUBLE], [ AC_CACHE_CHECK([for long double], gt_cv_c_long_double, diff --git a/gl/m4/longlong.m4 b/gl/m4/longlong.m4 deleted file mode 100644 index 7b399e012..000000000 --- a/gl/m4/longlong.m4 +++ /dev/null @@ -1,23 +0,0 @@ -# longlong.m4 serial 5 -dnl Copyright (C) 1999-2004 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Paul Eggert. - -# Define HAVE_LONG_LONG if 'long long' works. - -AC_DEFUN([gl_AC_TYPE_LONG_LONG], -[ - AC_CACHE_CHECK([for long long], ac_cv_type_long_long, - [AC_TRY_LINK([long long ll = 1LL; int i = 63;], - [long long llmax = (long long) -1; - return ll << i | ll >> i | llmax / ll | llmax % ll;], - ac_cv_type_long_long=yes, - ac_cv_type_long_long=no)]) - if test $ac_cv_type_long_long = yes; then - AC_DEFINE(HAVE_LONG_LONG, 1, - [Define if you have the 'long long' type.]) - fi -]) diff --git a/gl/m4/mkdtemp.m4 b/gl/m4/mkdtemp.m4 index e02c8256c..e39bcb938 100644 --- a/gl/m4/mkdtemp.m4 +++ b/gl/m4/mkdtemp.m4 @@ -1,5 +1,5 @@ -# mkdtemp.m4 serial 3 -dnl Copyright (C) 2001-2003 Free Software Foundation, Inc. +# mkdtemp.m4 serial 4 +dnl Copyright (C) 2001-2003, 2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -18,6 +18,5 @@ AC_DEFUN([gl_PREREQ_MKDTEMP], AC_REQUIRE([AC_HEADER_STAT]) AC_CHECK_HEADERS_ONCE(sys/time.h unistd.h) AC_CHECK_HEADERS(time.h) - AC_REQUIRE([gl_AC_TYPE_UINTMAX_T]) AC_CHECK_FUNCS(gettimeofday) ]) diff --git a/gl/m4/onceonly_2_57.m4 b/gl/m4/onceonly_2_57.m4 deleted file mode 100644 index 9fc510e06..000000000 --- a/gl/m4/onceonly_2_57.m4 +++ /dev/null @@ -1,86 +0,0 @@ -# onceonly_2_57.m4 serial 3 -dnl Copyright (C) 2002-2003 Free Software Foundation, Inc. -dnl This file is free software, distributed under the terms of the GNU -dnl General Public License. As a special exception to the GNU General -dnl Public License, this file may be distributed as part of a program -dnl that contains a configuration script generated by Autoconf, under -dnl the same distribution terms as the rest of that program. - -dnl This file defines some "once only" variants of standard autoconf macros. -dnl AC_CHECK_HEADERS_ONCE like AC_CHECK_HEADERS -dnl AC_CHECK_FUNCS_ONCE like AC_CHECK_FUNCS -dnl AC_CHECK_DECLS_ONCE like AC_CHECK_DECLS -dnl AC_REQUIRE([AC_HEADER_STDC]) like AC_HEADER_STDC -dnl The advantage is that the check for each of the headers/functions/decls -dnl will be put only once into the 'configure' file. It keeps the size of -dnl the 'configure' file down, and avoids redundant output when 'configure' -dnl is run. -dnl The drawback is that the checks cannot be conditionalized. If you write -dnl if some_condition; then gl_CHECK_HEADERS(stdlib.h); fi -dnl inside an AC_DEFUNed function, the gl_CHECK_HEADERS macro call expands to -dnl empty, and the check will be inserted before the body of the AC_DEFUNed -dnl function. - -dnl This is like onceonly.m4, except that it uses diversions to named sections -dnl DEFAULTS and INIT_PREPARE in order to check all requested headers at once, -dnl thus reducing the size of 'configure'. Works with autoconf-2.57. The -dnl size reduction is ca. 9%. - -dnl Autoconf version 2.57 or newer is recommended. -AC_PREREQ(2.54) - -# AC_CHECK_HEADERS_ONCE(HEADER1 HEADER2 ...) is a once-only variant of -# AC_CHECK_HEADERS(HEADER1 HEADER2 ...). -AC_DEFUN([AC_CHECK_HEADERS_ONCE], [ - : - AC_FOREACH([gl_HEADER_NAME], [$1], [ - AC_DEFUN([gl_CHECK_HEADER_]m4_quote(translit(gl_HEADER_NAME, - [./-], [___])), [ - m4_divert_text([INIT_PREPARE], - [gl_header_list="$gl_header_list gl_HEADER_NAME"]) - gl_HEADERS_EXPANSION - AH_TEMPLATE(AS_TR_CPP([HAVE_]m4_defn([gl_HEADER_NAME])), - [Define to 1 if you have the <]m4_defn([gl_HEADER_NAME])[> header file.]) - ]) - AC_REQUIRE([gl_CHECK_HEADER_]m4_quote(translit(gl_HEADER_NAME, - [./-], [___]))) - ]) -]) -m4_define([gl_HEADERS_EXPANSION], [ - m4_divert_text([DEFAULTS], [gl_header_list=]) - AC_CHECK_HEADERS([$gl_header_list]) - m4_define([gl_HEADERS_EXPANSION], []) -]) - -# AC_CHECK_FUNCS_ONCE(FUNC1 FUNC2 ...) is a once-only variant of -# AC_CHECK_FUNCS(FUNC1 FUNC2 ...). -AC_DEFUN([AC_CHECK_FUNCS_ONCE], [ - : - AC_FOREACH([gl_FUNC_NAME], [$1], [ - AC_DEFUN([gl_CHECK_FUNC_]m4_defn([gl_FUNC_NAME]), [ - m4_divert_text([INIT_PREPARE], - [gl_func_list="$gl_func_list gl_FUNC_NAME"]) - gl_FUNCS_EXPANSION - AH_TEMPLATE(AS_TR_CPP([HAVE_]m4_defn([gl_FUNC_NAME])), - [Define to 1 if you have the `]m4_defn([gl_FUNC_NAME])[' function.]) - ]) - AC_REQUIRE([gl_CHECK_FUNC_]m4_defn([gl_FUNC_NAME])) - ]) -]) -m4_define([gl_FUNCS_EXPANSION], [ - m4_divert_text([DEFAULTS], [gl_func_list=]) - AC_CHECK_FUNCS([$gl_func_list]) - m4_define([gl_FUNCS_EXPANSION], []) -]) - -# AC_CHECK_DECLS_ONCE(DECL1 DECL2 ...) is a once-only variant of -# AC_CHECK_DECLS(DECL1, DECL2, ...). -AC_DEFUN([AC_CHECK_DECLS_ONCE], [ - : - AC_FOREACH([gl_DECL_NAME], [$1], [ - AC_DEFUN([gl_CHECK_DECL_]m4_defn([gl_DECL_NAME]), [ - AC_CHECK_DECLS(m4_defn([gl_DECL_NAME])) - ]) - AC_REQUIRE([gl_CHECK_DECL_]m4_defn([gl_DECL_NAME])) - ]) -]) diff --git a/gl/m4/setenv.m4 b/gl/m4/setenv.m4 index 4c76be1ff..623fcf2b5 100644 --- a/gl/m4/setenv.m4 +++ b/gl/m4/setenv.m4 @@ -1,5 +1,5 @@ -# setenv.m4 serial 5 -dnl Copyright (C) 2001-2004 Free Software Foundation, Inc. +# setenv.m4 serial 6 +dnl Copyright (C) 2001-2004, 2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -57,7 +57,6 @@ AC_DEFUN([gl_PREREQ_SETENV], AC_CHECK_HEADERS_ONCE(unistd.h) AC_CHECK_HEADERS(search.h) AC_CHECK_FUNCS(tsearch) - gt_CHECK_VAR_DECL([#include <errno.h>], errno) gt_CHECK_VAR_DECL([#include <unistd.h>], environ) ]) @@ -65,6 +64,5 @@ AC_DEFUN([gl_PREREQ_SETENV], AC_DEFUN([gl_PREREQ_UNSETENV], [ AC_CHECK_HEADERS_ONCE(unistd.h) - gt_CHECK_VAR_DECL([#include <errno.h>], errno) gt_CHECK_VAR_DECL([#include <unistd.h>], environ) ]) diff --git a/gl/m4/signed.m4 b/gl/m4/signed.m4 deleted file mode 100644 index 048f59369..000000000 --- a/gl/m4/signed.m4 +++ /dev/null @@ -1,17 +0,0 @@ -# signed.m4 serial 1 (gettext-0.10.40) -dnl Copyright (C) 2001-2002 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Bruno Haible. - -AC_DEFUN([bh_C_SIGNED], -[ - AC_CACHE_CHECK([for signed], bh_cv_c_signed, - [AC_TRY_COMPILE(, [signed char x;], bh_cv_c_signed=yes, bh_cv_c_signed=no)]) - if test $bh_cv_c_signed = no; then - AC_DEFINE(signed, , - [Define to empty if the C compiler doesn't support this keyword.]) - fi -]) diff --git a/gl/m4/size_max.m4 b/gl/m4/size_max.m4 index 4fe81c7b0..029e47195 100644 --- a/gl/m4/size_max.m4 +++ b/gl/m4/size_max.m4 @@ -1,5 +1,5 @@ -# size_max.m4 serial 2 -dnl Copyright (C) 2003 Free Software Foundation, Inc. +# size_max.m4 serial 4 +dnl Copyright (C) 2003, 2005-2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -23,32 +23,33 @@ Found it ], result=yes) if test -z "$result"; then dnl Define it ourselves. Here we assume that the type 'size_t' is not wider - dnl than the type 'unsigned long'. - dnl The _AC_COMPUTE_INT macro works up to LONG_MAX, since it uses 'expr', - dnl which is guaranteed to work from LONG_MIN to LONG_MAX. - _AC_COMPUTE_INT([~(size_t)0 / 10], res_hi, - [#include <stddef.h>], result=?) - _AC_COMPUTE_INT([~(size_t)0 % 10], res_lo, - [#include <stddef.h>], result=?) + dnl than the type 'unsigned long'. Try hard to find a definition that can + dnl be used in a preprocessor #if, i.e. doesn't contain a cast. + _AC_COMPUTE_INT([sizeof (size_t) * CHAR_BIT - 1], size_t_bits_minus_1, + [#include <stddef.h> +#include <limits.h>], size_t_bits_minus_1=) _AC_COMPUTE_INT([sizeof (size_t) <= sizeof (unsigned int)], fits_in_uint, - [#include <stddef.h>], result=?) - if test "$fits_in_uint" = 1; then - dnl Even though SIZE_MAX fits in an unsigned int, it must be of type - dnl 'unsigned long' if the type 'size_t' is the same as 'unsigned long'. - AC_TRY_COMPILE([#include <stddef.h> - extern size_t foo; - extern unsigned long foo; - ], [], fits_in_uint=0) - fi - if test -z "$result"; then - if test "$fits_in_uint" = 1; then - result="$res_hi$res_lo"U + [#include <stddef.h>], fits_in_uint=) + if test -n "$size_t_bits_minus_1" && test -n "$fits_in_uint"; then + if test $fits_in_uint = 1; then + dnl Even though SIZE_MAX fits in an unsigned int, it must be of type + dnl 'unsigned long' if the type 'size_t' is the same as 'unsigned long'. + AC_TRY_COMPILE([#include <stddef.h> + extern size_t foo; + extern unsigned long foo; + ], [], fits_in_uint=0) + fi + dnl We cannot use 'expr' to simplify this expression, because 'expr' + dnl works only with 'long' integers in the host environment, while we + dnl might be cross-compiling from a 32-bit platform to a 64-bit platform. + if test $fits_in_uint = 1; then + result="(((1U << $size_t_bits_minus_1) - 1) * 2 + 1)" else - result="$res_hi$res_lo"UL + result="(((1UL << $size_t_bits_minus_1) - 1) * 2 + 1)" fi else dnl Shouldn't happen, but who knows... - result='~(size_t)0' + result='((size_t)~(size_t)0)' fi fi AC_MSG_RESULT([$result]) diff --git a/gl/m4/stdint.m4 b/gl/m4/stdint.m4 new file mode 100644 index 000000000..9261def3b --- /dev/null +++ b/gl/m4/stdint.m4 @@ -0,0 +1,368 @@ +# stdint.m4 serial 19 +dnl Copyright (C) 2001-2002, 2004-2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Paul Eggert and Bruno Haible. +dnl Test whether <stdint.h> is supported or must be substituted. + +AC_DEFUN([gl_STDINT_H], +[ + AC_PREREQ(2.59)dnl + + dnl Check for long long int and unsigned long long int. + AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) + if test $ac_cv_type_long_long_int = yes; then + HAVE_LONG_LONG_INT=1 + else + HAVE_LONG_LONG_INT=0 + fi + AC_SUBST([HAVE_LONG_LONG_INT]) + AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT]) + if test $ac_cv_type_unsigned_long_long_int = yes; then + HAVE_UNSIGNED_LONG_LONG_INT=1 + else + HAVE_UNSIGNED_LONG_LONG_INT=0 + fi + AC_SUBST([HAVE_UNSIGNED_LONG_LONG_INT]) + + dnl Check for <wchar.h>. + AC_CHECK_HEADERS_ONCE([wchar.h]) + if test $ac_cv_header_wchar_h = yes; then + HAVE_WCHAR_H=1 + else + HAVE_WCHAR_H=0 + fi + AC_SUBST([HAVE_WCHAR_H]) + + dnl Check for <inttypes.h>. + dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_inttypes_h. + if test $ac_cv_header_inttypes_h = yes; then + HAVE_INTTYPES_H=1 + else + HAVE_INTTYPES_H=0 + fi + AC_SUBST([HAVE_INTTYPES_H]) + + dnl Check for <sys/types.h>. + dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_sys_types_h. + if test $ac_cv_header_sys_types_h = yes; then + HAVE_SYS_TYPES_H=1 + else + HAVE_SYS_TYPES_H=0 + fi + AC_SUBST([HAVE_SYS_TYPES_H]) + + dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_stdint_h. + if test $ac_cv_header_stdint_h = yes; then + gl_ABSOLUTE_HEADER([stdint.h]) + ABSOLUTE_STDINT_H=\"$gl_cv_absolute_stdint_h\" + HAVE_STDINT_H=1 + else + ABSOLUTE_STDINT_H=\"no/such/file/stdint.h\" + HAVE_STDINT_H=0 + fi + AC_SUBST([ABSOLUTE_STDINT_H]) + AC_SUBST([HAVE_STDINT_H]) + + dnl Now see whether we need a substitute <stdint.h>. Use + dnl ABSOLUTE_STDINT_H, not <stdint.h>, so that it also works during + dnl a "config.status --recheck" if a stdint.h has been + dnl created in the build directory. + if test $ac_cv_header_stdint_h = yes; then + AC_CACHE_CHECK([whether stdint.h conforms to C99], + [gl_cv_header_working_stdint_h], + [gl_cv_header_working_stdint_h=no + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([[ +#include <stddef.h> +#define __STDC_LIMIT_MACROS 1 /* to make it work also in C++ mode */ +#define __STDC_CONSTANT_MACROS 1 /* to make it work also in C++ mode */ +#include ABSOLUTE_STDINT_H +#ifdef INT8_MAX +int8_t a1 = INT8_MAX; +int8_t a1min = INT8_MIN; +#endif +#ifdef INT16_MAX +int16_t a2 = INT16_MAX; +int16_t a2min = INT16_MIN; +#endif +#ifdef INT32_MAX +int32_t a3 = INT32_MAX; +int32_t a3min = INT32_MIN; +#endif +#ifdef INT64_MAX +int64_t a4 = INT64_MAX; +int64_t a4min = INT64_MIN; +#endif +#ifdef UINT8_MAX +uint8_t b1 = UINT8_MAX; +#else +typedef int b1[(unsigned char) -1 != 255 ? 1 : -1]; +#endif +#ifdef UINT16_MAX +uint16_t b2 = UINT16_MAX; +#endif +#ifdef UINT32_MAX +uint32_t b3 = UINT32_MAX; +#endif +#ifdef UINT64_MAX +uint64_t b4 = UINT64_MAX; +#endif +int_least8_t c1 = INT8_C (0x7f); +int_least8_t c1max = INT_LEAST8_MAX; +int_least8_t c1min = INT_LEAST8_MIN; +int_least16_t c2 = INT16_C (0x7fff); +int_least16_t c2max = INT_LEAST16_MAX; +int_least16_t c2min = INT_LEAST16_MIN; +int_least32_t c3 = INT32_C (0x7fffffff); +int_least32_t c3max = INT_LEAST32_MAX; +int_least32_t c3min = INT_LEAST32_MIN; +int_least64_t c4 = INT64_C (0x7fffffffffffffff); +int_least64_t c4max = INT_LEAST64_MAX; +int_least64_t c4min = INT_LEAST64_MIN; +uint_least8_t d1 = UINT8_C (0xff); +uint_least8_t d1max = UINT_LEAST8_MAX; +uint_least16_t d2 = UINT16_C (0xffff); +uint_least16_t d2max = UINT_LEAST16_MAX; +uint_least32_t d3 = UINT32_C (0xffffffff); +uint_least32_t d3max = UINT_LEAST32_MAX; +uint_least64_t d4 = UINT64_C (0xffffffffffffffff); +uint_least64_t d4max = UINT_LEAST64_MAX; +int_fast8_t e1 = INT_FAST8_MAX; +int_fast8_t e1min = INT_FAST8_MIN; +int_fast16_t e2 = INT_FAST16_MAX; +int_fast16_t e2min = INT_FAST16_MIN; +int_fast32_t e3 = INT_FAST32_MAX; +int_fast32_t e3min = INT_FAST32_MIN; +int_fast64_t e4 = INT_FAST64_MAX; +int_fast64_t e4min = INT_FAST64_MIN; +uint_fast8_t f1 = UINT_FAST8_MAX; +uint_fast16_t f2 = UINT_FAST16_MAX; +uint_fast32_t f3 = UINT_FAST32_MAX; +uint_fast64_t f4 = UINT_FAST64_MAX; +#ifdef INTPTR_MAX +intptr_t g = INTPTR_MAX; +intptr_t gmin = INTPTR_MIN; +#endif +#ifdef UINTPTR_MAX +uintptr_t h = UINTPTR_MAX; +#endif +intmax_t i = INTMAX_MAX; +uintmax_t j = UINTMAX_MAX; +struct s { + int check_PTRDIFF: PTRDIFF_MIN < 0 && 0 < PTRDIFF_MAX ? 1 : -1; + int check_SIG_ATOMIC: SIG_ATOMIC_MIN <= 0 && 0 < SIG_ATOMIC_MAX ? 1 : -1; + int check_SIZE: 0 < SIZE_MAX ? 1 : -1; + int check_WCHAR: WCHAR_MIN <= 0 && 0 < WCHAR_MAX ? 1 : -1; + int check_WINT: WINT_MIN <= 0 && 0 < WINT_MAX ? 1 : -1; + + /* Detect bugs in glibc 2.4 and Solaris 10 stdint.h, among others. */ + int check_UINT8_C: + (-1 < UINT8_C (0)) == (-1 < (uint_least8_t) 0) ? 1 : -1; + int check_UINT16_C: + (-1 < UINT16_C (0)) == (-1 < (uint_least16_t) 0) ? 1 : -1; + + /* Detect bugs in OpenBSD 3.9 stdint.h. */ +#ifdef UINT8_MAX + int check_uint8: (uint8_t) -1 == UINT8_MAX ? 1 : -1; +#endif +#ifdef UINT16_MAX + int check_uint16: (uint16_t) -1 == UINT16_MAX ? 1 : -1; +#endif +#ifdef UINT32_MAX + int check_uint32: (uint32_t) -1 == UINT32_MAX ? 1 : -1; +#endif +#ifdef UINT64_MAX + int check_uint64: (uint64_t) -1 == UINT64_MAX ? 1 : -1; +#endif + int check_uint_least8: (uint_least8_t) -1 == UINT_LEAST8_MAX ? 1 : -1; + int check_uint_least16: (uint_least16_t) -1 == UINT_LEAST16_MAX ? 1 : -1; + int check_uint_least32: (uint_least32_t) -1 == UINT_LEAST32_MAX ? 1 : -1; + int check_uint_least64: (uint_least64_t) -1 == UINT_LEAST64_MAX ? 1 : -1; + int check_uint_fast8: (uint_fast8_t) -1 == UINT_FAST8_MAX ? 1 : -1; + int check_uint_fast16: (uint_fast16_t) -1 == UINT_FAST16_MAX ? 1 : -1; + int check_uint_fast32: (uint_fast32_t) -1 == UINT_FAST32_MAX ? 1 : -1; + int check_uint_fast64: (uint_fast64_t) -1 == UINT_FAST64_MAX ? 1 : -1; + int check_uintptr: (uintptr_t) -1 == UINTPTR_MAX ? 1 : -1; + int check_uintmax: (uintmax_t) -1 == UINTMAX_MAX ? 1 : -1; + int check_size: (size_t) -1 == SIZE_MAX ? 1 : -1; +}; + ]])], + [gl_cv_header_working_stdint_h=yes])]) + fi + if test "$gl_cv_header_working_stdint_h" != yes; then + + dnl Check for <sys/inttypes.h>, and for + dnl <sys/bitypes.h> (used in Linux libc4 >= 4.6.7 and libc5). + AC_CHECK_HEADERS([sys/inttypes.h sys/bitypes.h]) + if test $ac_cv_header_sys_inttypes_h = yes; then + HAVE_SYS_INTTYPES_H=1 + else + HAVE_SYS_INTTYPES_H=0 + fi + AC_SUBST([HAVE_SYS_INTTYPES_H]) + if test $ac_cv_header_sys_bitypes_h = yes; then + HAVE_SYS_BITYPES_H=1 + else + HAVE_SYS_BITYPES_H=0 + fi + AC_SUBST([HAVE_SYS_BITYPES_H]) + + gl_STDINT_TYPE_PROPERTIES + STDINT_H=stdint.h + fi + AC_SUBST(STDINT_H) +]) + +dnl gl_STDINT_BITSIZEOF(TYPES, INCLUDES) +dnl Determine the size of each of the given types in bits. +AC_DEFUN([gl_STDINT_BITSIZEOF], +[ + dnl Use a shell loop, to avoid bloating configure, and + dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into + dnl config.h.in, + dnl - extra AC_SUBST calls, so that the right substitutions are made. + AC_FOREACH([gltype], [$1], + [AH_TEMPLATE([BITSIZEOF_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]), + [Define to the number of bits in type ']gltype['.])]) + for gltype in $1 ; do + AC_CACHE_CHECK([for bit size of $gltype], [gl_cv_bitsizeof_${gltype}], + [_AC_COMPUTE_INT([sizeof ($gltype) * CHAR_BIT], result, + [$2 +#include <limits.h>], [result=unknown]) + eval gl_cv_bitsizeof_${gltype}=\$result + ]) + eval result=\$gl_cv_bitsizeof_${gltype} + if test $result = unknown; then + dnl Use a nonempty default, because some compilers, such as IRIX 5 cc, + dnl do a syntax check even on unused #if conditions and give an error + dnl on valid C code like this: + dnl #if 0 + dnl # if > 32 + dnl # endif + dnl #endif + result=0 + fi + GLTYPE=`echo "$gltype" | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'` + AC_DEFINE_UNQUOTED([BITSIZEOF_${GLTYPE}], [$result]) + eval BITSIZEOF_${GLTYPE}=\$result + done + AC_FOREACH([gltype], [$1], + [AC_SUBST([BITSIZEOF_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))]) +]) + +dnl gl_CHECK_TYPES_SIGNED(TYPES, INCLUDES) +dnl Determine the signedness of each of the given types. +dnl Define HAVE_SIGNED_TYPE if type is signed. +AC_DEFUN([gl_CHECK_TYPES_SIGNED], +[ + dnl Use a shell loop, to avoid bloating configure, and + dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into + dnl config.h.in, + dnl - extra AC_SUBST calls, so that the right substitutions are made. + AC_FOREACH([gltype], [$1], + [AH_TEMPLATE([HAVE_SIGNED_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]), + [Define to 1 if ']gltype[' is a signed integer type.])]) + for gltype in $1 ; do + AC_CACHE_CHECK([whether $gltype is signed], [gl_cv_type_${gltype}_signed], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([$2[ + int verify[2 * (($gltype) -1 < ($gltype) 0) - 1];]])], + result=yes, result=no) + eval gl_cv_type_${gltype}_signed=\$result + ]) + eval result=\$gl_cv_type_${gltype}_signed + GLTYPE=`echo $gltype | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'` + if test "$result" = yes; then + AC_DEFINE_UNQUOTED([HAVE_SIGNED_${GLTYPE}], 1) + eval HAVE_SIGNED_${GLTYPE}=1 + else + eval HAVE_SIGNED_${GLTYPE}=0 + fi + done + AC_FOREACH([gltype], [$1], + [AC_SUBST([HAVE_SIGNED_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))]) +]) + +dnl gl_INTEGER_TYPE_SUFFIX(TYPES, INCLUDES) +dnl Determine the suffix to use for integer constants of the given types. +dnl Define t_SUFFIX for each such type. +AC_DEFUN([gl_INTEGER_TYPE_SUFFIX], +[ + dnl Use a shell loop, to avoid bloating configure, and + dnl - extra AH_TEMPLATE calls, so that autoheader knows what to put into + dnl config.h.in, + dnl - extra AC_SUBST calls, so that the right substitutions are made. + AC_FOREACH([gltype], [$1], + [AH_TEMPLATE(translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_])[_SUFFIX], + [Define to l, ll, u, ul, ull, etc., as suitable for + constants of type ']gltype['.])]) + for gltype in $1 ; do + AC_CACHE_CHECK([for $gltype integer literal suffix], + [gl_cv_type_${gltype}_suffix], + [eval gl_cv_type_${gltype}_suffix=no + eval result=\$gl_cv_type_${gltype}_signed + if test "$result" = yes; then + glsufu= + else + glsufu=u + fi + for glsuf in "$glsufu" ${glsufu}l ${glsufu}ll ${glsufu}i64; do + case $glsuf in + '') gltype1='int';; + l) gltype1='long int';; + ll) gltype1='long long int';; + i64) gltype1='__int64';; + u) gltype1='unsigned int';; + ul) gltype1='unsigned long int';; + ull) gltype1='unsigned long long int';; + ui64)gltype1='unsigned __int64';; + esac + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([$2 + extern $gltype foo; + extern $gltype1 foo;])], + [eval gl_cv_type_${gltype}_suffix=\$glsuf]) + eval result=\$gl_cv_type_${gltype}_suffix + test "$result" != no && break + done]) + GLTYPE=`echo $gltype | tr 'abcdefghijklmnopqrstuvwxyz ' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'` + eval result=\$gl_cv_type_${gltype}_suffix + test "$result" = no && result= + eval ${GLTYPE}_SUFFIX=\$result + AC_DEFINE_UNQUOTED([${GLTYPE}_SUFFIX], $result) + done + AC_FOREACH([gltype], [$1], + [AC_SUBST(translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_])[_SUFFIX])]) +]) + +dnl gl_STDINT_INCLUDES +AC_DEFUN([gl_STDINT_INCLUDES], +[[ + #include <stddef.h> + #include <signal.h> + #if HAVE_WCHAR_H + /* BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before + <wchar.h>. */ + # include <stdio.h> + # include <time.h> + # include <wchar.h> + #endif +]]) + +dnl gl_STDINT_TYPE_PROPERTIES +dnl Compute HAVE_SIGNED_t, BITSIZEOF_t and t_SUFFIX, for all the types t +dnl of interest to stdint_.h. +AC_DEFUN([gl_STDINT_TYPE_PROPERTIES], +[ + gl_STDINT_BITSIZEOF([ptrdiff_t sig_atomic_t size_t wchar_t wint_t], + [gl_STDINT_INCLUDES]) + gl_CHECK_TYPES_SIGNED([sig_atomic_t wchar_t wint_t], + [gl_STDINT_INCLUDES]) + gl_cv_type_ptrdiff_t_signed=yes + gl_cv_type_size_t_signed=no + gl_INTEGER_TYPE_SUFFIX([ptrdiff_t sig_atomic_t size_t wchar_t wint_t], + [gl_STDINT_INCLUDES]) +]) diff --git a/gl/m4/stdint_h.m4 b/gl/m4/stdint_h.m4 deleted file mode 100644 index 3355f35aa..000000000 --- a/gl/m4/stdint_h.m4 +++ /dev/null @@ -1,26 +0,0 @@ -# stdint_h.m4 serial 5 -dnl Copyright (C) 1997-2004 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Paul Eggert. - -# Define HAVE_STDINT_H_WITH_UINTMAX if <stdint.h> exists, -# doesn't clash with <sys/types.h>, and declares uintmax_t. - -AC_DEFUN([gl_AC_HEADER_STDINT_H], -[ - AC_CACHE_CHECK([for stdint.h], gl_cv_header_stdint_h, - [AC_TRY_COMPILE( - [#include <sys/types.h> -#include <stdint.h>], - [uintmax_t i = (uintmax_t) -1;], - gl_cv_header_stdint_h=yes, - gl_cv_header_stdint_h=no)]) - if test $gl_cv_header_stdint_h = yes; then - AC_DEFINE_UNQUOTED(HAVE_STDINT_H_WITH_UINTMAX, 1, - [Define if <stdint.h> exists, doesn't clash with <sys/types.h>, - and declares uintmax_t. ]) - fi -]) diff --git a/gl/m4/strpbrk.m4 b/gl/m4/strpbrk.m4 new file mode 100644 index 000000000..68360684e --- /dev/null +++ b/gl/m4/strpbrk.m4 @@ -0,0 +1,16 @@ +# strpbrk.m4 serial 2 +dnl Copyright (C) 2002-2003 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_STRPBRK], +[ + AC_REPLACE_FUNCS(strpbrk) + if test $ac_cv_func_strpbrk = no; then + gl_PREREQ_STRPBRK + fi +]) + +# Prerequisites of lib/strpbrk.c. +AC_DEFUN([gl_PREREQ_STRPBRK], [:]) diff --git a/gl/m4/uintmax_t.m4 b/gl/m4/uintmax_t.m4 deleted file mode 100644 index bf83ed746..000000000 --- a/gl/m4/uintmax_t.m4 +++ /dev/null @@ -1,30 +0,0 @@ -# uintmax_t.m4 serial 9 -dnl Copyright (C) 1997-2004 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Paul Eggert. - -AC_PREREQ(2.13) - -# Define uintmax_t to 'unsigned long' or 'unsigned long long' -# if it is not already defined in <stdint.h> or <inttypes.h>. - -AC_DEFUN([gl_AC_TYPE_UINTMAX_T], -[ - AC_REQUIRE([gl_AC_HEADER_INTTYPES_H]) - AC_REQUIRE([gl_AC_HEADER_STDINT_H]) - if test $gl_cv_header_inttypes_h = no && test $gl_cv_header_stdint_h = no; then - AC_REQUIRE([gl_AC_TYPE_UNSIGNED_LONG_LONG]) - test $ac_cv_type_unsigned_long_long = yes \ - && ac_type='unsigned long long' \ - || ac_type='unsigned long' - AC_DEFINE_UNQUOTED(uintmax_t, $ac_type, - [Define to unsigned long or unsigned long long - if <stdint.h> and <inttypes.h> don't define.]) - else - AC_DEFINE(HAVE_UINTMAX_T, 1, - [Define if you have the 'uintmax_t' type in <stdint.h> or <inttypes.h>.]) - fi -]) diff --git a/gl/m4/ulonglong.m4 b/gl/m4/ulonglong.m4 deleted file mode 100644 index dee10ccc3..000000000 --- a/gl/m4/ulonglong.m4 +++ /dev/null @@ -1,23 +0,0 @@ -# ulonglong.m4 serial 4 -dnl Copyright (C) 1999-2004 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Paul Eggert. - -# Define HAVE_UNSIGNED_LONG_LONG if 'unsigned long long' works. - -AC_DEFUN([gl_AC_TYPE_UNSIGNED_LONG_LONG], -[ - AC_CACHE_CHECK([for unsigned long long], ac_cv_type_unsigned_long_long, - [AC_TRY_LINK([unsigned long long ull = 1ULL; int i = 63;], - [unsigned long long ullmax = (unsigned long long) -1; - return ull << i | ull >> i | ullmax / ull | ullmax % ull;], - ac_cv_type_unsigned_long_long=yes, - ac_cv_type_unsigned_long_long=no)]) - if test $ac_cv_type_unsigned_long_long = yes; then - AC_DEFINE(HAVE_UNSIGNED_LONG_LONG, 1, - [Define if you have the 'unsigned long long' type.]) - fi -]) diff --git a/gl/m4/unistd_h.m4 b/gl/m4/unistd_h.m4 new file mode 100644 index 000000000..9c77f9bd0 --- /dev/null +++ b/gl/m4/unistd_h.m4 @@ -0,0 +1,18 @@ +# unistd_h.m4 serial 2 +dnl Copyright (C) 2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Written by Simon Josefsson + +AC_DEFUN([gl_HEADER_UNISTD], +[ + dnl Prerequisites of lib/unistd.h. + AC_CHECK_HEADERS([unistd.h], [ + UNISTD_H='' + ], [ + UNISTD_H='unistd.h' + ]) + AC_SUBST(UNISTD_H) +]) diff --git a/gl/m4/vasnprintf.m4 b/gl/m4/vasnprintf.m4 deleted file mode 100644 index 7ff343035..000000000 --- a/gl/m4/vasnprintf.m4 +++ /dev/null @@ -1,58 +0,0 @@ -# vasnprintf.m4 serial 5 -dnl Copyright (C) 2002-2004 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_FUNC_VASNPRINTF], -[ - AC_REQUIRE([gl_EOVERFLOW]) - AC_REPLACE_FUNCS(vasnprintf) - if test $ac_cv_func_vasnprintf = no; then - AC_LIBOBJ(printf-args) - AC_LIBOBJ(printf-parse) - AC_LIBOBJ(asnprintf) - gl_PREREQ_PRINTF_ARGS - gl_PREREQ_PRINTF_PARSE - gl_PREREQ_VASNPRINTF - gl_PREREQ_ASNPRINTF - fi -]) - -# Prequisites of lib/printf-args.h, lib/printf-args.c. -AC_DEFUN([gl_PREREQ_PRINTF_ARGS], -[ - AC_REQUIRE([bh_C_SIGNED]) - AC_REQUIRE([gl_AC_TYPE_LONG_LONG]) - AC_REQUIRE([gt_TYPE_LONGDOUBLE]) - AC_REQUIRE([gt_TYPE_WCHAR_T]) - AC_REQUIRE([gt_TYPE_WINT_T]) -]) - -# Prequisites of lib/printf-parse.h, lib/printf-parse.c. -AC_DEFUN([gl_PREREQ_PRINTF_PARSE], -[ - AC_REQUIRE([gl_AC_TYPE_LONG_LONG]) - AC_REQUIRE([gt_TYPE_LONGDOUBLE]) - AC_REQUIRE([gt_TYPE_WCHAR_T]) - AC_REQUIRE([gt_TYPE_WINT_T]) - AC_REQUIRE([AC_TYPE_SIZE_T]) - AC_CHECK_TYPES(ptrdiff_t) - AC_REQUIRE([gt_AC_TYPE_INTMAX_T]) -]) - -# Prerequisites of lib/vasnprintf.c. -AC_DEFUN([gl_PREREQ_VASNPRINTF], -[ - AC_REQUIRE([AC_FUNC_ALLOCA]) - AC_REQUIRE([gl_AC_TYPE_LONG_LONG]) - AC_REQUIRE([gt_TYPE_LONGDOUBLE]) - AC_REQUIRE([gt_TYPE_WCHAR_T]) - AC_REQUIRE([gt_TYPE_WINT_T]) - AC_CHECK_FUNCS(snprintf wcslen) -]) - -# Prerequisites of lib/asnprintf.c. -AC_DEFUN([gl_PREREQ_ASNPRINTF], -[ -]) diff --git a/gl/m4/vasprintf.m4 b/gl/m4/vasprintf.m4 deleted file mode 100644 index 385e92edd..000000000 --- a/gl/m4/vasprintf.m4 +++ /dev/null @@ -1,25 +0,0 @@ -# vasprintf.m4 serial 1 -dnl Copyright (C) 2002-2003 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_FUNC_VASPRINTF], -[ - AC_REPLACE_FUNCS(vasprintf) - if test $ac_cv_func_vasprintf = no; then - AC_LIBOBJ(asprintf) - gl_PREREQ_VASPRINTF - gl_PREREQ_ASPRINTF - fi -]) - -# Prerequisites of lib/vasprintf.c. -AC_DEFUN([gl_PREREQ_VASPRINTF], -[ -]) - -# Prerequisites of lib/asprintf.c. -AC_DEFUN([gl_PREREQ_ASPRINTF], -[ -]) diff --git a/gl/m4/wchar_t.m4 b/gl/m4/wchar_t.m4 deleted file mode 100644 index cde2129a9..000000000 --- a/gl/m4/wchar_t.m4 +++ /dev/null @@ -1,20 +0,0 @@ -# wchar_t.m4 serial 1 (gettext-0.12) -dnl Copyright (C) 2002-2003 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Bruno Haible. -dnl Test whether <stddef.h> has the 'wchar_t' type. -dnl Prerequisite: AC_PROG_CC - -AC_DEFUN([gt_TYPE_WCHAR_T], -[ - AC_CACHE_CHECK([for wchar_t], gt_cv_c_wchar_t, - [AC_TRY_COMPILE([#include <stddef.h> - wchar_t foo = (wchar_t)'\0';], , - gt_cv_c_wchar_t=yes, gt_cv_c_wchar_t=no)]) - if test $gt_cv_c_wchar_t = yes; then - AC_DEFINE(HAVE_WCHAR_T, 1, [Define if you have the 'wchar_t' type.]) - fi -]) diff --git a/gl/m4/wint_t.m4 b/gl/m4/wint_t.m4 deleted file mode 100644 index b8fff9c86..000000000 --- a/gl/m4/wint_t.m4 +++ /dev/null @@ -1,20 +0,0 @@ -# wint_t.m4 serial 1 (gettext-0.12) -dnl Copyright (C) 2003 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Bruno Haible. -dnl Test whether <wchar.h> has the 'wint_t' type. -dnl Prerequisite: AC_PROG_CC - -AC_DEFUN([gt_TYPE_WINT_T], -[ - AC_CACHE_CHECK([for wint_t], gt_cv_c_wint_t, - [AC_TRY_COMPILE([#include <wchar.h> - wint_t foo = (wchar_t)'\0';], , - gt_cv_c_wint_t=yes, gt_cv_c_wint_t=no)]) - if test $gt_cv_c_wint_t = yes; then - AC_DEFINE(HAVE_WINT_T, 1, [Define if you have the 'wint_t' type.]) - fi -]) diff --git a/gl/mkdtemp.c b/gl/mkdtemp.c index 469cf4718..60bbd0aa4 100644 --- a/gl/mkdtemp.c +++ b/gl/mkdtemp.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1999, 2001-2003 Free Software Foundation, Inc. +/* Copyright (C) 1999, 2001-2003, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. This program is free software; you can redistribute it and/or modify @@ -17,9 +17,7 @@ /* Extracted from misc/mkdtemp.c and sysdeps/posix/tempname.c. */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif +#include <config.h> /* Specification. */ #include "mkdtemp.h" @@ -30,6 +28,7 @@ #endif #include <stddef.h> +#include <stdint.h> #include <stdlib.h> #include <string.h> @@ -38,16 +37,7 @@ # define TMP_MAX 238328 #endif -#if HAVE_STDINT_H || _LIBC -# include <stdint.h> -#endif -#if HAVE_INTTYPES_H -# include <inttypes.h> -#endif - -#if HAVE_UNISTD_H || _LIBC -# include <unistd.h> -#endif +#include <unistd.h> #if HAVE_GETTIMEOFDAY || _LIBC # if HAVE_SYS_TIME_H || _LIBC @@ -60,9 +50,6 @@ #endif #include <sys/stat.h> -#if STAT_MACROS_BROKEN -# undef S_ISDIR -#endif #if !defined S_ISDIR && defined S_IFDIR # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) #endif @@ -86,9 +73,10 @@ #endif #ifdef __MINGW32__ -/* mingw's mkdir() function has 1 argument, but we pass 2 arguments. +# include <io.h> +/* mingw's _mkdir() function has 1 argument, but we pass 2 arguments. Therefore we have to disable the argument count checking. */ -# define mkdir ((int (*)()) mkdir) +# define mkdir ((int (*)()) _mkdir) #endif #if !_LIBC @@ -126,9 +114,26 @@ gen_tempname (char *tmpl) char *XXXXXX; static uint64_t value; uint64_t random_time_bits; - int count, fd = -1; + unsigned int count; + int fd = -1; int save_errno = errno; + /* A lower bound on the number of temporary files to attempt to + generate. The maximum total number of temporary file names that + can exist for a given template is 62**6. It should never be + necessary to try all these combinations. Instead if a reasonable + number of names is tried (we define reasonable as 62**3) fail to + give the system administrator the chance to remove the problems. */ +#define ATTEMPTS_MIN (62 * 62 * 62) + + /* The number of times to attempt to generate a temporary file. To + conform to POSIX, this must be no smaller than TMP_MAX. */ +#if ATTEMPTS_MIN < TMP_MAX + unsigned int attempts = TMP_MAX; +#else + unsigned int attempts = ATTEMPTS_MIN; +#endif + len = strlen (tmpl); if (len < 6 || strcmp (&tmpl[len - 6], "XXXXXX")) { @@ -155,7 +160,7 @@ gen_tempname (char *tmpl) #endif value += random_time_bits ^ __getpid (); - for (count = 0; count < TMP_MAX; value += 7777, ++count) + for (count = 0; count < attempts; value += 7777, ++count) { uint64_t v = value; diff --git a/gl/printf-args.c b/gl/printf-args.c deleted file mode 100644 index 0ed1acbb8..000000000 --- a/gl/printf-args.c +++ /dev/null @@ -1,118 +0,0 @@ -/* Decomposed printf argument list. - Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc. - - This program 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, or (at your option) - any later version. - - This program 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -/* Specification. */ -#include "printf-args.h" - -#ifdef STATIC -STATIC -#endif -int -printf_fetchargs (va_list args, arguments *a) -{ - size_t i; - argument *ap; - - for (i = 0, ap = &a->arg[0]; i < a->count; i++, ap++) - switch (ap->type) - { - case TYPE_SCHAR: - ap->a.a_schar = va_arg (args, /*signed char*/ int); - break; - case TYPE_UCHAR: - ap->a.a_uchar = va_arg (args, /*unsigned char*/ int); - break; - case TYPE_SHORT: - ap->a.a_short = va_arg (args, /*short*/ int); - break; - case TYPE_USHORT: - ap->a.a_ushort = va_arg (args, /*unsigned short*/ int); - break; - case TYPE_INT: - ap->a.a_int = va_arg (args, int); - break; - case TYPE_UINT: - ap->a.a_uint = va_arg (args, unsigned int); - break; - case TYPE_LONGINT: - ap->a.a_longint = va_arg (args, long int); - break; - case TYPE_ULONGINT: - ap->a.a_ulongint = va_arg (args, unsigned long int); - break; -#ifdef HAVE_LONG_LONG - case TYPE_LONGLONGINT: - ap->a.a_longlongint = va_arg (args, long long int); - break; - case TYPE_ULONGLONGINT: - ap->a.a_ulonglongint = va_arg (args, unsigned long long int); - break; -#endif - case TYPE_DOUBLE: - ap->a.a_double = va_arg (args, double); - break; -#ifdef HAVE_LONG_DOUBLE - case TYPE_LONGDOUBLE: - ap->a.a_longdouble = va_arg (args, long double); - break; -#endif - case TYPE_CHAR: - ap->a.a_char = va_arg (args, int); - break; -#ifdef HAVE_WINT_T - case TYPE_WIDE_CHAR: - ap->a.a_wide_char = va_arg (args, wint_t); - break; -#endif - case TYPE_STRING: - ap->a.a_string = va_arg (args, const char *); - break; -#ifdef HAVE_WCHAR_T - case TYPE_WIDE_STRING: - ap->a.a_wide_string = va_arg (args, const wchar_t *); - break; -#endif - case TYPE_POINTER: - ap->a.a_pointer = va_arg (args, void *); - break; - case TYPE_COUNT_SCHAR_POINTER: - ap->a.a_count_schar_pointer = va_arg (args, signed char *); - break; - case TYPE_COUNT_SHORT_POINTER: - ap->a.a_count_short_pointer = va_arg (args, short *); - break; - case TYPE_COUNT_INT_POINTER: - ap->a.a_count_int_pointer = va_arg (args, int *); - break; - case TYPE_COUNT_LONGINT_POINTER: - ap->a.a_count_longint_pointer = va_arg (args, long int *); - break; -#ifdef HAVE_LONG_LONG - case TYPE_COUNT_LONGLONGINT_POINTER: - ap->a.a_count_longlongint_pointer = va_arg (args, long long int *); - break; -#endif - default: - /* Unknown type. */ - return -1; - } - return 0; -} diff --git a/gl/printf-args.h b/gl/printf-args.h deleted file mode 100644 index cec1cc6c2..000000000 --- a/gl/printf-args.h +++ /dev/null @@ -1,136 +0,0 @@ -/* Decomposed printf argument list. - Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc. - - This program 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, or (at your option) - any later version. - - This program 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef _PRINTF_ARGS_H -#define _PRINTF_ARGS_H - -/* Get size_t. */ -#include <stddef.h> - -/* Get wchar_t. */ -#ifdef HAVE_WCHAR_T -# include <stddef.h> -#endif - -/* Get wint_t. */ -#ifdef HAVE_WINT_T -# include <wchar.h> -#endif - -/* Get va_list. */ -#include <stdarg.h> - - -/* Argument types */ -typedef enum -{ - TYPE_NONE, - TYPE_SCHAR, - TYPE_UCHAR, - TYPE_SHORT, - TYPE_USHORT, - TYPE_INT, - TYPE_UINT, - TYPE_LONGINT, - TYPE_ULONGINT, -#ifdef HAVE_LONG_LONG - TYPE_LONGLONGINT, - TYPE_ULONGLONGINT, -#endif - TYPE_DOUBLE, -#ifdef HAVE_LONG_DOUBLE - TYPE_LONGDOUBLE, -#endif - TYPE_CHAR, -#ifdef HAVE_WINT_T - TYPE_WIDE_CHAR, -#endif - TYPE_STRING, -#ifdef HAVE_WCHAR_T - TYPE_WIDE_STRING, -#endif - TYPE_POINTER, - TYPE_COUNT_SCHAR_POINTER, - TYPE_COUNT_SHORT_POINTER, - TYPE_COUNT_INT_POINTER, - TYPE_COUNT_LONGINT_POINTER -#ifdef HAVE_LONG_LONG -, TYPE_COUNT_LONGLONGINT_POINTER -#endif -} arg_type; - -/* Polymorphic argument */ -typedef struct -{ - arg_type type; - union - { - signed char a_schar; - unsigned char a_uchar; - short a_short; - unsigned short a_ushort; - int a_int; - unsigned int a_uint; - long int a_longint; - unsigned long int a_ulongint; -#ifdef HAVE_LONG_LONG - long long int a_longlongint; - unsigned long long int a_ulonglongint; -#endif - float a_float; - double a_double; -#ifdef HAVE_LONG_DOUBLE - long double a_longdouble; -#endif - int a_char; -#ifdef HAVE_WINT_T - wint_t a_wide_char; -#endif - const char* a_string; -#ifdef HAVE_WCHAR_T - const wchar_t* a_wide_string; -#endif - void* a_pointer; - signed char * a_count_schar_pointer; - short * a_count_short_pointer; - int * a_count_int_pointer; - long int * a_count_longint_pointer; -#ifdef HAVE_LONG_LONG - long long int * a_count_longlongint_pointer; -#endif - } - a; -} -argument; - -typedef struct -{ - size_t count; - argument *arg; -} -arguments; - - -/* Fetch the arguments, putting them into a. */ -#ifdef STATIC -STATIC -#else -extern -#endif -int printf_fetchargs (va_list args, arguments *a); - -#endif /* _PRINTF_ARGS_H */ diff --git a/gl/printf-parse.c b/gl/printf-parse.c deleted file mode 100644 index 3d2fb175f..000000000 --- a/gl/printf-parse.c +++ /dev/null @@ -1,536 +0,0 @@ -/* Formatted output to strings. - Copyright (C) 1999-2000, 2002-2003 Free Software Foundation, Inc. - - This program 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, or (at your option) - any later version. - - This program 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -/* Specification. */ -#if WIDE_CHAR_VERSION -# include "wprintf-parse.h" -#else -# include "printf-parse.h" -#endif - -/* Get size_t, NULL. */ -#include <stddef.h> - -/* Get intmax_t. */ -#if HAVE_STDINT_H_WITH_UINTMAX -# include <stdint.h> -#endif -#if HAVE_INTTYPES_H_WITH_UINTMAX -# include <inttypes.h> -#endif - -/* malloc(), realloc(), free(). */ -#include <stdlib.h> - -/* Checked size_t computations. */ -#include "xsize.h" - -#if WIDE_CHAR_VERSION -# define PRINTF_PARSE wprintf_parse -# define CHAR_T wchar_t -# define DIRECTIVE wchar_t_directive -# define DIRECTIVES wchar_t_directives -#else -# define PRINTF_PARSE printf_parse -# define CHAR_T char -# define DIRECTIVE char_directive -# define DIRECTIVES char_directives -#endif - -#ifdef STATIC -STATIC -#endif -int -PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) -{ - const CHAR_T *cp = format; /* pointer into format */ - size_t arg_posn = 0; /* number of regular arguments consumed */ - size_t d_allocated; /* allocated elements of d->dir */ - size_t a_allocated; /* allocated elements of a->arg */ - size_t max_width_length = 0; - size_t max_precision_length = 0; - - d->count = 0; - d_allocated = 1; - d->dir = malloc (d_allocated * sizeof (DIRECTIVE)); - if (d->dir == NULL) - /* Out of memory. */ - return -1; - - a->count = 0; - a_allocated = 0; - a->arg = NULL; - -#define REGISTER_ARG(_index_,_type_) \ - { \ - size_t n = (_index_); \ - if (n >= a_allocated) \ - { \ - size_t memory_size; \ - argument *memory; \ - \ - a_allocated = xtimes (a_allocated, 2); \ - if (a_allocated <= n) \ - a_allocated = xsum (n, 1); \ - memory_size = xtimes (a_allocated, sizeof (argument)); \ - if (size_overflow_p (memory_size)) \ - /* Overflow, would lead to out of memory. */ \ - goto error; \ - memory = (a->arg \ - ? realloc (a->arg, memory_size) \ - : malloc (memory_size)); \ - if (memory == NULL) \ - /* Out of memory. */ \ - goto error; \ - a->arg = memory; \ - } \ - while (a->count <= n) \ - a->arg[a->count++].type = TYPE_NONE; \ - if (a->arg[n].type == TYPE_NONE) \ - a->arg[n].type = (_type_); \ - else if (a->arg[n].type != (_type_)) \ - /* Ambiguous type for positional argument. */ \ - goto error; \ - } - - while (*cp != '\0') - { - CHAR_T c = *cp++; - if (c == '%') - { - size_t arg_index = ARG_NONE; - DIRECTIVE *dp = &d->dir[d->count];/* pointer to next directive */ - - /* Initialize the next directive. */ - dp->dir_start = cp - 1; - dp->flags = 0; - dp->width_start = NULL; - dp->width_end = NULL; - dp->width_arg_index = ARG_NONE; - dp->precision_start = NULL; - dp->precision_end = NULL; - dp->precision_arg_index = ARG_NONE; - dp->arg_index = ARG_NONE; - - /* Test for positional argument. */ - if (*cp >= '0' && *cp <= '9') - { - const CHAR_T *np; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - ; - if (*np == '$') - { - size_t n = 0; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - n = xsum (xtimes (n, 10), *np - '0'); - if (n == 0) - /* Positional argument 0. */ - goto error; - if (size_overflow_p (n)) - /* n too large, would lead to out of memory later. */ - goto error; - arg_index = n - 1; - cp = np + 1; - } - } - - /* Read the flags. */ - for (;;) - { - if (*cp == '\'') - { - dp->flags |= FLAG_GROUP; - cp++; - } - else if (*cp == '-') - { - dp->flags |= FLAG_LEFT; - cp++; - } - else if (*cp == '+') - { - dp->flags |= FLAG_SHOWSIGN; - cp++; - } - else if (*cp == ' ') - { - dp->flags |= FLAG_SPACE; - cp++; - } - else if (*cp == '#') - { - dp->flags |= FLAG_ALT; - cp++; - } - else if (*cp == '0') - { - dp->flags |= FLAG_ZERO; - cp++; - } - else - break; - } - - /* Parse the field width. */ - if (*cp == '*') - { - dp->width_start = cp; - cp++; - dp->width_end = cp; - if (max_width_length < 1) - max_width_length = 1; - - /* Test for positional argument. */ - if (*cp >= '0' && *cp <= '9') - { - const CHAR_T *np; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - ; - if (*np == '$') - { - size_t n = 0; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - n = xsum (xtimes (n, 10), *np - '0'); - if (n == 0) - /* Positional argument 0. */ - goto error; - if (size_overflow_p (n)) - /* n too large, would lead to out of memory later. */ - goto error; - dp->width_arg_index = n - 1; - cp = np + 1; - } - } - if (dp->width_arg_index == ARG_NONE) - { - dp->width_arg_index = arg_posn++; - if (dp->width_arg_index == ARG_NONE) - /* arg_posn wrapped around. */ - goto error; - } - REGISTER_ARG (dp->width_arg_index, TYPE_INT); - } - else if (*cp >= '0' && *cp <= '9') - { - size_t width_length; - - dp->width_start = cp; - for (; *cp >= '0' && *cp <= '9'; cp++) - ; - dp->width_end = cp; - width_length = dp->width_end - dp->width_start; - if (max_width_length < width_length) - max_width_length = width_length; - } - - /* Parse the precision. */ - if (*cp == '.') - { - cp++; - if (*cp == '*') - { - dp->precision_start = cp - 1; - cp++; - dp->precision_end = cp; - if (max_precision_length < 2) - max_precision_length = 2; - - /* Test for positional argument. */ - if (*cp >= '0' && *cp <= '9') - { - const CHAR_T *np; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - ; - if (*np == '$') - { - size_t n = 0; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - n = xsum (xtimes (n, 10), *np - '0'); - if (n == 0) - /* Positional argument 0. */ - goto error; - if (size_overflow_p (n)) - /* n too large, would lead to out of memory - later. */ - goto error; - dp->precision_arg_index = n - 1; - cp = np + 1; - } - } - if (dp->precision_arg_index == ARG_NONE) - { - dp->precision_arg_index = arg_posn++; - if (dp->precision_arg_index == ARG_NONE) - /* arg_posn wrapped around. */ - goto error; - } - REGISTER_ARG (dp->precision_arg_index, TYPE_INT); - } - else - { - size_t precision_length; - - dp->precision_start = cp - 1; - for (; *cp >= '0' && *cp <= '9'; cp++) - ; - dp->precision_end = cp; - precision_length = dp->precision_end - dp->precision_start; - if (max_precision_length < precision_length) - max_precision_length = precision_length; - } - } - - { - arg_type type; - - /* Parse argument type/size specifiers. */ - { - int flags = 0; - - for (;;) - { - if (*cp == 'h') - { - flags |= (1 << (flags & 1)); - cp++; - } - else if (*cp == 'L') - { - flags |= 4; - cp++; - } - else if (*cp == 'l') - { - flags += 8; - cp++; - } -#ifdef HAVE_INTMAX_T - else if (*cp == 'j') - { - if (sizeof (intmax_t) > sizeof (long)) - { - /* intmax_t = long long */ - flags += 16; - } - else if (sizeof (intmax_t) > sizeof (int)) - { - /* intmax_t = long */ - flags += 8; - } - cp++; - } -#endif - else if (*cp == 'z' || *cp == 'Z') - { - /* 'z' is standardized in ISO C 99, but glibc uses 'Z' - because the warning facility in gcc-2.95.2 understands - only 'Z' (see gcc-2.95.2/gcc/c-common.c:1784). */ - if (sizeof (size_t) > sizeof (long)) - { - /* size_t = long long */ - flags += 16; - } - else if (sizeof (size_t) > sizeof (int)) - { - /* size_t = long */ - flags += 8; - } - cp++; - } - else if (*cp == 't') - { - if (sizeof (ptrdiff_t) > sizeof (long)) - { - /* ptrdiff_t = long long */ - flags += 16; - } - else if (sizeof (ptrdiff_t) > sizeof (int)) - { - /* ptrdiff_t = long */ - flags += 8; - } - cp++; - } - else - break; - } - - /* Read the conversion character. */ - c = *cp++; - switch (c) - { - case 'd': case 'i': -#ifdef HAVE_LONG_LONG - if (flags >= 16 || (flags & 4)) - type = TYPE_LONGLONGINT; - else -#endif - if (flags >= 8) - type = TYPE_LONGINT; - else if (flags & 2) - type = TYPE_SCHAR; - else if (flags & 1) - type = TYPE_SHORT; - else - type = TYPE_INT; - break; - case 'o': case 'u': case 'x': case 'X': -#ifdef HAVE_LONG_LONG - if (flags >= 16 || (flags & 4)) - type = TYPE_ULONGLONGINT; - else -#endif - if (flags >= 8) - type = TYPE_ULONGINT; - else if (flags & 2) - type = TYPE_UCHAR; - else if (flags & 1) - type = TYPE_USHORT; - else - type = TYPE_UINT; - break; - case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': - case 'a': case 'A': -#ifdef HAVE_LONG_DOUBLE - if (flags >= 16 || (flags & 4)) - type = TYPE_LONGDOUBLE; - else -#endif - type = TYPE_DOUBLE; - break; - case 'c': - if (flags >= 8) -#ifdef HAVE_WINT_T - type = TYPE_WIDE_CHAR; -#else - goto error; -#endif - else - type = TYPE_CHAR; - break; -#ifdef HAVE_WINT_T - case 'C': - type = TYPE_WIDE_CHAR; - c = 'c'; - break; -#endif - case 's': - if (flags >= 8) -#ifdef HAVE_WCHAR_T - type = TYPE_WIDE_STRING; -#else - goto error; -#endif - else - type = TYPE_STRING; - break; -#ifdef HAVE_WCHAR_T - case 'S': - type = TYPE_WIDE_STRING; - c = 's'; - break; -#endif - case 'p': - type = TYPE_POINTER; - break; - case 'n': -#ifdef HAVE_LONG_LONG - if (flags >= 16 || (flags & 4)) - type = TYPE_COUNT_LONGLONGINT_POINTER; - else -#endif - if (flags >= 8) - type = TYPE_COUNT_LONGINT_POINTER; - else if (flags & 2) - type = TYPE_COUNT_SCHAR_POINTER; - else if (flags & 1) - type = TYPE_COUNT_SHORT_POINTER; - else - type = TYPE_COUNT_INT_POINTER; - break; - case '%': - type = TYPE_NONE; - break; - default: - /* Unknown conversion character. */ - goto error; - } - } - - if (type != TYPE_NONE) - { - dp->arg_index = arg_index; - if (dp->arg_index == ARG_NONE) - { - dp->arg_index = arg_posn++; - if (dp->arg_index == ARG_NONE) - /* arg_posn wrapped around. */ - goto error; - } - REGISTER_ARG (dp->arg_index, type); - } - dp->conversion = c; - dp->dir_end = cp; - } - - d->count++; - if (d->count >= d_allocated) - { - size_t memory_size; - DIRECTIVE *memory; - - d_allocated = xtimes (d_allocated, 2); - memory_size = xtimes (d_allocated, sizeof (DIRECTIVE)); - if (size_overflow_p (memory_size)) - /* Overflow, would lead to out of memory. */ - goto error; - memory = realloc (d->dir, memory_size); - if (memory == NULL) - /* Out of memory. */ - goto error; - d->dir = memory; - } - } - } - d->dir[d->count].dir_start = cp; - - d->max_width_length = max_width_length; - d->max_precision_length = max_precision_length; - return 0; - -error: - if (a->arg) - free (a->arg); - if (d->dir) - free (d->dir); - return -1; -} - -#undef DIRECTIVES -#undef DIRECTIVE -#undef CHAR_T -#undef PRINTF_PARSE diff --git a/gl/printf-parse.h b/gl/printf-parse.h deleted file mode 100644 index 82a0d37cd..000000000 --- a/gl/printf-parse.h +++ /dev/null @@ -1,74 +0,0 @@ -/* Parse printf format string. - Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc. - - This program 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, or (at your option) - any later version. - - This program 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef _PRINTF_PARSE_H -#define _PRINTF_PARSE_H - -#include "printf-args.h" - - -/* Flags */ -#define FLAG_GROUP 1 /* ' flag */ -#define FLAG_LEFT 2 /* - flag */ -#define FLAG_SHOWSIGN 4 /* + flag */ -#define FLAG_SPACE 8 /* space flag */ -#define FLAG_ALT 16 /* # flag */ -#define FLAG_ZERO 32 - -/* arg_index value indicating that no argument is consumed. */ -#define ARG_NONE (~(size_t)0) - -/* A parsed directive. */ -typedef struct -{ - const char* dir_start; - const char* dir_end; - int flags; - const char* width_start; - const char* width_end; - size_t width_arg_index; - const char* precision_start; - const char* precision_end; - size_t precision_arg_index; - char conversion; /* d i o u x X f e E g G c s p n U % but not C S */ - size_t arg_index; -} -char_directive; - -/* A parsed format string. */ -typedef struct -{ - size_t count; - char_directive *dir; - size_t max_width_length; - size_t max_precision_length; -} -char_directives; - - -/* Parses the format string. Fills in the number N of directives, and fills - in directives[0], ..., directives[N-1], and sets directives[N].dir_start - to the end of the format string. Also fills in the arg_type fields of the - arguments and the needed count of arguments. */ -#ifdef STATIC -STATIC -#else -extern -#endif -int printf_parse (const char *format, char_directives *d, arguments *a); - -#endif /* _PRINTF_PARSE_H */ diff --git a/gl/setenv.c b/gl/setenv.c index 33dbeb7a3..23832485a 100644 --- a/gl/setenv.c +++ b/gl/setenv.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1992,1995-1999,2000-2003 Free Software Foundation, Inc. +/* Copyright (C) 1992,1995-1999,2000-2003,2005,2006 Free Software Foundation, Inc. This file is part of the GNU C Library. This program is free software; you can redistribute it and/or modify @@ -13,9 +13,9 @@ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#if HAVE_CONFIG_H +#if !_LIBC # include <config.h> #endif #include <alloca.h> diff --git a/gl/asnprintf.c b/gl/size_max.h index 1b7f4ba39..ed0bc1377 100644 --- a/gl/asnprintf.c +++ b/gl/size_max.h @@ -1,5 +1,6 @@ -/* Formatted output to strings. - Copyright (C) 1999, 2002 Free Software Foundation, Inc. +/* size_max.h -- declare SIZE_MAX through system headers + Copyright (C) 2005-2006 Free Software Foundation, Inc. + Written by Simon Josefsson. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -11,27 +12,20 @@ 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, + 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif +#ifndef GNULIB_SIZE_MAX_H +#define GNULIB_SIZE_MAX_H -/* Specification. */ -#include "vasnprintf.h" +/* Get SIZE_MAX declaration on systems like Solaris 7/8/9. */ +# include <limits.h> +/* Get SIZE_MAX declaration on systems like glibc 2. */ +# if HAVE_STDINT_H +# include <stdint.h> +# endif +/* On systems where these include files don't define it, SIZE_MAX is defined + in config.h. */ -#include <stdarg.h> - -char * -asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...) -{ - va_list args; - char *result; - - va_start (args, format); - result = vasnprintf (resultbuf, lengthp, format, args); - va_end (args); - return result; -} +#endif /* GNULIB_SIZE_MAX_H */ diff --git a/gl/stdint_.h b/gl/stdint_.h new file mode 100644 index 000000000..b0af52243 --- /dev/null +++ b/gl/stdint_.h @@ -0,0 +1,492 @@ +/* Copyright (C) 2001-2002, 2004-2006 Free Software Foundation, Inc. + Written by Paul Eggert, Bruno Haible, Sam Steingold, Peter Burwood. + This file is part of gnulib. + + This program 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, or (at your option) + any later version. + + This program 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef _GL_STDINT_H +#define _GL_STDINT_H + +/* + * ISO C 99 <stdint.h> for platforms that lack it. + * <http://www.opengroup.org/susv3xbd/stdint.h.html> + */ + +/* Get those types that are already defined in other system include + files, so that we can "#define int8_t signed char" below without + worrying about a later system include file containing a "typedef + signed char int8_t;" that will get messed up by our macro. Our + macros should all be consistent with the system versions, except + for the "fast" types and macros, which we recommend against using + in public interfaces due to compiler differences. */ + +#if @HAVE_STDINT_H@ +# if defined __sgi && ! defined __c99 + /* Bypass IRIX's <stdint.h> if in C89 mode, since it merely annoys users + with "This header file is to be used only for c99 mode compilations" + diagnostics. */ +# define __STDINT_H__ +# endif + /* Other systems may have an incomplete or buggy <stdint.h>. + Include it before <inttypes.h>, since any "#include <stdint.h>" + in <inttypes.h> would reinclude us, skipping our contents because + _GL_STDINT_H is defined. */ +# include @ABSOLUTE_STDINT_H@ +#endif + +/* <sys/types.h> defines some of the stdint.h types as well, on glibc, + IRIX 6.5, and OpenBSD 3.8 (via <machine/types.h>). + MacOS X 10.4.6 <sys/types.h> includes <stdint.h> (which is us), but + relies on the system <stdint.h> definitions, so include + <sys/types.h> after @ABSOLUTE_STDINT_H@. */ +#if @HAVE_SYS_TYPES_H@ +# include <sys/types.h> +#endif + +/* Get LONG_MIN, LONG_MAX, ULONG_MAX. */ +#include <limits.h> + +#if @HAVE_INTTYPES_H@ + /* In OpenBSD 3.8, <inttypes.h> includes <machine/types.h>, which defines + int{8,16,32,64}_t, uint{8,16,32,64}_t and __BIT_TYPES_DEFINED__. + <inttypes.h> also defines intptr_t and uintptr_t. */ +# define _GL_JUST_INCLUDE_ABSOLUTE_INTTYPES_H +# include <inttypes.h> +# undef _GL_JUST_INCLUDE_ABSOLUTE_INTTYPES_H +#elif @HAVE_SYS_INTTYPES_H@ + /* Solaris 7 <sys/inttypes.h> has the types except the *_fast*_t types, and + the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX. */ +# include <sys/inttypes.h> +#endif + +#if @HAVE_SYS_BITYPES_H@ && ! defined __BIT_TYPES_DEFINED__ + /* Linux libc4 >= 4.6.7 and libc5 have a <sys/bitypes.h> that defines + int{8,16,32,64}_t and __BIT_TYPES_DEFINED__. In libc5 >= 5.2.2 it is + included by <sys/types.h>. */ +# include <sys/bitypes.h> +#endif + +#if ! defined __cplusplus || defined __STDC_CONSTANT_MACROS + +/* Get WCHAR_MIN, WCHAR_MAX. */ +# if @HAVE_WCHAR_H@ && ! (defined WCHAR_MIN && defined WCHAR_MAX) + /* BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before + <wchar.h>. */ +# include <stdio.h> +# include <time.h> +# include <wchar.h> +# endif + +#endif + +/* Minimum and maximum values for a integer type under the usual assumption. + Return an unspecified value if BITS == 0, adding a check to pacify + picky compilers. */ + +#define _STDINT_MIN(signed, bits, zero) \ + ((signed) ? (- ((zero) + 1) << ((bits) ? (bits) - 1 : 0)) : (zero)) + +#define _STDINT_MAX(signed, bits, zero) \ + ((signed) \ + ? ~ _STDINT_MIN (signed, bits, zero) \ + : ((((zero) + 1) << ((bits) ? (bits) - 1 : 0)) - 1) * 2 + 1) + +/* 7.18.1.1. Exact-width integer types */ + +/* Here we assume a standard architecture where the hardware integer + types have 8, 16, 32, optionally 64 bits. */ + +#undef int8_t +#undef uint8_t +#define int8_t signed char +#define uint8_t unsigned char + +#undef int16_t +#undef uint16_t +#define int16_t short int +#define uint16_t unsigned short int + +#undef int32_t +#undef uint32_t +#define int32_t int +#define uint32_t unsigned int + +#undef int64_t +#if LONG_MAX >> 31 >> 31 == 1 +# define int64_t long int +#elif defined _MSC_VER +# define int64_t __int64 +#elif @HAVE_LONG_LONG_INT@ +# define int64_t long long int +#endif + +#undef uint64_t +#if ULONG_MAX >> 31 >> 31 >> 1 == 1 +# define uint64_t unsigned long int +#elif defined _MSC_VER +# define uint64_t unsigned __int64 +#elif @HAVE_UNSIGNED_LONG_LONG_INT@ +# define uint64_t unsigned long long int +#endif + +/* Avoid collision with Solaris 2.5.1 <pthread.h> etc. */ +#define _UINT8_T +#define _UINT32_T +#define _UINT64_T + + +/* 7.18.1.2. Minimum-width integer types */ + +/* Here we assume a standard architecture where the hardware integer + types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types + are the same as the corresponding N_t types. */ + +#undef int_least8_t +#undef uint_least8_t +#undef int_least16_t +#undef uint_least16_t +#undef int_least32_t +#undef uint_least32_t +#undef int_least64_t +#undef uint_least64_t +#define int_least8_t int8_t +#define uint_least8_t uint8_t +#define int_least16_t int16_t +#define uint_least16_t uint16_t +#define int_least32_t int32_t +#define uint_least32_t uint32_t +#ifdef int64_t +# define int_least64_t int64_t +#endif +#ifdef uint64_t +# define uint_least64_t uint64_t +#endif + +/* 7.18.1.3. Fastest minimum-width integer types */ + +/* Note: Other <stdint.h> substitutes may define these types differently. + It is not recommended to use these types in public header files. */ + +/* Here we assume a standard architecture where the hardware integer + types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types + are taken from the same list of types. Assume that 'long int' + is fast enough for all narrower integers. */ + +#undef int_fast8_t +#undef uint_fast8_t +#undef int_fast16_t +#undef uint_fast16_t +#undef int_fast32_t +#undef uint_fast32_t +#undef int_fast64_t +#undef uint_fast64_t +#define int_fast8_t long int +#define uint_fast8_t unsigned int_fast8_t +#define int_fast16_t long int +#define uint_fast16_t unsigned int_fast16_t +#define int_fast32_t long int +#define uint_fast32_t unsigned int_fast32_t +#ifdef int64_t +# define int_fast64_t int64_t +#endif +#ifdef uint64_t +# define uint_fast64_t uint64_t +#endif + +/* 7.18.1.4. Integer types capable of holding object pointers */ + +#undef intptr_t +#undef uintptr_t +#define intptr_t long int +#define uintptr_t unsigned long int + +/* 7.18.1.5. Greatest-width integer types */ + +/* Note: These types are compiler dependent. It may be unwise to use them in + public header files. */ + +#undef intmax_t +#if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1 +# define intmax_t long long int +#elif defined int64_t +# define intmax_t int64_t +#else +# define intmax_t long int +#endif + +#undef uintmax_t +#if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1 +# define uintmax_t unsigned long long int +#elif defined int64_t +# define uintmax_t uint64_t +#else +# define uintmax_t unsigned long int +#endif + +/* 7.18.2. Limits of specified-width integer types */ + +#if ! defined __cplusplus || defined __STDC_LIMIT_MACROS + +/* 7.18.2.1. Limits of exact-width integer types */ + +/* Here we assume a standard architecture where the hardware integer + types have 8, 16, 32, optionally 64 bits. */ + +#undef INT8_MIN +#undef INT8_MAX +#undef UINT8_MAX +#define INT8_MIN (~ INT8_MAX) +#define INT8_MAX 127 +#define UINT8_MAX 255 + +#undef INT16_MIN +#undef INT16_MAX +#undef UINT16_MAX +#define INT16_MIN (~ INT16_MAX) +#define INT16_MAX 32767 +#define UINT16_MAX 65535 + +#undef INT32_MIN +#undef INT32_MAX +#undef UINT32_MAX +#define INT32_MIN (~ INT32_MAX) +#define INT32_MAX 2147483647 +#define UINT32_MAX 4294967295U + +#undef INT64_MIN +#undef INT64_MAX +#ifdef int64_t +# define INT64_MIN (~ INT64_MAX) +# define INT64_MAX INTMAX_C (9223372036854775807) +#endif + +#undef UINT64_MAX +#ifdef uint64_t +# define UINT64_MAX UINTMAX_C (18446744073709551615) +#endif + +/* 7.18.2.2. Limits of minimum-width integer types */ + +/* Here we assume a standard architecture where the hardware integer + types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types + are the same as the corresponding N_t types. */ + +#undef INT_LEAST8_MIN +#undef INT_LEAST8_MAX +#undef UINT_LEAST8_MAX +#define INT_LEAST8_MIN INT8_MIN +#define INT_LEAST8_MAX INT8_MAX +#define UINT_LEAST8_MAX UINT8_MAX + +#undef INT_LEAST16_MIN +#undef INT_LEAST16_MAX +#undef UINT_LEAST16_MAX +#define INT_LEAST16_MIN INT16_MIN +#define INT_LEAST16_MAX INT16_MAX +#define UINT_LEAST16_MAX UINT16_MAX + +#undef INT_LEAST32_MIN +#undef INT_LEAST32_MAX +#undef UINT_LEAST32_MAX +#define INT_LEAST32_MIN INT32_MIN +#define INT_LEAST32_MAX INT32_MAX +#define UINT_LEAST32_MAX UINT32_MAX + +#undef INT_LEAST64_MIN +#undef INT_LEAST64_MAX +#ifdef int64_t +# define INT_LEAST64_MIN INT64_MIN +# define INT_LEAST64_MAX INT64_MAX +#endif + +#undef UINT_LEAST64_MAX +#ifdef uint64_t +# define UINT_LEAST64_MAX UINT64_MAX +#endif + +/* 7.18.2.3. Limits of fastest minimum-width integer types */ + +/* Here we assume a standard architecture where the hardware integer + types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types + are taken from the same list of types. */ + +#undef INT_FAST8_MIN +#undef INT_FAST8_MAX +#undef UINT_FAST8_MAX +#define INT_FAST8_MIN LONG_MIN +#define INT_FAST8_MAX LONG_MAX +#define UINT_FAST8_MAX ULONG_MAX + +#undef INT_FAST16_MIN +#undef INT_FAST16_MAX +#undef UINT_FAST16_MAX +#define INT_FAST16_MIN LONG_MIN +#define INT_FAST16_MAX LONG_MAX +#define UINT_FAST16_MAX ULONG_MAX + +#undef INT_FAST32_MIN +#undef INT_FAST32_MAX +#undef UINT_FAST32_MAX +#define INT_FAST32_MIN LONG_MIN +#define INT_FAST32_MAX LONG_MAX +#define UINT_FAST32_MAX ULONG_MAX + +#undef INT_FAST64_MIN +#undef INT_FAST64_MAX +#ifdef int64_t +# define INT_FAST64_MIN INT64_MIN +# define INT_FAST64_MAX INT64_MAX +#endif + +#undef UINT_FAST64_MAX +#ifdef uint64_t +# define UINT_FAST64_MAX UINT64_MAX +#endif + +/* 7.18.2.4. Limits of integer types capable of holding object pointers */ + +#undef INTPTR_MIN +#undef INTPTR_MAX +#undef UINTPTR_MAX +#define INTPTR_MIN LONG_MIN +#define INTPTR_MAX LONG_MAX +#define UINTPTR_MAX ULONG_MAX + +/* 7.18.2.5. Limits of greatest-width integer types */ + +#undef INTMAX_MIN +#undef INTMAX_MAX +#define INTMAX_MIN (~ INTMAX_MAX) +#ifdef INT64_MAX +# define INTMAX_MAX INT64_MAX +#else +# define INTMAX_MAX INT32_MAX +#endif + +#undef UINTMAX_MAX +#ifdef UINT64_MAX +# define UINTMAX_MAX UINT64_MAX +#else +# define UINTMAX_MAX UINT32_MAX +#endif + +/* 7.18.3. Limits of other integer types */ + +/* ptrdiff_t limits */ +#undef PTRDIFF_MIN +#undef PTRDIFF_MAX +#define PTRDIFF_MIN \ + _STDINT_MIN (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@) +#define PTRDIFF_MAX \ + _STDINT_MAX (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@) + +/* sig_atomic_t limits */ +#undef SIG_ATOMIC_MIN +#undef SIG_ATOMIC_MAX +#define SIG_ATOMIC_MIN \ + _STDINT_MIN (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \ + 0@SIG_ATOMIC_T_SUFFIX@) +#define SIG_ATOMIC_MAX \ + _STDINT_MAX (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \ + 0@SIG_ATOMIC_T_SUFFIX@) + + +/* size_t limit */ +#undef SIZE_MAX +#define SIZE_MAX _STDINT_MAX (0, @BITSIZEOF_SIZE_T@, 0@SIZE_T_SUFFIX@) + +/* wchar_t limits */ +#undef WCHAR_MIN +#undef WCHAR_MAX +#define WCHAR_MIN \ + _STDINT_MIN (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@) +#define WCHAR_MAX \ + _STDINT_MAX (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@) + +/* wint_t limits */ +#undef WINT_MIN +#undef WINT_MAX +#define WINT_MIN \ + _STDINT_MIN (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@) +#define WINT_MAX \ + _STDINT_MAX (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@) + +#endif /* !defined __cplusplus || defined __STDC_LIMIT_MACROS */ + +/* 7.18.4. Macros for integer constants */ + +#if ! defined __cplusplus || defined __STDC_CONSTANT_MACROS + +/* 7.18.4.1. Macros for minimum-width integer constants */ +/* According to ISO C 99 Technical Corrigendum 1 */ + +/* Here we assume a standard architecture where the hardware integer + types have 8, 16, 32, optionally 64 bits, and int is 32 bits. */ + +#undef INT8_C +#undef UINT8_C +#define INT8_C(x) x +#define UINT8_C(x) x + +#undef INT16_C +#undef UINT16_C +#define INT16_C(x) x +#define UINT16_C(x) x + +#undef INT32_C +#undef UINT32_C +#define INT32_C(x) x +#define UINT32_C(x) x ## U + +#undef INT64_C +#undef UINT64_C +#if LONG_MAX >> 31 >> 31 == 1 +# define INT64_C(x) x##L +#elif defined _MSC_VER +# define INT64_C(x) x##i64 +#elif @HAVE_LONG_LONG_INT@ +# define INT64_C(x) x##LL +#endif +#if ULONG_MAX >> 31 >> 31 >> 1 == 1 +# define UINT64_C(x) x##UL +#elif defined _MSC_VER +# define UINT64_C(x) x##ui64 +#elif @HAVE_UNSIGNED_LONG_LONG_INT@ +# define UINT64_C(x) x##ULL +#endif + +/* 7.18.4.2. Macros for greatest-width integer constants */ + +#undef INTMAX_C +#if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1 +# define INTMAX_C(x) x##LL +#elif defined int64_t +# define INTMAX_C(x) INT64_C(x) +#else +# define INTMAX_C(x) x##L +#endif + +#undef UINTMAX_C +#if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1 +# define UINTMAX_C(x) x##ULL +#elif defined uint64_t +# define UINTMAX_C(x) UINT64_C(x) +#else +# define UINTMAX_C(x) x##UL +#endif + +#endif /* !defined __cplusplus || defined __STDC_CONSTANT_MACROS */ + +#endif /* _GL_STDINT_H */ diff --git a/gl/strpbrk.c b/gl/strpbrk.c new file mode 100644 index 000000000..7843a6dd6 --- /dev/null +++ b/gl/strpbrk.c @@ -0,0 +1,42 @@ +/* Copyright (C) 1991, 1994, 2000, 2002-2003, 2006 Free Software + Foundation, Inc. + + NOTE: The canonical source of this file is maintained with the GNU C Library. + Bugs can be reported to bug-glibc@prep.ai.mit.edu. + + This program 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, or (at your option) any + later version. + + This program 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include <config.h> + +#include <stddef.h> +#include <string.h> + +#undef strpbrk + +/* Find the first occurrence in S of any character in ACCEPT. */ +char * +strpbrk (const char *s, const char *accept) +{ + while (*s != '\0') + { + const char *a = accept; + while (*a != '\0') + if (*a++ == *s) + return (char *) s; + ++s; + } + + return NULL; +} diff --git a/gl/asprintf.c b/gl/strpbrk.h index 7c4e64a24..acc8d358b 100644 --- a/gl/asprintf.c +++ b/gl/strpbrk.h @@ -1,5 +1,5 @@ -/* Formatted output to strings. - Copyright (C) 1999, 2002 Free Software Foundation, Inc. +/* Searching in a string. + Copyright (C) 2001-2002 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -11,27 +11,18 @@ 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, + 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif +#if HAVE_STRPBRK -/* Specification. */ -#include "vasprintf.h" +/* Get strpbrk() declaration. */ +#include <string.h> -#include <stdarg.h> +#else -int -asprintf (char **resultp, const char *format, ...) -{ - va_list args; - int result; +/* Find the first occurrence in S of any character in ACCEPT. */ +extern char *strpbrk (const char *s, const char *accept); - va_start (args, format); - result = vasprintf (resultp, format, args); - va_end (args); - return result; -} +#endif diff --git a/gl/unsetenv.c b/gl/unsetenv.c index 4b53fc9c8..0f837440d 100644 --- a/gl/unsetenv.c +++ b/gl/unsetenv.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1992,1995-1999,2000-2002 Free Software Foundation, Inc. +/* Copyright (C) 1992,1995-1999,2000-2002,2005-2006 Free Software Foundation, Inc. This file is part of the GNU C Library. This program is free software; you can redistribute it and/or modify @@ -13,25 +13,18 @@ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#if HAVE_CONFIG_H -# include <config.h> -#endif +#include <config.h> #include <errno.h> #if !_LIBC -# if !defined errno && !defined HAVE_ERRNO_DECL -extern int errno; -# endif # define __set_errno(ev) ((errno) = (ev)) #endif #include <stdlib.h> #include <string.h> -#if _LIBC || HAVE_UNISTD_H -# include <unistd.h> -#endif +#include <unistd.h> #if !_LIBC # define __environ environ diff --git a/gl/vasnprintf.c b/gl/vasnprintf.c deleted file mode 100644 index 324d62ecd..000000000 --- a/gl/vasnprintf.c +++ /dev/null @@ -1,901 +0,0 @@ -/* vsprintf with automatic memory allocation. - Copyright (C) 1999, 2002-2005 Free Software Foundation, Inc. - - This program 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, or (at your option) - any later version. - - This program 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -/* Tell glibc's <stdio.h> to provide a prototype for snprintf(). - This must come before <config.h> because <config.h> may include - <features.h>, and once <features.h> has been included, it's too late. */ -#ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 -#endif - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif -#ifndef IN_LIBINTL -# include <alloca.h> -#endif - -/* Specification. */ -#if WIDE_CHAR_VERSION -# include "vasnwprintf.h" -#else -# include "vasnprintf.h" -#endif - -#include <stdio.h> /* snprintf(), sprintf() */ -#include <stdlib.h> /* abort(), malloc(), realloc(), free() */ -#include <string.h> /* memcpy(), strlen() */ -#include <errno.h> /* errno */ -#include <limits.h> /* CHAR_BIT, INT_MAX */ -#include <float.h> /* DBL_MAX_EXP, LDBL_MAX_EXP */ -#if WIDE_CHAR_VERSION -# include "wprintf-parse.h" -#else -# include "printf-parse.h" -#endif - -/* Checked size_t computations. */ -#include "xsize.h" - -/* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW. */ -#ifndef EOVERFLOW -# define EOVERFLOW E2BIG -#endif - -#ifdef HAVE_WCHAR_T -# ifdef HAVE_WCSLEN -# define local_wcslen wcslen -# else - /* Solaris 2.5.1 has wcslen() in a separate library libw.so. To avoid - a dependency towards this library, here is a local substitute. - Define this substitute only once, even if this file is included - twice in the same compilation unit. */ -# ifndef local_wcslen_defined -# define local_wcslen_defined 1 -static size_t -local_wcslen (const wchar_t *s) -{ - const wchar_t *ptr; - - for (ptr = s; *ptr != (wchar_t) 0; ptr++) - ; - return ptr - s; -} -# endif -# endif -#endif - -#if WIDE_CHAR_VERSION -# define VASNPRINTF vasnwprintf -# define CHAR_T wchar_t -# define DIRECTIVE wchar_t_directive -# define DIRECTIVES wchar_t_directives -# define PRINTF_PARSE wprintf_parse -# define USE_SNPRINTF 1 -# if HAVE_DECL__SNWPRINTF - /* On Windows, the function swprintf() has a different signature than - on Unix; we use the _snwprintf() function instead. */ -# define SNPRINTF _snwprintf -# else - /* Unix. */ -# define SNPRINTF swprintf -# endif -#else -# define VASNPRINTF vasnprintf -# define CHAR_T char -# define DIRECTIVE char_directive -# define DIRECTIVES char_directives -# define PRINTF_PARSE printf_parse -# define USE_SNPRINTF (HAVE_DECL__SNPRINTF || HAVE_SNPRINTF) -# if HAVE_DECL__SNPRINTF - /* Windows. */ -# define SNPRINTF _snprintf -# else - /* Unix. */ -# define SNPRINTF snprintf -# endif -#endif - -CHAR_T * -VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list args) -{ - DIRECTIVES d; - arguments a; - - if (PRINTF_PARSE (format, &d, &a) < 0) - { - errno = EINVAL; - return NULL; - } - -#define CLEANUP() \ - free (d.dir); \ - if (a.arg) \ - free (a.arg); - - if (printf_fetchargs (args, &a) < 0) - { - CLEANUP (); - errno = EINVAL; - return NULL; - } - - { - size_t buf_neededlength; - CHAR_T *buf; - CHAR_T *buf_malloced; - const CHAR_T *cp; - size_t i; - DIRECTIVE *dp; - /* Output string accumulator. */ - CHAR_T *result; - size_t allocated; - size_t length; - - /* Allocate a small buffer that will hold a directive passed to - sprintf or snprintf. */ - buf_neededlength = - xsum4 (7, d.max_width_length, d.max_precision_length, 6); -#if HAVE_ALLOCA - if (buf_neededlength < 4000 / sizeof (CHAR_T)) - { - buf = (CHAR_T *) alloca (buf_neededlength * sizeof (CHAR_T)); - buf_malloced = NULL; - } - else -#endif - { - size_t buf_memsize = xtimes (buf_neededlength, sizeof (CHAR_T)); - if (size_overflow_p (buf_memsize)) - goto out_of_memory_1; - buf = (CHAR_T *) malloc (buf_memsize); - if (buf == NULL) - goto out_of_memory_1; - buf_malloced = buf; - } - - if (resultbuf != NULL) - { - result = resultbuf; - allocated = *lengthp; - } - else - { - result = NULL; - allocated = 0; - } - length = 0; - /* Invariants: - result is either == resultbuf or == NULL or malloc-allocated. - If length > 0, then result != NULL. */ - - /* Ensures that allocated >= needed. Aborts through a jump to - out_of_memory if needed is SIZE_MAX or otherwise too big. */ -#define ENSURE_ALLOCATION(needed) \ - if ((needed) > allocated) \ - { \ - size_t memory_size; \ - CHAR_T *memory; \ - \ - allocated = (allocated > 0 ? xtimes (allocated, 2) : 12); \ - if ((needed) > allocated) \ - allocated = (needed); \ - memory_size = xtimes (allocated, sizeof (CHAR_T)); \ - if (size_overflow_p (memory_size)) \ - goto out_of_memory; \ - if (result == resultbuf || result == NULL) \ - memory = (CHAR_T *) malloc (memory_size); \ - else \ - memory = (CHAR_T *) realloc (result, memory_size); \ - if (memory == NULL) \ - goto out_of_memory; \ - if (result == resultbuf && length > 0) \ - memcpy (memory, result, length * sizeof (CHAR_T)); \ - result = memory; \ - } - - for (cp = format, i = 0, dp = &d.dir[0]; ; cp = dp->dir_end, i++, dp++) - { - if (cp != dp->dir_start) - { - size_t n = dp->dir_start - cp; - size_t augmented_length = xsum (length, n); - - ENSURE_ALLOCATION (augmented_length); - memcpy (result + length, cp, n * sizeof (CHAR_T)); - length = augmented_length; - } - if (i == d.count) - break; - - /* Execute a single directive. */ - if (dp->conversion == '%') - { - size_t augmented_length; - - if (!(dp->arg_index == ARG_NONE)) - abort (); - augmented_length = xsum (length, 1); - ENSURE_ALLOCATION (augmented_length); - result[length] = '%'; - length = augmented_length; - } - else - { - if (!(dp->arg_index != ARG_NONE)) - abort (); - - if (dp->conversion == 'n') - { - switch (a.arg[dp->arg_index].type) - { - case TYPE_COUNT_SCHAR_POINTER: - *a.arg[dp->arg_index].a.a_count_schar_pointer = length; - break; - case TYPE_COUNT_SHORT_POINTER: - *a.arg[dp->arg_index].a.a_count_short_pointer = length; - break; - case TYPE_COUNT_INT_POINTER: - *a.arg[dp->arg_index].a.a_count_int_pointer = length; - break; - case TYPE_COUNT_LONGINT_POINTER: - *a.arg[dp->arg_index].a.a_count_longint_pointer = length; - break; -#ifdef HAVE_LONG_LONG - case TYPE_COUNT_LONGLONGINT_POINTER: - *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length; - break; -#endif - default: - abort (); - } - } - else - { - arg_type type = a.arg[dp->arg_index].type; - CHAR_T *p; - unsigned int prefix_count; - int prefixes[2]; -#if !USE_SNPRINTF - size_t tmp_length; - CHAR_T tmpbuf[700]; - CHAR_T *tmp; - - /* Allocate a temporary buffer of sufficient size for calling - sprintf. */ - { - size_t width; - size_t precision; - - width = 0; - if (dp->width_start != dp->width_end) - { - if (dp->width_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->width_arg_index].a.a_int; - width = (arg < 0 ? (unsigned int) (-arg) : arg); - } - else - { - const CHAR_T *digitp = dp->width_start; - - do - width = xsum (xtimes (width, 10), *digitp++ - '0'); - while (digitp != dp->width_end); - } - } - - precision = 6; - if (dp->precision_start != dp->precision_end) - { - if (dp->precision_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->precision_arg_index].a.a_int; - precision = (arg < 0 ? 0 : arg); - } - else - { - const CHAR_T *digitp = dp->precision_start + 1; - - precision = 0; - while (digitp != dp->precision_end) - precision = xsum (xtimes (precision, 10), *digitp++ - '0'); - } - } - - switch (dp->conversion) - { - - case 'd': case 'i': case 'u': -# ifdef HAVE_LONG_LONG - if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long long) * CHAR_BIT - * 0.30103 /* binary -> decimal */ - * 2 /* estimate for FLAG_GROUP */ - ) - + 1 /* turn floor into ceil */ - + 1; /* account for leading sign */ - else -# endif - if (type == TYPE_LONGINT || type == TYPE_ULONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long) * CHAR_BIT - * 0.30103 /* binary -> decimal */ - * 2 /* estimate for FLAG_GROUP */ - ) - + 1 /* turn floor into ceil */ - + 1; /* account for leading sign */ - else - tmp_length = - (unsigned int) (sizeof (unsigned int) * CHAR_BIT - * 0.30103 /* binary -> decimal */ - * 2 /* estimate for FLAG_GROUP */ - ) - + 1 /* turn floor into ceil */ - + 1; /* account for leading sign */ - break; - - case 'o': -# ifdef HAVE_LONG_LONG - if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long long) * CHAR_BIT - * 0.333334 /* binary -> octal */ - ) - + 1 /* turn floor into ceil */ - + 1; /* account for leading sign */ - else -# endif - if (type == TYPE_LONGINT || type == TYPE_ULONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long) * CHAR_BIT - * 0.333334 /* binary -> octal */ - ) - + 1 /* turn floor into ceil */ - + 1; /* account for leading sign */ - else - tmp_length = - (unsigned int) (sizeof (unsigned int) * CHAR_BIT - * 0.333334 /* binary -> octal */ - ) - + 1 /* turn floor into ceil */ - + 1; /* account for leading sign */ - break; - - case 'x': case 'X': -# ifdef HAVE_LONG_LONG - if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long long) * CHAR_BIT - * 0.25 /* binary -> hexadecimal */ - ) - + 1 /* turn floor into ceil */ - + 2; /* account for leading sign or alternate form */ - else -# endif - if (type == TYPE_LONGINT || type == TYPE_ULONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long) * CHAR_BIT - * 0.25 /* binary -> hexadecimal */ - ) - + 1 /* turn floor into ceil */ - + 2; /* account for leading sign or alternate form */ - else - tmp_length = - (unsigned int) (sizeof (unsigned int) * CHAR_BIT - * 0.25 /* binary -> hexadecimal */ - ) - + 1 /* turn floor into ceil */ - + 2; /* account for leading sign or alternate form */ - break; - - case 'f': case 'F': -# ifdef HAVE_LONG_DOUBLE - if (type == TYPE_LONGDOUBLE) - tmp_length = - (unsigned int) (LDBL_MAX_EXP - * 0.30103 /* binary -> decimal */ - * 2 /* estimate for FLAG_GROUP */ - ) - + 1 /* turn floor into ceil */ - + 10; /* sign, decimal point etc. */ - else -# endif - tmp_length = - (unsigned int) (DBL_MAX_EXP - * 0.30103 /* binary -> decimal */ - * 2 /* estimate for FLAG_GROUP */ - ) - + 1 /* turn floor into ceil */ - + 10; /* sign, decimal point etc. */ - tmp_length = xsum (tmp_length, precision); - break; - - case 'e': case 'E': case 'g': case 'G': - case 'a': case 'A': - tmp_length = - 12; /* sign, decimal point, exponent etc. */ - tmp_length = xsum (tmp_length, precision); - break; - - case 'c': -# if defined HAVE_WINT_T && !WIDE_CHAR_VERSION - if (type == TYPE_WIDE_CHAR) - tmp_length = MB_CUR_MAX; - else -# endif - tmp_length = 1; - break; - - case 's': -# ifdef HAVE_WCHAR_T - if (type == TYPE_WIDE_STRING) - { - tmp_length = - local_wcslen (a.arg[dp->arg_index].a.a_wide_string); - -# if !WIDE_CHAR_VERSION - tmp_length = xtimes (tmp_length, MB_CUR_MAX); -# endif - } - else -# endif - tmp_length = strlen (a.arg[dp->arg_index].a.a_string); - break; - - case 'p': - tmp_length = - (unsigned int) (sizeof (void *) * CHAR_BIT - * 0.25 /* binary -> hexadecimal */ - ) - + 1 /* turn floor into ceil */ - + 2; /* account for leading 0x */ - break; - - default: - abort (); - } - - if (tmp_length < width) - tmp_length = width; - - tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ - } - - if (tmp_length <= sizeof (tmpbuf) / sizeof (CHAR_T)) - tmp = tmpbuf; - else - { - size_t tmp_memsize = xtimes (tmp_length, sizeof (CHAR_T)); - - if (size_overflow_p (tmp_memsize)) - /* Overflow, would lead to out of memory. */ - goto out_of_memory; - tmp = (CHAR_T *) malloc (tmp_memsize); - if (tmp == NULL) - /* Out of memory. */ - goto out_of_memory; - } -#endif - - /* Construct the format string for calling snprintf or - sprintf. */ - p = buf; - *p++ = '%'; - if (dp->flags & FLAG_GROUP) - *p++ = '\''; - if (dp->flags & FLAG_LEFT) - *p++ = '-'; - if (dp->flags & FLAG_SHOWSIGN) - *p++ = '+'; - if (dp->flags & FLAG_SPACE) - *p++ = ' '; - if (dp->flags & FLAG_ALT) - *p++ = '#'; - if (dp->flags & FLAG_ZERO) - *p++ = '0'; - if (dp->width_start != dp->width_end) - { - size_t n = dp->width_end - dp->width_start; - memcpy (p, dp->width_start, n * sizeof (CHAR_T)); - p += n; - } - if (dp->precision_start != dp->precision_end) - { - size_t n = dp->precision_end - dp->precision_start; - memcpy (p, dp->precision_start, n * sizeof (CHAR_T)); - p += n; - } - - switch (type) - { -#ifdef HAVE_LONG_LONG - case TYPE_LONGLONGINT: - case TYPE_ULONGLONGINT: - *p++ = 'l'; - /*FALLTHROUGH*/ -#endif - case TYPE_LONGINT: - case TYPE_ULONGINT: -#ifdef HAVE_WINT_T - case TYPE_WIDE_CHAR: -#endif -#ifdef HAVE_WCHAR_T - case TYPE_WIDE_STRING: -#endif - *p++ = 'l'; - break; -#ifdef HAVE_LONG_DOUBLE - case TYPE_LONGDOUBLE: - *p++ = 'L'; - break; -#endif - default: - break; - } - *p = dp->conversion; -#if USE_SNPRINTF - p[1] = '%'; - p[2] = 'n'; - p[3] = '\0'; -#else - p[1] = '\0'; -#endif - - /* Construct the arguments for calling snprintf or sprintf. */ - prefix_count = 0; - if (dp->width_arg_index != ARG_NONE) - { - if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) - abort (); - prefixes[prefix_count++] = a.arg[dp->width_arg_index].a.a_int; - } - if (dp->precision_arg_index != ARG_NONE) - { - if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) - abort (); - prefixes[prefix_count++] = a.arg[dp->precision_arg_index].a.a_int; - } - -#if USE_SNPRINTF - /* Prepare checking whether snprintf returns the count - via %n. */ - ENSURE_ALLOCATION (xsum (length, 1)); - result[length] = '\0'; -#endif - - for (;;) - { - size_t maxlen; - int count; - int retcount; - - maxlen = allocated - length; - count = -1; - retcount = 0; - -#if USE_SNPRINTF -# define SNPRINTF_BUF(arg) \ - switch (prefix_count) \ - { \ - case 0: \ - retcount = SNPRINTF (result + length, maxlen, buf, \ - arg, &count); \ - break; \ - case 1: \ - retcount = SNPRINTF (result + length, maxlen, buf, \ - prefixes[0], arg, &count); \ - break; \ - case 2: \ - retcount = SNPRINTF (result + length, maxlen, buf, \ - prefixes[0], prefixes[1], arg, \ - &count); \ - break; \ - default: \ - abort (); \ - } -#else -# define SNPRINTF_BUF(arg) \ - switch (prefix_count) \ - { \ - case 0: \ - count = sprintf (tmp, buf, arg); \ - break; \ - case 1: \ - count = sprintf (tmp, buf, prefixes[0], arg); \ - break; \ - case 2: \ - count = sprintf (tmp, buf, prefixes[0], prefixes[1],\ - arg); \ - break; \ - default: \ - abort (); \ - } -#endif - - switch (type) - { - case TYPE_SCHAR: - { - int arg = a.arg[dp->arg_index].a.a_schar; - SNPRINTF_BUF (arg); - } - break; - case TYPE_UCHAR: - { - unsigned int arg = a.arg[dp->arg_index].a.a_uchar; - SNPRINTF_BUF (arg); - } - break; - case TYPE_SHORT: - { - int arg = a.arg[dp->arg_index].a.a_short; - SNPRINTF_BUF (arg); - } - break; - case TYPE_USHORT: - { - unsigned int arg = a.arg[dp->arg_index].a.a_ushort; - SNPRINTF_BUF (arg); - } - break; - case TYPE_INT: - { - int arg = a.arg[dp->arg_index].a.a_int; - SNPRINTF_BUF (arg); - } - break; - case TYPE_UINT: - { - unsigned int arg = a.arg[dp->arg_index].a.a_uint; - SNPRINTF_BUF (arg); - } - break; - case TYPE_LONGINT: - { - long int arg = a.arg[dp->arg_index].a.a_longint; - SNPRINTF_BUF (arg); - } - break; - case TYPE_ULONGINT: - { - unsigned long int arg = a.arg[dp->arg_index].a.a_ulongint; - SNPRINTF_BUF (arg); - } - break; -#ifdef HAVE_LONG_LONG - case TYPE_LONGLONGINT: - { - long long int arg = a.arg[dp->arg_index].a.a_longlongint; - SNPRINTF_BUF (arg); - } - break; - case TYPE_ULONGLONGINT: - { - unsigned long long int arg = a.arg[dp->arg_index].a.a_ulonglongint; - SNPRINTF_BUF (arg); - } - break; -#endif - case TYPE_DOUBLE: - { - double arg = a.arg[dp->arg_index].a.a_double; - SNPRINTF_BUF (arg); - } - break; -#ifdef HAVE_LONG_DOUBLE - case TYPE_LONGDOUBLE: - { - long double arg = a.arg[dp->arg_index].a.a_longdouble; - SNPRINTF_BUF (arg); - } - break; -#endif - case TYPE_CHAR: - { - int arg = a.arg[dp->arg_index].a.a_char; - SNPRINTF_BUF (arg); - } - break; -#ifdef HAVE_WINT_T - case TYPE_WIDE_CHAR: - { - wint_t arg = a.arg[dp->arg_index].a.a_wide_char; - SNPRINTF_BUF (arg); - } - break; -#endif - case TYPE_STRING: - { - const char *arg = a.arg[dp->arg_index].a.a_string; - SNPRINTF_BUF (arg); - } - break; -#ifdef HAVE_WCHAR_T - case TYPE_WIDE_STRING: - { - const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string; - SNPRINTF_BUF (arg); - } - break; -#endif - case TYPE_POINTER: - { - void *arg = a.arg[dp->arg_index].a.a_pointer; - SNPRINTF_BUF (arg); - } - break; - default: - abort (); - } - -#if USE_SNPRINTF - /* Portability: Not all implementations of snprintf() - are ISO C 99 compliant. Determine the number of - bytes that snprintf() has produced or would have - produced. */ - if (count >= 0) - { - /* Verify that snprintf() has NUL-terminated its - result. */ - if (count < maxlen && result[length + count] != '\0') - abort (); - /* Portability hack. */ - if (retcount > count) - count = retcount; - } - else - { - /* snprintf() doesn't understand the '%n' - directive. */ - if (p[1] != '\0') - { - /* Don't use the '%n' directive; instead, look - at the snprintf() return value. */ - p[1] = '\0'; - continue; - } - else - { - /* Look at the snprintf() return value. */ - if (retcount < 0) - { - /* HP-UX 10.20 snprintf() is doubly deficient: - It doesn't understand the '%n' directive, - *and* it returns -1 (rather than the length - that would have been required) when the - buffer is too small. */ - size_t bigger_need = - xsum (xtimes (allocated, 2), 12); - ENSURE_ALLOCATION (bigger_need); - continue; - } - else - count = retcount; - } - } -#endif - - /* Attempt to handle failure. */ - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EINVAL; - return NULL; - } - -#if !USE_SNPRINTF - if (count >= tmp_length) - /* tmp_length was incorrectly calculated - fix the - code above! */ - abort (); -#endif - - /* Make room for the result. */ - if (count >= maxlen) - { - /* Need at least count bytes. But allocate - proportionally, to avoid looping eternally if - snprintf() reports a too small count. */ - size_t n = - xmax (xsum (length, count), xtimes (allocated, 2)); - - ENSURE_ALLOCATION (n); -#if USE_SNPRINTF - continue; -#endif - } - -#if USE_SNPRINTF - /* The snprintf() result did fit. */ -#else - /* Append the sprintf() result. */ - memcpy (result + length, tmp, count * sizeof (CHAR_T)); - if (tmp != tmpbuf) - free (tmp); -#endif - - length += count; - break; - } - } - } - } - - /* Add the final NUL. */ - ENSURE_ALLOCATION (xsum (length, 1)); - result[length] = '\0'; - - if (result != resultbuf && length + 1 < allocated) - { - /* Shrink the allocated memory if possible. */ - CHAR_T *memory; - - memory = (CHAR_T *) realloc (result, (length + 1) * sizeof (CHAR_T)); - if (memory != NULL) - result = memory; - } - - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - *lengthp = length; - if (length > INT_MAX) - goto length_overflow; - return result; - - length_overflow: - /* We could produce such a big string, but its length doesn't fit into - an 'int'. POSIX says that snprintf() fails with errno = EOVERFLOW in - this case. */ - if (result != resultbuf) - free (result); - errno = EOVERFLOW; - return NULL; - - out_of_memory: - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - out_of_memory_1: - CLEANUP (); - errno = ENOMEM; - return NULL; - } -} - -#undef SNPRINTF -#undef USE_SNPRINTF -#undef PRINTF_PARSE -#undef DIRECTIVES -#undef DIRECTIVE -#undef CHAR_T -#undef VASNPRINTF diff --git a/gl/vasnprintf.h b/gl/vasnprintf.h deleted file mode 100644 index 894008cae..000000000 --- a/gl/vasnprintf.h +++ /dev/null @@ -1,77 +0,0 @@ -/* vsprintf with automatic memory allocation. - Copyright (C) 2002-2004 Free Software Foundation, Inc. - - This program 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, or (at your option) - any later version. - - This program 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef _VASNPRINTF_H -#define _VASNPRINTF_H - -/* Get va_list. */ -#include <stdarg.h> - -/* Get size_t. */ -#include <stddef.h> - -#ifndef __attribute__ -/* This feature is available in gcc versions 2.5 and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ -# define __attribute__(Spec) /* empty */ -# endif -/* The __-protected variants of `format' and `printf' attributes - are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) -# define __format__ format -# define __printf__ printf -# endif -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* Write formatted output to a string dynamically allocated with malloc(). - You can pass a preallocated buffer for the result in RESULTBUF and its - size in *LENGTHP; otherwise you pass RESULTBUF = NULL. - If successful, return the address of the string (this may be = RESULTBUF - if no dynamic memory allocation was necessary) and set *LENGTHP to the - number of resulting bytes, excluding the trailing NUL. Upon error, set - errno and return NULL. - - When dynamic memory allocation occurs, the preallocated buffer is left - alone (with possibly modified contents). This makes it possible to use - a statically allocated or stack-allocated buffer, like this: - - char buf[100]; - size_t len = sizeof (buf); - char *output = vasnprintf (buf, &len, format, args); - if (output == NULL) - ... error handling ...; - else - { - ... use the output string ...; - if (output != buf) - free (output); - } - */ -extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...) - __attribute__ ((__format__ (__printf__, 3, 4))); -extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) - __attribute__ ((__format__ (__printf__, 3, 0))); - -#ifdef __cplusplus -} -#endif - -#endif /* _VASNPRINTF_H */ diff --git a/gl/vasprintf.c b/gl/vasprintf.c deleted file mode 100644 index 149c29242..000000000 --- a/gl/vasprintf.c +++ /dev/null @@ -1,42 +0,0 @@ -/* Formatted output to strings. - Copyright (C) 1999, 2002 Free Software Foundation, Inc. - - This program 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, or (at your option) - any later version. - - This program 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -/* Specification. */ -#include "vasprintf.h" - -#include <stdlib.h> - -#include "vasnprintf.h" - -int -vasprintf (char **resultp, const char *format, va_list args) -{ - size_t length; - char *result = vasnprintf (NULL, &length, format, args); - if (result == NULL) - return -1; - - *resultp = result; - /* Return the number of resulting bytes, excluding the trailing NUL. - If it wouldn't fit in an 'int', vasnprintf() would have returned NULL - and set errno to EOVERFLOW. */ - return length; -} diff --git a/gl/vasprintf.h b/gl/vasprintf.h deleted file mode 100644 index d02f15451..000000000 --- a/gl/vasprintf.h +++ /dev/null @@ -1,63 +0,0 @@ -/* vsprintf with automatic memory allocation. - Copyright (C) 2002-2003 Free Software Foundation, Inc. - - This program 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, or (at your option) - any later version. - - This program 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef _VASPRINTF_H -#define _VASPRINTF_H - -#if HAVE_VASPRINTF - -/* Get asprintf(), vasprintf() declarations. */ -#include <stdio.h> - -#else - -/* Get va_list. */ -#include <stdarg.h> - -#ifndef __attribute__ -/* This feature is available in gcc versions 2.5 and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ -# define __attribute__(Spec) /* empty */ -# endif -/* The __-protected variants of `format' and `printf' attributes - are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) -# define __format__ format -# define __printf__ printf -# endif -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* Write formatted output to a string dynamically allocated with malloc(). - If the memory allocation succeeds, store the address of the string in - *RESULT and return the number of resulting bytes, excluding the trailing - NUL. Upon memory allocation error, or some other error, return -1. */ -extern int asprintf (char **result, const char *format, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); -extern int vasprintf (char **result, const char *format, va_list args) - __attribute__ ((__format__ (__printf__, 2, 0))); - -#ifdef __cplusplus -} -#endif - -#endif - -#endif /* _VASPRINTF_H */ diff --git a/jnlib/ChangeLog b/jnlib/ChangeLog index 0db89e3c4..bb2d06574 100644 --- a/jnlib/ChangeLog +++ b/jnlib/ChangeLog @@ -1,3 +1,25 @@ +2007-06-06 Werner Koch <wk@g10code.com> + + * w32help.h: New. + * w32-gettext.c: New. Taken from gnupg 1.4, added ngettext, + changed to use jnlib malloc functions and put under the LGPL. + * w32-reg.c: New. Taken from../common/w32reg.c and changed to + LGPL. Changed API to use the jnlib malloc functions. + * Makefile.am (libjnlib_a_SOURCES) [!W32]: Do not build the w32 + specific modules. + + * dotlock.c: Include stringhelp.h for stpcpy prototype. + +2007-06-04 Werner Koch <wk@g10code.com> + + * dynload.h: New. Taken from ../common and changed to LGPL. + + * utf8conv.c (load_libiconv): New. Taken from GnuPG 1.4 + +2007-05-30 Werner Koch <wk@g10code.com> + + * w32-pth.h, w32-pth.c: Remove. + 2007-04-25 Werner Koch <wk@g10code.com> * argparse.c (long_opt_strlen): Fixed for utf-8. diff --git a/jnlib/Makefile.am b/jnlib/Makefile.am index 951c562f2..0f593bb3f 100644 --- a/jnlib/Makefile.am +++ b/jnlib/Makefile.am @@ -41,9 +41,12 @@ libjnlib_a_SOURCES = \ argparse.c argparse.h \ logging.c logging.h \ dotlock.c dotlock.h \ - types.h mischelp.c mischelp.h \ - w32-pth.c w32-pth.h \ - w32-afunix.c w32-afunix.h + types.h mischelp.c mischelp.h dynload.h w32help.h + +if HAVE_W32_SYSTEM +libjnlib_a_SOURCES += w32-reg.c w32-afunix.c w32-afunix.h w32-gettext.c +endif + # For GnuPG we don't need the xmalloc stuff. # xmalloc.c xmalloc.h diff --git a/jnlib/dotlock.c b/jnlib/dotlock.c index ba89bcea6..53fb52655 100644 --- a/jnlib/dotlock.c +++ b/jnlib/dotlock.c @@ -37,6 +37,7 @@ #include <signal.h> #include "libjnlib-config.h" +#include "stringhelp.h" #include "dotlock.h" #if !defined(DIRSEP_C) && !defined(EXTSEP_C) \ diff --git a/jnlib/dynload.h b/jnlib/dynload.h new file mode 100644 index 000000000..e365d4f0d --- /dev/null +++ b/jnlib/dynload.h @@ -0,0 +1,73 @@ +/* dynload.h - Wrapper functions for run-time dynamic loading + * Copyright (C) 2003 Free Software Foundation, Inc. + * + * This file is part of JNLIB. + * + * JNLIB 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. + * + * JNLIB 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., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef LIBJNLIB_DYNLOAD_H +#define LIBJNLIB_DYNLOAD_H + +#ifndef __MINGW32__ +# include <dlfcn.h> +#else +# include <windows.h> + +# define RTLD_LAZY 0 + +static inline void * +dlopen (const char * name, int flag) +{ + void * hd = LoadLibrary (name); + return hd; +} + +static inline void * +dlsym (void *hd, const char *sym) +{ + if (hd && sym) + { + void * fnc = GetProcAddress (hd, sym); + if (!fnc) + return NULL; + return fnc; + } + return NULL; +} + + +static inline const char * +dlerror (void) +{ + static char buf[32]; + sprintf (buf, "ec=%lu", GetLastError ()); + return buf; +} + + +static inline int +dlclose (void * hd) +{ + if (hd) + { + CloseHandle (hd); + return 0; + } + return -1; +} +# endif /*__MINGW32__*/ +#endif /*LIBJNLIB_DYNLOAD_H*/ diff --git a/jnlib/libjnlib-config.h b/jnlib/libjnlib-config.h index 4554b9d1a..6c9408fdb 100644 --- a/jnlib/libjnlib-config.h +++ b/jnlib/libjnlib-config.h @@ -34,11 +34,14 @@ #define JNLIB_NEED_UTF8CONV 1 + +#if !defined(JNLIB_NEED_UTF8CONV) && defined(HAVE_W32_SYSTEM) +#define JNLIB_NEED_UTF8CONV 1 +#endif + /* Gettext stuff */ #ifdef USE_SIMPLE_GETTEXT - int set_gettext_file( const char *filename ); - const char *gettext( const char *msgid ); - +# include "w32help.h" # define _(a) gettext (a) # define N_(a) (a) @@ -61,7 +64,9 @@ #endif #endif /* !USE_SIMPLE_GETTEXT */ -/* Malloc functions to be jused by jnlib. */ +/* Malloc functions to be used by jnlib. */ +#define jnlib_malloc(a) gcry_malloc( (a) ) +#define jnlib_calloc(a,b) gcry_calloc( (a), (b) ) #define jnlib_xmalloc(a) gcry_xmalloc( (a) ) #define jnlib_xcalloc(a,b) gcry_xcalloc( (a), (b) ) #define jnlib_xrealloc(a,n) gcry_xrealloc( (a), (n) ) diff --git a/jnlib/stringhelp.c b/jnlib/stringhelp.c index b74f84a9c..b7f8b28db 100644 --- a/jnlib/stringhelp.c +++ b/jnlib/stringhelp.c @@ -821,7 +821,7 @@ memrchr (const void *buffer, int c, size_t n) for (p += n; n ; n--) if (*--p == c) - return p; + return (void *)p; return NULL; } #endif /*HAVE_MEMRCHR*/ diff --git a/jnlib/utf8conv.c b/jnlib/utf8conv.c index d7c0d44ba..90a319984 100644 --- a/jnlib/utf8conv.c +++ b/jnlib/utf8conv.c @@ -29,10 +29,13 @@ #include <langinfo.h> #endif #include <errno.h> -#include <iconv.h> +#ifndef HAVE_W32_SYSTEM +# include <iconv.h> +#endif #include "libjnlib-config.h" #include "stringhelp.h" +#include "dynload.h" #include "utf8conv.h" #ifndef MB_LEN_MAX @@ -45,6 +48,58 @@ static int no_translation; /* Set to true if we let simply pass through. */ static int use_iconv; /* iconv comversion fucntions required. */ +/* Under W32 we dlopen the iconv dll and don't require any iconv + related headers at all. However we need to define some stuff. */ +#ifdef HAVE_W32_SYSTEM +typedef void *iconv_t; +#ifndef ICONV_CONST +#define ICONV_CONST const +#endif +static iconv_t (* __stdcall iconv_open) (const char *tocode, + const char *fromcode); +static size_t (* __stdcall iconv) (iconv_t cd, + const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft); +static int (* __stdcall iconv_close) (iconv_t cd); + +static int +load_libiconv (void) +{ + static int done; + + if (!done) + { + void *handle; + + done = 1; /* Do it right now because we might get called recursivly + through gettext. */ + + handle = dlopen ("iconv.dll", RTLD_LAZY); + if (handle) + { + iconv_open = dlsym (handle, "libiconv_open"); + if (iconv_open) + iconv = dlsym (handle, "libiconv"); + if (iconv) + iconv_close = dlsym (handle, "libiconv_close"); + } + if (!handle || !iconv_close) + { + log_info (_("error loading `%s': %s\n"), + "iconv.dll", dlerror ()); + log_info (_("please see http://www.gnupg.org/download/iconv.html " + "for more information\n")); + iconv_open = NULL; + iconv = NULL; + iconv_close = NULL; + if (handle) + dlclose (handle); + } + } + return iconv_open? 0: -1; +} +#endif /*HAVE_W32_SYSTEM*/ + /* Error handler for iconv failures. This is needed to not clutter the output with repeated diagnostics about a missing conversion. */ diff --git a/jnlib/w32-gettext.c b/jnlib/w32-gettext.c new file mode 100644 index 000000000..eca1ee324 --- /dev/null +++ b/jnlib/w32-gettext.c @@ -0,0 +1,556 @@ +/* w32-gettext.c - A simplified version of gettext for use under W32. + * Copyright (C) 1995, 1996, 1997, 1999, + * 2005, 2007 Free Software Foundation, Inc. + * + * This file is part of JNLIB. + * + * JNLIB 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. + * + * JNLIB 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., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +/* + This is a simplified version of gettext written by Ulrich Drepper. + It is used for the Win32 version of GnuPG becaise all the overhead + of gettext is not needed and we have to do some special Win32 + stuff. I decided that this is far easier than to tweak gettext for + the special cases (I tried it but it is a lot of code). wk 15.09.99 + */ + +#include <config.h> +#ifdef USE_SIMPLE_GETTEXT +#if !defined (_WIN32) && !defined (__CYGWIN32__) +#error This module may only be build for Windows or Cygwin32 +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <ctype.h> +#include <errno.h> +#include <sys/types.h> +#include <sys/stat.h> + +#include "libjnlib-config.h" +#include "types.h" +#include "stringhelp.h" +#include "utf8conv.h" +#include "w32help.h" + +#include "windows.h" /* For GetModuleFileName. */ + +/* The magic number of the GNU message catalog format. */ +#define MAGIC 0x950412de +#define MAGIC_SWAPPED 0xde120495 + +/* Revision number of the currently used .mo (binary) file format. */ +#define MO_REVISION_NUMBER 0 + + +/* Header for binary .mo file format. */ +struct mo_file_header +{ + /* The magic number. */ + u32 magic; + /* The revision number of the file format. */ + u32 revision; + /* The number of strings pairs. */ + u32 nstrings; + /* Offset of table with start offsets of original strings. */ + u32 orig_tab_offset; + /* Offset of table with start offsets of translation strings. */ + u32 trans_tab_offset; + /* Size of hashing table. */ + u32 hash_tab_size; + /* Offset of first hashing entry. */ + u32 hash_tab_offset; +}; + +struct string_desc +{ + /* Length of addressed string. */ + u32 length; + /* Offset of string in file. */ + u32 offset; +}; + + +struct overflow_space_s +{ + struct overflow_space_s *next; + u32 idx; + char d[1]; +}; + +struct loaded_domain +{ + char *data; + int must_swap; + u32 nstrings; + char *mapped; /* 0 = not yet mapped, 1 = mapped, + 2 = mapped to + overflow space */ + struct overflow_space_s *overflow_space; + struct string_desc *orig_tab; + struct string_desc *trans_tab; + u32 hash_size; + u32 *hash_tab; +}; + + +static struct loaded_domain *the_domain; + +static __inline__ u32 +do_swap_u32( u32 i ) +{ + return (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24); +} + +#define SWAPIT(flag, data) ((flag) ? do_swap_u32(data) : (data) ) + + +/* We assume to have `unsigned long int' value with at least 32 bits. */ +#define HASHWORDBITS 32 + +/* The so called `hashpjw' function by P.J. Weinberger + [see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools, + 1986, 1987 Bell Telephone Laboratories, Inc.] */ + +static __inline__ ulong +hash_string (const char *str_param) +{ + unsigned long int hval, g; + const char *str = str_param; + + hval = 0; + while (*str != '\0') + { + hval <<= 4; + hval += (unsigned long int) *str++; + g = hval & ((unsigned long int) 0xf << (HASHWORDBITS - 4)); + if (g != 0) + { + hval ^= g >> (HASHWORDBITS - 8); + hval ^= g; + } + } + return hval; +} + + +static struct loaded_domain * +load_domain (const char *filename) +{ + FILE *fp; + size_t size; + struct stat st; + struct mo_file_header *data = NULL; + struct loaded_domain *domain = NULL; + size_t to_read; + char *read_ptr; + + fp = fopen( filename, "rb" ); + if (!fp) + return NULL; /* Can't open the file. */ + /* We need to know the size of the file. */ + if (fstat( fileno(fp ), &st ) + || (size = (size_t)st.st_size) != st.st_size + || size < sizeof (struct mo_file_header) ) + { + fclose (fp); + return NULL; + } + + data = jnlib_malloc (size); + if (!data) + { + fclose (fp); + return NULL; /* Out of memory. */ + } + + to_read = size; + read_ptr = (char *) data; + do + { + long int nb; + + nb = fread (read_ptr, 1, to_read, fp); + if (nb < to_read ) + { + fclose (fp); + jnlib_free (data); + return NULL; /* Read error. */ + } + read_ptr += nb; + to_read -= nb; + } + while (to_read > 0); + fclose (fp); + + /* Using the magic number we test whether it is really a message + catalog file. */ + if (data->magic != MAGIC && data->magic != MAGIC_SWAPPED) + { + /* The magic number is wrong: not a message catalog file. */ + jnlib_free (data); + return NULL; + } + + domain = jnlib_calloc (1, sizeof *domain); + if (!domain) + { + jnlib_free (data); + return NULL; + } + domain->data = (char *) data; + domain->must_swap = data->magic != MAGIC; + + /* Fill in the information about the available tables. */ + switch (SWAPIT(domain->must_swap, data->revision)) + { + case 0: + domain->nstrings = SWAPIT(domain->must_swap, data->nstrings); + domain->orig_tab = (struct string_desc *) + ((char *) data + SWAPIT(domain->must_swap, data->orig_tab_offset)); + domain->trans_tab = (struct string_desc *) + ((char *) data + SWAPIT(domain->must_swap, data->trans_tab_offset)); + domain->hash_size = SWAPIT(domain->must_swap, data->hash_tab_size); + domain->hash_tab = (u32 *) + ((char *) data + SWAPIT(domain->must_swap, data->hash_tab_offset)); + break; + + default: /* This is an invalid revision. */ + jnlib_free( data ); + jnlib_free( domain ); + return NULL; + } + + /* Allocate an array to keep track of code page mappings. */ + domain->mapped = jnlib_calloc (1, domain->nstrings); + if (!domain->mapped) + { + jnlib_free (data); + jnlib_free (domain); + return NULL; + } + + return domain; +} + + +/* Set the file used for translations. Pass a NULL to disable + translation. A new filename may be set at anytime. WARNING: After + changing the filename you should not access any data retrieved by + gettext(). + + If REGKEY is not NULL, the function tries to selected the language + the registry key "Lang" below that key. If in addition the + environment variable LANGUAGE has been set, that value will + override a value set by the registry key. + */ +int +set_gettext_file ( const char *filename, const char *regkey ) +{ + struct loaded_domain *domain = NULL; + + if ( filename && *filename ) + { + if ( filename[0] == '/' +#ifdef HAVE_DRIVE_LETTERS + || ( isalpha(filename[0]) + && filename[1] == ':' + && (filename[2] == '/' || filename[2] == '\\') ) +#endif + ) + { + /* absolute path - use it as is */ + domain = load_domain( filename ); + } + else if (regkey) /* Standard. */ + { + char *instdir, *langid, *fname; + char *p; + int envvar_mode = 0; + + again: + if (!envvar_mode && (p = getenv ("LANGUAGE")) && *p) + { + envvar_mode = 1; + langid = jnlib_malloc (strlen (p)+1); + if (!langid) + return -1; + strcpy (langid, p); + /* We only make use of the first language given. Strip + the rest. */ + p = strchr (langid, ':'); + if (p) + *p = 0; + + /* In the $LANGUAGE case we do not use the registered + installation directory but the one where the gpg + binary has been found. */ + instdir = jnlib_malloc (MAX_PATH+5); + if ( !instdir || !GetModuleFileName (NULL, instdir, MAX_PATH) ) + { + jnlib_free (langid); + jnlib_free (instdir); + return -1; /* Error getting the process' file name. */ + } + p = strrchr (instdir, DIRSEP_C); + if (!p) + { + jnlib_free (langid); + jnlib_free (instdir); + return -1; /* Invalid file name returned. */ + } + *p = 0; + } + else + { + instdir = read_w32_registry_string ("HKEY_LOCAL_MACHINE", + regkey, + "Install Directory"); + if (!instdir) + return -1; + langid = read_w32_registry_string (NULL, /* HKCU then HKLM */ + regkey, + "Lang"); + if (!langid) + { + jnlib_free (instdir); + return -1; + } + } + + /* Strip stuff after a dot in case the user tried to enter + the entire locale syntacs as usual for POSIX. */ + p = strchr (langid, '.'); + if (p) + *p = 0; + + /* Build the key: "<instdir>/<domain>.nls/<langid>.mo" We + use a directory below the installation directory with the + domain included in case the software has been insalled + with other software altogether at the same place. */ + fname = jnlib_malloc (strlen (instdir) + 1 + strlen (filename) + 5 + + strlen (langid) + 3 + 1); + if (!fname) + { + jnlib_free (instdir); + jnlib_free (langid); + return -1; + } + strcpy (stpcpy (stpcpy (stpcpy (stpcpy ( stpcpy (fname, + instdir),"\\"), filename), ".nls\\"), langid), ".mo"); + jnlib_free (instdir); + jnlib_free (langid); + + /* Better make sure that we don't mix forward and backward + slashes. It seems that some Windoze versions don't + accept this. */ + for (p=fname; *p; p++) + { + if (*p == '/') + *p = '\\'; + } + domain = load_domain (fname); + jnlib_free(fname); + + if (!domain && envvar_mode == 1) + { + /* In case it failed, we try again using the registry + method. */ + envvar_mode++; + goto again; + } + } + + + if (!domain) + return -1; + } + + if ( the_domain ) + { + struct overflow_space_s *os, *os2; + + jnlib_free ( the_domain->data ); + jnlib_free ( the_domain->mapped ); + for (os=the_domain->overflow_space; os; os = os2) + { + os2 = os->next; + jnlib_free (os); + } + jnlib_free ( the_domain ); + the_domain = NULL; + } + the_domain = domain; + return 0; +} + + +static const char* +get_string( struct loaded_domain *domain, u32 idx ) +{ + struct overflow_space_s *os; + char *p; + + p = domain->data + SWAPIT(domain->must_swap, domain->trans_tab[idx].offset); + if (!domain->mapped[idx]) + { + size_t plen, buflen; + char *buf; + + domain->mapped[idx] = 1; + + plen = strlen (p); + buf = utf8_to_native (p, plen, -1); + buflen = strlen (buf); + if (buflen <= plen) + strcpy (p, buf); + else + { + /* There is not enough space for the translation - store it + in the overflow_space else and mark that in the mapped + array. Because we expect that this won't happen too + often, we use a simple linked list. */ + os = jnlib_malloc (sizeof *os + buflen); + if (os) + { + os->idx = idx; + strcpy (os->d, buf); + os->next = domain->overflow_space; + domain->overflow_space = os; + p = os->d; + } + else + p = "ERROR in GETTEXT MALLOC"; + } + jnlib_free (buf); + } + else if (domain->mapped[idx] == 2) + { /* We need to get the string from the overflow_space. */ + for (os=domain->overflow_space; os; os = os->next) + if (os->idx == idx) + return (const char*)os->d; + p = "ERROR in GETTEXT\n"; + } + return (const char*)p; +} + + + +const char * +gettext( const char *msgid ) +{ + struct loaded_domain *domain; + size_t act = 0; + size_t top, bottom; + + if (!(domain = the_domain)) + goto not_found; + + /* Locate the MSGID and its translation. */ + if (domain->hash_size > 2 && domain->hash_tab) + { + /* Use the hashing table. */ + u32 len = strlen (msgid); + u32 hash_val = hash_string (msgid); + u32 idx = hash_val % domain->hash_size; + u32 incr = 1 + (hash_val % (domain->hash_size - 2)); + u32 nstr = SWAPIT (domain->must_swap, domain->hash_tab[idx]); + + if ( !nstr ) /* Hash table entry is empty. */ + goto not_found; + + if (SWAPIT(domain->must_swap, + domain->orig_tab[nstr - 1].length) == len + && !strcmp (msgid, + domain->data + SWAPIT(domain->must_swap, + domain->orig_tab[nstr-1].offset))) + return get_string( domain, nstr - 1 ); + + for (;;) + { + if (idx >= domain->hash_size - incr) + idx -= domain->hash_size - incr; + else + idx += incr; + + nstr = SWAPIT (domain->must_swap, domain->hash_tab[idx]); + if (!nstr) + goto not_found; /* Hash table entry is empty. */ + + if ( SWAPIT(domain->must_swap, + domain->orig_tab[nstr - 1].length) == len + && !strcmp (msgid, + domain->data + + SWAPIT(domain->must_swap, + domain->orig_tab[nstr-1].offset))) + return get_string( domain, nstr-1 ); + } + /*NOTREACHED*/ + } + + /* Now we try the default method: binary search in the sorted array + of messages. */ + bottom = 0; + top = domain->nstrings; + while (bottom < top) + { + int cmp_val; + + act = (bottom + top) / 2; + cmp_val = strcmp(msgid, domain->data + + SWAPIT(domain->must_swap, + domain->orig_tab[act].offset)); + if (cmp_val < 0) + top = act; + else if (cmp_val > 0) + bottom = act + 1; + else + return get_string (domain, act); + } + + not_found: + return msgid; +} + + +const char * +ngettext (const char *msgid1, const char *msgid2, unsigned long int n) +{ + /* We use the simple Germanic plural rule. */ + return gettext (n==1? msgid1 : msgid2); +} + + + +#if 0 + unsigned int cp1, cp2; + + cp1 = GetConsoleCP(); + cp2 = GetConsoleOutputCP(); + + log_info("InputCP=%u OutputCP=%u\n", cp1, cp2 ); + + if( !SetConsoleOutputCP( 1252 ) ) + log_info("SetConsoleOutputCP failed: %s\n", w32_strerror (0)); + + cp1 = GetConsoleCP(); + cp2 = GetConsoleOutputCP(); + log_info("InputCP=%u OutputCP=%u after switch1\n", cp1, cp2 ); +#endif + +#endif /* USE_SIMPLE_GETTEXT */ diff --git a/jnlib/w32-pth.c b/jnlib/w32-pth.c deleted file mode 100644 index 0ef4d9e4e..000000000 --- a/jnlib/w32-pth.c +++ /dev/null @@ -1,1500 +0,0 @@ -/* w32-pth.c - GNU Pth emulation for W32 (MS Windows). - * Copyright (c) 1999-2003 Ralf S. Engelschall <rse@engelschall.com> - * Copyright (C) 2004, 2006 g10 Code GmbH - * - * This file is part of JNLIB. - * - * JNLIB 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. - * - * JNLIB 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., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - * - * ------------------------------------------------------------------ - * This code is based on Ralf Engelschall's GNU Pth, a non-preemptive - * thread scheduling library which can be found at - * http://www.gnu.org/software/pth/. MS Windows (W32) specific code - * written by Timo Schulz, g10 Code. - */ - -#include <config.h> -#ifdef HAVE_W32_SYSTEM -#include <windows.h> -#include <stdio.h> -#include <stdlib.h> -#include <io.h> -#include <signal.h> - -#include "logging.h" /* For log_get_prefix () */ - -/* We don't want to have any Windows specific code in the header, thus - we use a macro which defaults to a compatible type in w32-pth.h. */ -#define W32_PTH_HANDLE_INTERNAL HANDLE -#include "w32-pth.h" - - -#ifndef FALSE -#define FALSE 0 -#endif -#ifndef TRUE -#define TRUE 1 -#endif -#if FALSE != 0 || TRUE != 1 -#error TRUE or FALSE defined to wrong values -#endif - - -/* States whether this module has been initialized. */ -static int pth_initialized; - -/* Keeps the current debug level. Define marcos to test them. */ -static int debug_level; -#define DBG_ERROR (debug_level >= 1) -#define DBG_INFO (debug_level >= 2) -#define DBG_CALLS (debug_level >= 3) - -/* Variables to support event handling. */ -static int pth_signo; -static HANDLE pth_signo_ev; - -/* Mutex to make sure only one thread is running. */ -static CRITICAL_SECTION pth_shd; - -/* Events are store in a double linked event ring. */ -struct pth_event_s -{ - struct pth_event_s * next; - struct pth_event_s * prev; - HANDLE hd; - union - { - struct sigset_s * sig; - int fd; - struct timeval tv; - pth_mutex_t * mx; - } u; - int * val; - int u_type; - int flags; -}; - - -struct pth_attr_s -{ - unsigned int flags; - unsigned int stack_size; - char * name; -}; - - -/* Object to keep information about a thread. This may eventually be - used to implement a scheduler queue. */ -struct thread_info_s -{ - void *(*thread)(void *); /* The actual thread fucntion. */ - void * arg; /* The argument passed to that fucntion. */ - int joinable; /* True if this Thread is joinable. */ - HANDLE th; /* Handle of this thread. Used by non-joinable - threads to close the handle. */ -}; - - -/* Convenience macro to startup the system. */ -#define implicit_init() do { if (!pth_initialized) pth_init(); } while (0) - -/* Prototypes. */ -static pth_event_t do_pth_event (unsigned long spec, ...); -static unsigned int do_pth_waitpid (unsigned pid, int * status, int options); -static int do_pth_wait (pth_event_t ev); -static int do_pth_event_status (pth_event_t ev); -static void *launch_thread (void * ctx); - - - - -int -pth_init (void) -{ - SECURITY_ATTRIBUTES sa; - WSADATA wsadat; - const char *s; - - if (pth_initialized) - return TRUE; - - debug_level = (s=getenv ("DEBUG_PTH"))? atoi (s):0; - if (debug_level) - fprintf (stderr, "%s: pth_init: called.\n", log_get_prefix (NULL)); - - if (WSAStartup (0x202, &wsadat)) - return FALSE; - pth_signo = 0; - InitializeCriticalSection (&pth_shd); - if (pth_signo_ev) - CloseHandle (pth_signo_ev); - memset (&sa, 0, sizeof sa); - sa.bInheritHandle = TRUE; - sa.lpSecurityDescriptor = NULL; - sa.nLength = sizeof sa; - pth_signo_ev = CreateEvent (&sa, TRUE, FALSE, NULL); - if (!pth_signo_ev) - return FALSE; - - pth_initialized = 1; - EnterCriticalSection (&pth_shd); - return TRUE; -} - - -int -pth_kill (void) -{ - pth_signo = 0; - if (pth_signo_ev) - { - CloseHandle (pth_signo_ev); - pth_signo_ev = NULL; - } - if (pth_initialized) - DeleteCriticalSection (&pth_shd); - WSACleanup (); - pth_initialized = 0; - return TRUE; -} - - -static char * -w32_strerror (char *strerr, size_t strerrsize) -{ - if (strerrsize > 1) - FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, (int)GetLastError (), - MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), - strerr, strerrsize, NULL); - return strerr; -} - - -static void -enter_pth (const char *function) -{ - /* Fixme: I am not sure whether the same thread my enter a critical - section twice. */ - if (DBG_CALLS) - fprintf (stderr, "%s: enter_pth (%s)\n", - log_get_prefix (NULL), function? function:""); - LeaveCriticalSection (&pth_shd); -} - - -static void -leave_pth (const char *function) -{ - EnterCriticalSection (&pth_shd); - if (DBG_CALLS) - fprintf (stderr, "%s: leave_pth (%s)\n", - log_get_prefix (NULL), function? function:""); -} - - -long -pth_ctrl (unsigned long query, ...) -{ - implicit_init (); - - switch (query) - { - case PTH_CTRL_GETAVLOAD: - case PTH_CTRL_GETPRIO: - case PTH_CTRL_GETNAME: - case PTH_CTRL_GETTHREADS_NEW: - case PTH_CTRL_GETTHREADS_READY: - case PTH_CTRL_GETTHREADS_RUNNING: - case PTH_CTRL_GETTHREADS_WAITING: - case PTH_CTRL_GETTHREADS_SUSPENDED: - case PTH_CTRL_GETTHREADS_DEAD: - case PTH_CTRL_GETTHREADS: - default: - return -1; - } - return 0; -} - - - -pth_time_t -pth_timeout (long sec, long usec) -{ - pth_time_t tvd; - - tvd.tv_sec = sec; - tvd.tv_usec = usec; - return tvd; -} - - -int -pth_read_ev (int fd, void *buffer, size_t size, pth_event_t ev) -{ - implicit_init (); - return 0; -} - - -int -pth_read (int fd, void * buffer, size_t size) -{ - int n; - - implicit_init (); - enter_pth (__FUNCTION__); - - n = recv (fd, buffer, size, 0); - if (n == -1 && WSAGetLastError () == WSAENOTSOCK) - { - DWORD nread = 0; - n = ReadFile ((HANDLE)fd, buffer, size, &nread, NULL); - if (!n) - { - char strerr[256]; - - if (DBG_ERROR) - fprintf (stderr, "%s: pth_read(%d) failed read from file: %s\n", - log_get_prefix (NULL), fd, - w32_strerror (strerr, sizeof strerr)); - n = -1; - } - else - n = (int)nread; - } - leave_pth (__FUNCTION__); - return n; -} - - -int -pth_write_ev (int fd, const void *buffer, size_t size, pth_event_t ev) -{ - implicit_init (); - return 0; -} - - -int -pth_write (int fd, const void * buffer, size_t size) -{ - int n; - - implicit_init (); - enter_pth (__FUNCTION__); - n = send (fd, buffer, size, 0); - if (n == -1 && WSAGetLastError () == WSAENOTSOCK) - { - DWORD nwrite; - char strerr[256]; - - /* This is no real error because we first need to figure out if - we have a handle or a socket. */ - - n = WriteFile ((HANDLE)fd, buffer, size, &nwrite, NULL); - if (!n) - { - if (DBG_ERROR) - fprintf (stderr, "%s: pth_write(%d) failed in write: %s\n", - log_get_prefix (NULL), fd, - w32_strerror (strerr, sizeof strerr)); - n = -1; - } - else - n = (int)nwrite; - } - leave_pth (__FUNCTION__); - return n; -} - - -int -pth_select (int nfds, fd_set * rfds, fd_set * wfds, fd_set * efds, - const struct timeval * timeout) -{ - int n; - - implicit_init (); - enter_pth (__FUNCTION__); - n = select (nfds, rfds, wfds, efds, timeout); - leave_pth (__FUNCTION__); - return n; -} - - -int -pth_fdmode (int fd, int mode) -{ - unsigned long val; - int ret = PTH_FDMODE_BLOCK; - - implicit_init (); - /* Note: we don't do the eter/leave pth here because this is for one - a fast fucntion and secondly already called from inside such a - block. */ - /* XXX: figure out original fd mode */ - switch (mode) - { - case PTH_FDMODE_NONBLOCK: - val = 1; - if (ioctlsocket (fd, FIONBIO, &val) == SOCKET_ERROR) - ret = PTH_FDMODE_ERROR; - break; - - case PTH_FDMODE_BLOCK: - val = 0; - if (ioctlsocket (fd, FIONBIO, &val) == SOCKET_ERROR) - ret = PTH_FDMODE_ERROR; - break; - } - return ret; -} - - -int -pth_accept (int fd, struct sockaddr *addr, int *addrlen) -{ - int rc; - - implicit_init (); - enter_pth (__FUNCTION__); - rc = accept (fd, addr, addrlen); - leave_pth (__FUNCTION__); - return rc; -} - - -int -pth_accept_ev (int fd, struct sockaddr *addr, int *addrlen, - pth_event_t ev_extra) -{ - pth_key_t ev_key; - pth_event_t ev; - int rv; - int fdmode; - - implicit_init (); - enter_pth (__FUNCTION__); - - fdmode = pth_fdmode (fd, PTH_FDMODE_NONBLOCK); - if (fdmode == PTH_FDMODE_ERROR) - { - leave_pth (__FUNCTION__); - return -1; - } - - ev = NULL; - while ((rv = accept (fd, addr, addrlen)) == -1 && - (WSAGetLastError () == WSAEINPROGRESS || - WSAGetLastError () == WSAEWOULDBLOCK)) - { - if (!ev) - { - ev = do_pth_event (PTH_EVENT_FD|PTH_UNTIL_FD_READABLE| - PTH_MODE_STATIC, &ev_key, fd); - if (!ev) - { - leave_pth (__FUNCTION__); - return -1; - } - if (ev_extra) - pth_event_concat (ev, ev_extra, NULL); - } - /* Wait until accept has a chance. */ - do_pth_wait (ev); - if (ev_extra) - { - pth_event_isolate (ev); - if (do_pth_event_status (ev) != PTH_STATUS_OCCURRED) - { - pth_fdmode (fd, fdmode); - leave_pth (__FUNCTION__); - return -1; - } - } - } - - pth_fdmode (fd, fdmode); - leave_pth (__FUNCTION__); - return rv; -} - - -int -pth_connect (int fd, struct sockaddr *name, int namelen) -{ - int rc; - - implicit_init (); - enter_pth (__FUNCTION__); - rc = connect (fd, name, namelen); - leave_pth (__FUNCTION__); - return rc; -} - - -int -pth_mutex_release (pth_mutex_t *mutex) -{ - int rc; - - implicit_init (); - enter_pth (__FUNCTION__); - - if (!ReleaseMutex (*mutex)) - { - char strerr[256]; - - if (DBG_ERROR) - fprintf (stderr, "%s: pth_release_mutex %p failed: %s\n", - log_get_prefix (NULL), *mutex, - w32_strerror (strerr, sizeof strerr)); - rc = FALSE; - } - else - rc = TRUE; - - leave_pth (__FUNCTION__); - return rc; -} - - -int -pth_mutex_acquire (pth_mutex_t *mutex, int tryonly, pth_event_t ev_extra) -{ - int code; - int rc; - - implicit_init (); - enter_pth (__FUNCTION__); - - /* FIXME: ev_extra is not yet supported. */ - - code = WaitForSingleObject (*mutex, INFINITE); - switch (code) - { - case WAIT_FAILED: - { - char strerr[256]; - - if (DBG_ERROR) - fprintf (stderr, "%s: pth_mutex_acquire for %p failed: %s\n", - log_get_prefix (NULL), *mutex, - w32_strerror (strerr, sizeof strerr)); - } - rc = FALSE; - break; - - case WAIT_OBJECT_0: - rc = TRUE; - break; - - default: - if (DBG_ERROR) - fprintf (stderr, "%s: WaitForSingleObject returned unexpected " - "code %d for mutex %p\n", - log_get_prefix (NULL), code, *mutex); - rc = FALSE; - break; - } - - leave_pth (__FUNCTION__); - return rc; -} - - - -int -pth_mutex_init (pth_mutex_t *mutex) -{ - SECURITY_ATTRIBUTES sa; - - implicit_init (); - enter_pth (__FUNCTION__); - - memset (&sa, 0, sizeof sa); - sa.bInheritHandle = TRUE; - sa.lpSecurityDescriptor = NULL; - sa.nLength = sizeof sa; - *mutex = CreateMutex (&sa, FALSE, NULL); - if (!*mutex) - { - free (*mutex); - *mutex = NULL; - leave_pth (__FUNCTION__); - return FALSE; - } - - leave_pth (__FUNCTION__); - return TRUE; -} - - -pth_attr_t -pth_attr_new (void) -{ - pth_attr_t hd; - - implicit_init (); - hd = calloc (1, sizeof *hd); - return hd; -} - - -int -pth_attr_destroy (pth_attr_t hd) -{ - if (!hd) - return -1; - implicit_init (); - if (hd->name) - free (hd->name); - free (hd); - return TRUE; -} - - -int -pth_attr_set (pth_attr_t hd, int field, ...) -{ - va_list args; - char * str; - int val; - int rc = TRUE; - - implicit_init (); - - va_start (args, field); - switch (field) - { - case PTH_ATTR_JOINABLE: - val = va_arg (args, int); - if (val) - { - hd->flags |= PTH_ATTR_JOINABLE; - if (DBG_INFO) - fprintf (stderr, "%s: pth_attr_set: PTH_ATTR_JOINABLE\n", - log_get_prefix (NULL)); - } - break; - - case PTH_ATTR_STACK_SIZE: - val = va_arg (args, int); - if (val) - { - hd->flags |= PTH_ATTR_STACK_SIZE; - hd->stack_size = val; - if (DBG_INFO) - fprintf (stderr, "%s: pth_attr_set: PTH_ATTR_STACK_SIZE %d\n", - log_get_prefix (NULL), val); - } - break; - - case PTH_ATTR_NAME: - str = va_arg (args, char*); - if (hd->name) - free (hd->name); - if (str) - { - hd->name = strdup (str); - if (!hd->name) - return FALSE; - hd->flags |= PTH_ATTR_NAME; - if (DBG_INFO) - fprintf (stderr, "%s: pth_attr_set: PTH_ATTR_NAME %s\n", - log_get_prefix (NULL), hd->name); - } - break; - - default: - rc = FALSE; - break; - } - va_end (args); - return rc; -} - - -static pth_t -do_pth_spawn (pth_attr_t hd, void *(*func)(void *), void *arg) -{ - SECURITY_ATTRIBUTES sa; - DWORD tid; - HANDLE th; - struct thread_info_s *ctx; - - if (!hd) - return NULL; - - memset (&sa, 0, sizeof sa); - sa.bInheritHandle = TRUE; - sa.lpSecurityDescriptor = NULL; - sa.nLength = sizeof sa; - - ctx = calloc (1, sizeof *ctx); - if (!ctx) - return NULL; - ctx->thread = func; - ctx->arg = arg; - ctx->joinable = (hd->flags & PTH_ATTR_JOINABLE); - - /* XXX: we don't use all thread attributes. */ - - /* Note that we create the thread suspended so that we are able to - store the thread's handle in the context structure. We need to - do this to be able to close the handle from the launch helper. - - FIXME: We should no use th W32's Thread handle directly but keep - our own thread control structure. CTX may be used for that. */ - if (DBG_INFO) - fprintf (stderr, "%s: do_pth_spawn creating thread ...\n", - log_get_prefix (NULL)); - th = CreateThread (&sa, hd->stack_size, - (LPTHREAD_START_ROUTINE)launch_thread, - ctx, CREATE_SUSPENDED, &tid); - ctx->th = th; - if (DBG_INFO) - fprintf (stderr, "%s: do_pth_spawn created thread %p\n", - log_get_prefix (NULL),th); - if (!th) - free (ctx); - else - ResumeThread (th); - - return th; -} - -pth_t -pth_spawn (pth_attr_t hd, void *(*func)(void *), void *arg) -{ - HANDLE th; - - if (!hd) - return NULL; - - implicit_init (); - enter_pth (__FUNCTION__); - th = do_pth_spawn (hd, func, arg); - leave_pth (__FUNCTION__); - return th; -} - - -pth_t -pth_self (void) -{ - return GetCurrentThread (); -} - -int -pth_join (pth_t hd, void **value) -{ - return TRUE; -} - - -/* friendly */ -int -pth_cancel (pth_t hd) -{ - if (!hd) - return -1; - implicit_init (); - enter_pth (__FUNCTION__); - WaitForSingleObject (hd, 1000); - TerminateThread (hd, 0); - leave_pth (__FUNCTION__); - return TRUE; -} - - -/* cruel */ -int -pth_abort (pth_t hd) -{ - if (!hd) - return -1; - implicit_init (); - enter_pth (__FUNCTION__); - TerminateThread (hd, 0); - leave_pth (__FUNCTION__); - return TRUE; -} - - -void -pth_exit (void *value) -{ - implicit_init (); - enter_pth (__FUNCTION__); - pth_kill (); - leave_pth (__FUNCTION__); - exit ((int)(long)value); -} - - -static unsigned int -do_pth_waitpid (unsigned pid, int * status, int options) -{ -#if 0 - pth_event_t ev; - static pth_key_t ev_key = PTH_KEY_INIT; - pid_t pid; - - pth_debug2("pth_waitpid: called from thread \"%s\"", pth_current->name); - - for (;;) - { - /* do a non-blocking poll for the pid */ - while ( (pid = pth_sc(waitpid)(wpid, status, options|WNOHANG)) < 0 - && errno == EINTR) - ; - - /* if pid was found or caller requested a polling return immediately */ - if (pid == -1 || pid > 0 || (pid == 0 && (options & WNOHANG))) - break; - - /* else wait a little bit */ - ev = pth_event(PTH_EVENT_TIME|PTH_MODE_STATIC, &ev_key, - pth_timeout (0,250000)); - pth_wait(ev); - } - - pth_debug2("pth_waitpid: leave to thread \"%s\"", pth_current->name); -#endif - return 0; -} - - -unsigned int -pth_waitpid (unsigned pid, int * status, int options) -{ - unsigned int n; - - implicit_init (); - enter_pth (__FUNCTION__); - n = do_pth_waitpid (pid, status, options); - leave_pth (__FUNCTION__); - return n; -} - - -static BOOL WINAPI -sig_handler (DWORD signo) -{ - switch (signo) - { - case CTRL_C_EVENT: pth_signo = SIGINT; break; - case CTRL_BREAK_EVENT: pth_signo = SIGTERM; break; - } - SetEvent (pth_signo_ev); - if (DBG_INFO) - fprintf (stderr, "%s: sig_handler=%d\n", log_get_prefix (NULL), pth_signo); - return TRUE; -} - - -static pth_event_t -do_pth_event_body (unsigned long spec, va_list arg) -{ - SECURITY_ATTRIBUTES sa; - pth_event_t ev; - int rc; - - if (DBG_INFO) - fprintf (stderr, "%s: pth_event spec=%lu\n", log_get_prefix (NULL), spec); - ev = calloc (1, sizeof *ev); - if (!ev) - return NULL; - if (spec == 0) - ; - else if (spec & PTH_EVENT_SIGS) - { - ev->u.sig = va_arg (arg, struct sigset_s *); - ev->u_type = PTH_EVENT_SIGS; - ev->val = va_arg (arg, int *); - rc = SetConsoleCtrlHandler (sig_handler, TRUE); - if (DBG_INFO) - fprintf (stderr, "%s: pth_event: sigs rc=%d\n", - log_get_prefix (NULL), rc); - } - else if (spec & PTH_EVENT_FD) - { - if (spec & PTH_UNTIL_FD_READABLE) - ev->flags |= PTH_UNTIL_FD_READABLE; - if (spec & PTH_MODE_STATIC) - ev->flags |= PTH_MODE_STATIC; - ev->u_type = PTH_EVENT_FD; - va_arg (arg, pth_key_t); - ev->u.fd = va_arg (arg, int); - if (DBG_INFO) - fprintf (stderr, "%s: pth_event: fd=%d\n", - log_get_prefix (NULL), ev->u.fd); - } - else if (spec & PTH_EVENT_TIME) - { - pth_time_t t; - if (spec & PTH_MODE_STATIC) - ev->flags |= PTH_MODE_STATIC; - va_arg (arg, pth_key_t); - t = va_arg (arg, pth_time_t); - ev->u_type = PTH_EVENT_TIME; - ev->u.tv.tv_sec = t.tv_sec; - ev->u.tv.tv_usec = t.tv_usec; - } - else if (spec & PTH_EVENT_MUTEX) - { - va_arg (arg, pth_key_t); - ev->u_type = PTH_EVENT_MUTEX; - ev->u.mx = va_arg (arg, pth_mutex_t*); - } - - memset (&sa, 0, sizeof sa); - sa.bInheritHandle = TRUE; - sa.lpSecurityDescriptor = NULL; - sa.nLength = sizeof sa; - ev->hd = CreateEvent (&sa, FALSE, FALSE, NULL); - if (!ev->hd) - { - free (ev); - return NULL; - } - ev->next = ev; - ev->prev = ev; - - return ev; -} - -static pth_event_t -do_pth_event (unsigned long spec, ...) -{ - va_list arg; - pth_event_t ev; - - va_start (arg, spec); - ev = do_pth_event_body (spec, arg); - va_end (arg); - - return ev; -} - -pth_event_t -pth_event (unsigned long spec, ...) -{ - va_list arg; - pth_event_t ev; - - implicit_init (); - enter_pth (__FUNCTION__); - - va_start (arg, spec); - ev = do_pth_event_body (spec, arg); - va_end (arg); - - leave_pth (__FUNCTION__); - return ev; -} - - -static void -pth_event_add (pth_event_t root, pth_event_t node) -{ - pth_event_t n; - - for (n=root; n->next; n = n->next) - ; - n->next = node; -} - - -pth_event_t -pth_event_concat (pth_event_t evf, ...) -{ - pth_event_t evn; - va_list ap; - - if (!evf) - return NULL; - - implicit_init (); - - va_start (ap, evf); - while ((evn = va_arg(ap, pth_event_t)) != NULL) - pth_event_add (evf, evn); - va_end (ap); - - return evf; -} - - -static int -wait_for_fd (int fd, int is_read, int nwait) -{ - struct timeval tv; - fd_set r; - fd_set w; - int n; - - FD_ZERO (&r); - FD_ZERO (&w); - FD_SET (fd, is_read ? &r : &w); - - tv.tv_sec = nwait; - tv.tv_usec = 0; - - while (1) - { - n = select (fd+1, &r, &w, NULL, &tv); - if (DBG_INFO) - fprintf (stderr, "%s: wait_for_fd=%d fd %d (ec=%d)\n", - log_get_prefix (NULL), n, fd,(int)WSAGetLastError ()); - if (n == -1) - break; - if (!n) - continue; - if (n == 1) - { - if (is_read && FD_ISSET (fd, &r)) - break; - else if (FD_ISSET (fd, &w)) - break; - } - } - return 0; -} - - -static void * -launch_thread (void *arg) -{ - struct thread_info_s *c = arg; - - if (c) - { - leave_pth (__FUNCTION__); - c->thread (c->arg); - if (!c->joinable && c->th) - { - CloseHandle (c->th); - c->th = NULL; - } - /* FIXME: We would badly fail if someone accesses the now - deallocated handle. Don't use it directly but setup proper - scheduling queues. */ - enter_pth (__FUNCTION__); - free (c); - } - ExitThread (0); - return NULL; -} - -/* void */ -/* sigemptyset (struct sigset_s * ss) */ -/* { */ -/* if (ss) { */ -/* memset (ss->sigs, 0, sizeof ss->sigs); */ -/* ss->idx = 0; */ -/* } */ -/* } */ - - -/* int */ -/* sigaddset (struct sigset_s * ss, int signo) */ -/* { */ -/* if (!ss) */ -/* return -1; */ -/* if (ss->idx + 1 > 64) */ -/* return -1; */ -/* ss->sigs[ss->idx] = signo; */ -/* ss->idx++; */ -/* return 0; */ -/* } */ - - -static int -sigpresent (struct sigset_s * ss, int signo) -{ -/* int i; */ -/* for (i=0; i < ss->idx; i++) { */ -/* if (ss->sigs[i] == signo) */ -/* return 1; */ -/* } */ -/* FIXME: See how to implement it. */ - return 0; -} - - -static int -do_pth_event_occurred (pth_event_t ev) -{ - int ret; - - if (!ev) - return 0; - - ret = 0; - switch (ev->u_type) - { - case 0: - if (WaitForSingleObject (ev->hd, 0) == WAIT_OBJECT_0) - ret = 1; - break; - - case PTH_EVENT_SIGS: - if (sigpresent (ev->u.sig, pth_signo) && - WaitForSingleObject (pth_signo_ev, 0) == WAIT_OBJECT_0) - { - if (DBG_INFO) - fprintf (stderr, "%s: pth_event_occurred: sig signaled.\n", - log_get_prefix (NULL)); - (*ev->val) = pth_signo; - ret = 1; - } - break; - - case PTH_EVENT_FD: - if (WaitForSingleObject (ev->hd, 0) == WAIT_OBJECT_0) - ret = 1; - break; - } - - return ret; -} - - -int -pth_event_occurred (pth_event_t ev) -{ - int ret; - - implicit_init (); - enter_pth (__FUNCTION__); - ret = do_pth_event_occurred (ev); - leave_pth (__FUNCTION__); - return ret; -} - - -static int -do_pth_event_status (pth_event_t ev) -{ - if (!ev) - return 0; - if (do_pth_event_occurred (ev)) - return PTH_STATUS_OCCURRED; - return 0; -} - -int -pth_event_status (pth_event_t ev) -{ - if (!ev) - return 0; - if (pth_event_occurred (ev)) - return PTH_STATUS_OCCURRED; - return 0; -} - - -static int -do_pth_event_free (pth_event_t ev, int mode) -{ - if (!ev) - return FALSE; - - if (mode == PTH_FREE_ALL) - { - pth_event_t cur = ev; - do - { - pth_event_t next = cur->next; - CloseHandle (cur->hd); - cur->hd = NULL; - free (cur); - cur = next; - } - while (cur != ev); - } - else if (mode == PTH_FREE_THIS) - { - ev->prev->next = ev->next; - ev->next->prev = ev->prev; - CloseHandle (ev->hd); - ev->hd = NULL; - free (ev); - } - else - return FALSE; - - return TRUE; -} - -int -pth_event_free (pth_event_t ev, int mode) -{ - int rc; - - implicit_init (); - enter_pth (__FUNCTION__); - rc = do_pth_event_free (ev, mode); - leave_pth (__FUNCTION__); - return rc; -} - - -pth_event_t -pth_event_isolate (pth_event_t ev) -{ - pth_event_t ring; - - if (!ev) - return NULL; - if (ev->next == ev && ev->prev == ev) - return NULL; /* Only one event. */ - - ring = ev->next; - ev->prev->next = ev->next; - ev->next->prev = ev->prev; - ev->prev = ev; - ev->next = ev; - return ring; -} - - -static int -event_count (pth_event_t ev) -{ - pth_event_t r; - int cnt = 0; - - if (ev) - { - r = ev; - do - { - cnt++; - r = r->next; - } - while (r != ev); - } - - return cnt; -} - - - -static pth_t -spawn_helper_thread (void *(*func)(void *), void *arg) -{ - SECURITY_ATTRIBUTES sa; - DWORD tid; - HANDLE th; - - memset (&sa, 0, sizeof sa); - sa.bInheritHandle = TRUE; - sa.lpSecurityDescriptor = NULL; - sa.nLength = sizeof sa; - - if (DBG_INFO) - fprintf (stderr, "%s: spawn_helper_thread creating thread ...\n", - log_get_prefix (NULL)); - th = CreateThread (&sa, 32*1024, - (LPTHREAD_START_ROUTINE)func, - arg, 0, &tid); - if (DBG_INFO) - fprintf (stderr, "%s: spawn_helper_thread created thread %p\n", - log_get_prefix (NULL), th); - - return th; -} - - -static void -free_helper_threads (HANDLE *waitbuf, int *hdidx, int n) -{ - int i; - - for (i=0; i < n; i++) - { - CloseHandle (waitbuf[hdidx[i]]); - waitbuf[hdidx[i]] = NULL; - } -} - - -static void * -wait_fd_thread (void * ctx) -{ - pth_event_t ev = ctx; - - wait_for_fd (ev->u.fd, ev->flags & PTH_UNTIL_FD_READABLE, 3600); - if (DBG_INFO) - fprintf (stderr, "%s: wait_fd_thread: exit.\n", log_get_prefix (NULL)); - SetEvent (ev->hd); - ExitThread (0); - return NULL; -} - - -static void * -wait_timer_thread (void * ctx) -{ - pth_event_t ev = ctx; - int n = ev->u.tv.tv_sec*1000; - Sleep (n); - SetEvent (ev->hd); - if (DBG_INFO) - fprintf (stderr, "%s: wait_timer_thread: exit.\n", log_get_prefix (NULL)); - ExitThread (0); - return NULL; -} - - -static int -do_pth_wait (pth_event_t ev) -{ - HANDLE waitbuf[MAXIMUM_WAIT_OBJECTS/2]; - int hdidx[MAXIMUM_WAIT_OBJECTS/2]; - DWORD n = 0; - int pos=0, i=0; - - if (!ev) - return 0; - - n = event_count (ev); - if (n > MAXIMUM_WAIT_OBJECTS/2) - return -1; - - if (DBG_INFO) - fprintf (stderr, "%s: pth_wait: cnt %lu\n", log_get_prefix (NULL), n); - if (ev) - { - pth_event_t r = ev; - do - { - switch (r->u_type) - { - case 0: - waitbuf[pos++] = r->hd; - break; - - case PTH_EVENT_SIGS: - waitbuf[pos++] = pth_signo_ev; - if (DBG_INFO) - fprintf (stderr, "pth_wait: add signal event.\n"); - break; - - case PTH_EVENT_FD: - if (DBG_INFO) - fprintf (stderr, "pth_wait: spawn event wait thread.\n"); - hdidx[i++] = pos; - waitbuf[pos++] = spawn_helper_thread (wait_fd_thread, r); - break; - - case PTH_EVENT_TIME: - if (DBG_INFO) - fprintf (stderr, "pth_wait: spawn event timer thread.\n"); - hdidx[i++] = pos; - waitbuf[pos++] = spawn_helper_thread (wait_timer_thread, r); - break; - - case PTH_EVENT_MUTEX: - if (DBG_INFO) - fprintf (stderr, "pth_wait: ignoring mutex event.\n"); - break; - } - } - while ( r != ev ); - } - if (DBG_INFO) - fprintf (stderr, "%s: pth_wait: set %d\n", log_get_prefix (NULL), pos); - n = WaitForMultipleObjects (pos, waitbuf, FALSE, INFINITE); - free_helper_threads (waitbuf, hdidx, i); - if (DBG_INFO) - fprintf (stderr, "%s: pth_wait: n %ld\n", log_get_prefix (NULL), n); - - if (n != WAIT_TIMEOUT) - return 1; - - return 0; -} - -int -pth_wait (pth_event_t ev) -{ - int rc; - - implicit_init (); - enter_pth (__FUNCTION__); - rc = do_pth_wait (ev); - leave_pth (__FUNCTION__); - return rc; -} - - -int -pth_sleep (int sec) -{ - static pth_key_t ev_key = PTH_KEY_INIT; - pth_event_t ev; - - implicit_init (); - enter_pth (__FUNCTION__); - - if (sec == 0) - { - leave_pth (__FUNCTION__); - return 0; - } - - ev = do_pth_event (PTH_EVENT_TIME|PTH_MODE_STATIC, &ev_key, - pth_timeout (sec, 0)); - if (ev == NULL) - { - leave_pth (__FUNCTION__); - return -1; - } - do_pth_wait (ev); - do_pth_event_free (ev, PTH_FREE_ALL); - - leave_pth (__FUNCTION__); - return 0; -} - - - - - -/* - Some simple tests. - */ -#ifdef TEST -#include <stdio.h> - -void * thread (void * c) -{ - - Sleep (2000); - SetEvent (((pth_event_t)c)->hd); - fprintf (stderr, "\n\nhallo!.\n"); - pth_exit (NULL); - return NULL; -} - - -int main_1 (int argc, char ** argv) -{ - pth_attr_t t; - pth_t hd; - pth_event_t ev; - - pth_init (); - ev = pth_event (0, NULL); - t = pth_attr_new (); - pth_attr_set (t, PTH_ATTR_JOINABLE, 1); - pth_attr_set (t, PTH_ATTR_STACK_SIZE, 4096); - pth_attr_set (t, PTH_ATTR_NAME, "hello"); - hd = pth_spawn (t, thread, ev); - - pth_wait (ev); - pth_attr_destroy (t); - pth_event_free (ev, 0); - pth_kill (); - - return 0; -} - - -static pth_event_t -setup_signals (struct sigset_s *sigs, int *signo) -{ - pth_event_t ev; - - sigemptyset (sigs); - sigaddset (sigs, SIGINT); - sigaddset (sigs, SIGTERM); - - ev = pth_event (PTH_EVENT_SIGS, sigs, signo); - return ev; -} - -int -main_2 (int argc, char ** argv) -{ - pth_event_t ev; - struct sigset_s sigs; - int signo = 0; - - pth_init (); - ev = setup_signals (&sigs, &signo); - pth_wait (ev); - if (pth_event_occured (ev) && signo) - fprintf (stderr, "signal caught! signo %d\n", signo); - - pth_event_free (ev, PTH_FREE_ALL); - pth_kill (); - return 0; -} - -int -main_3 (int argc, char ** argv) -{ - struct sockaddr_in addr, rem; - int fd, n = 0, infd; - int signo = 0; - struct sigset_s sigs; - pth_event_t ev; - - pth_init (); - fd = socket (AF_INET, SOCK_STREAM, 0); - - memset (&addr, 0, sizeof addr); - addr.sin_addr.s_addr = INADDR_ANY; - addr.sin_port = htons (5050); - addr.sin_family = AF_INET; - bind (fd, (struct sockaddr*)&addr, sizeof addr); - listen (fd, 5); - - ev = setup_signals (&sigs, &signo); - n = sizeof addr; - infd = pth_accept_ev (fd, (struct sockaddr *)&rem, &n, ev); - fprintf (stderr, "infd %d: %s:%d\n", infd, inet_ntoa (rem.sin_addr), - htons (rem.sin_port)); - - closesocket (infd); - pth_event_free (ev, PTH_FREE_ALL); - pth_kill (); - return 0; -} - -int -main (int argc, char ** argv) -{ - pth_event_t ev; - pth_key_t ev_key; - - pth_init (); - /*ev = pth_event (PTH_EVENT_TIME, &ev_key, pth_timeout (5, 0)); - pth_wait (ev); - pth_event_free (ev, PTH_FREE_ALL);*/ - pth_sleep (5); - pth_kill (); - return 0; -} -#endif - -#endif /*HAVE_W32_SYSTEM*/ - diff --git a/jnlib/w32-pth.h b/jnlib/w32-pth.h deleted file mode 100644 index e351a9f0a..000000000 --- a/jnlib/w32-pth.h +++ /dev/null @@ -1,245 +0,0 @@ -/* w32-pth.h - GNU Pth emulation for W32 (MS Windows). - * Copyright (c) 1999-2003 Ralf S. Engelschall <rse@engelschall.com> - * Copyright (C) 2004, 2006 g10 Code GmbH - * - * This file is part of JNLIB. - * - * JNLIB 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. - * - * JNLIB 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., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - * - * ------------------------------------------------------------------ - * This code is based on Ralf Engelschall's GNU Pth, a non-preemptive - * thread scheduling library which can be found at - * http://www.gnu.org/software/pth/. - */ - -/* Note that this header is usually used through a symlinked pth.h - file. This is needed so that we don't have a pth.h file here which - would conflict if a system really has pth available. */ -#ifndef W32_PTH_H -#define W32_PTH_H - -#include <windows.h> /* We need this for sockaddr et al. FIXME: too - heavyweight - may be we should factor such - code out to a second header and adjust all - user files to include it only if required. */ - -#ifndef W32_PTH_HANDLE_INTERNAL -#define W32_PTH_HANDLE_INTERNAL int -#endif - - -/* Filedescriptor blocking modes. */ -enum - { - PTH_FDMODE_ERROR = -1, - PTH_FDMODE_POLL = 0, - PTH_FDMODE_BLOCK, - PTH_FDMODE_NONBLOCK - }; - - -/* Mutex values. */ -#define PTH_MUTEX_INITIALIZED (1<<0) -#define PTH_MUTEX_LOCKED (1<<1) - -/* Note: We can't do static initialization, thus we don't define the - initializer PTH_MUTEX_INIT. */ - - -#define PTH_KEY_INIT (1<<0) - - -/* Event subject classes. */ -#define PTH_EVENT_FD (1<<1) -#define PTH_EVENT_SELECT (1<<2) -#define PTH_EVENT_SIGS (1<<3) -#define PTH_EVENT_TIME (1<<4) -#define PTH_EVENT_MSG (1<<5) -#define PTH_EVENT_MUTEX (1<<6) -#define PTH_EVENT_COND (1<<7) -#define PTH_EVENT_TID (1<<8) -#define PTH_EVENT_FUNC (1<<9) - - - -/* Event occurrence restrictions. */ -#define PTH_UNTIL_OCCURRED (1<<11) -#define PTH_UNTIL_FD_READABLE (1<<12) -#define PTH_UNTIL_FD_WRITEABLE (1<<13) -#define PTH_UNTIL_FD_EXCEPTION (1<<14) -#define PTH_UNTIL_TID_NEW (1<<15) -#define PTH_UNTIL_TID_READY (1<<16) -#define PTH_UNTIL_TID_WAITING (1<<17) -#define PTH_UNTIL_TID_DEAD (1<<18) - - -/* Event structure handling modes. */ -#define PTH_MODE_REUSE (1<<20) -#define PTH_MODE_CHAIN (1<<21) -#define PTH_MODE_STATIC (1<<22) - - -/* Attribute commands for pth_attr_get and pth_attr_set(). */ -enum - { - PTH_ATTR_PRIO, /* RW [int] Priority of thread. */ - PTH_ATTR_NAME, /* RW [char *] Name of thread. */ - PTH_ATTR_JOINABLE, /* RW [int] Thread detachment type. */ - PTH_ATTR_CANCEL_STATE, /* RW [unsigned int] Thread cancellation state.*/ - PTH_ATTR_STACK_SIZE, /* RW [unsigned int] Stack size. */ - PTH_ATTR_STACK_ADDR, /* RW [char *] Stack lower address. */ - PTH_ATTR_DISPATCHES, /* RO [int] Total number of - thread dispatches. */ - PTH_ATTR_TIME_SPAWN, /* RO [pth_time_t] Time thread was spawned. */ - PTH_ATTR_TIME_LAST, /* RO [pth_time_t] Time thread was - last dispatched. */ - PTH_ATTR_TIME_RAN, /* RO [pth_time_t] Time thread was running. */ - PTH_ATTR_START_FUNC, /* RO [void *(*)(void *)] Thread start function.*/ - PTH_ATTR_START_ARG, /* RO [void *] Thread start argument. */ - PTH_ATTR_STATE, /* RO [pth_state_t] Scheduling state. */ - PTH_ATTR_EVENTS, /* RO [pth_event_t] Events the thread - is waiting for. */ - PTH_ATTR_BOUND /* RO [int] Whether object is - bound to thread. */ - }; - - - -/* Queries for pth_ctrl(). */ -#define PTH_CTRL_GETAVLOAD (1<<1) -#define PTH_CTRL_GETPRIO (1<<2) -#define PTH_CTRL_GETNAME (1<<3) -#define PTH_CTRL_GETTHREADS_NEW (1<<4) -#define PTH_CTRL_GETTHREADS_READY (1<<5) -#define PTH_CTRL_GETTHREADS_RUNNING (1<<6) -#define PTH_CTRL_GETTHREADS_WAITING (1<<7) -#define PTH_CTRL_GETTHREADS_SUSPENDED (1<<8) -#define PTH_CTRL_GETTHREADS_DEAD (1<<9) -#define PTH_CTRL_DUMPSTATE (1<<10) - -#define PTH_CTRL_GETTHREADS ( PTH_CTRL_GETTHREADS_NEW \ - | PTH_CTRL_GETTHREADS_READY \ - | PTH_CTRL_GETTHREADS_RUNNING \ - | PTH_CTRL_GETTHREADS_WAITING \ - | PTH_CTRL_GETTHREADS_SUSPENDED \ - | PTH_CTRL_GETTHREADS_DEAD ) - - -/* Event status codes. */ -typedef enum - { - PTH_STATUS_PENDING, - PTH_STATUS_OCCURRED, - PTH_STATUS_FAILED - } -pth_status_t; - - -/* Event deallocation types. */ -enum - { - PTH_FREE_THIS, - PTH_FREE_ALL - }; - - -/* The Pth thread handle object. */ -typedef void *pth_t; - - -/* The Mutex object. */ -typedef W32_PTH_HANDLE_INTERNAL pth_mutex_t; - - -/* The Event object. */ -struct pth_event_s; -typedef struct pth_event_s *pth_event_t; - - -/* The Attribute object. */ -struct pth_attr_s; -typedef struct pth_attr_s *pth_attr_t; - - -/* The Key object. */ -typedef int pth_key_t; - - -/* The Pth time object. */ -typedef struct timeval pth_time_t; - - -/* Function prototypes. */ -int pth_init (void); -int pth_kill (void); -long pth_ctrl (unsigned long query, ...); - -int pth_read_ev (int fd, void *buffer, size_t size, pth_event_t ev); -int pth_read (int fd, void *buffer, size_t size); -int pth_write_ev (int fd, const void *buffer, size_t size, pth_event_t ev); -int pth_write (int fd, const void *buffer, size_t size); - -int pth_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, - const struct timeval *timeout); - -int pth_accept (int fd, struct sockaddr *addr, int *addrlen); -int pth_accept_ev (int fd, struct sockaddr *addr, int *addrlen, - pth_event_t hd); - -int pth_connect (int fd, struct sockaddr *name, int namelen); - - -int pth_mutex_release (pth_mutex_t *hd); -int pth_mutex_acquire(pth_mutex_t *hd, int try_only, pth_event_t ev_extra); -int pth_mutex_init (pth_mutex_t *hd); - - -pth_attr_t pth_attr_new (void); -int pth_attr_destroy (pth_attr_t hd); -int pth_attr_set (pth_attr_t hd, int field, ...); - -pth_t pth_spawn (pth_attr_t hd, void *(*func)(void *), void *arg); -pth_t pth_self (void); -int pth_join (pth_t hd, void **value); -int pth_abort (pth_t hd); -void pth_exit (void *value); - -unsigned int pth_waitpid (unsigned int, int *status, int options); -int pth_wait (pth_event_t hd); - -int pth_sleep (int n); -pth_time_t pth_timeout (long sec, long usec); - - - -pth_event_t pth_event_isolate (pth_event_t hd); -int pth_event_free (pth_event_t hd, int mode); -int pth_event_status (pth_event_t hd); -int pth_event_occurred (pth_event_t hd); -pth_event_t pth_event_concat (pth_event_t ev, ...); -pth_event_t pth_event (unsigned long spec, ...); - - - -/*-- pth_util.c --*/ - -/* void sigemptyset (struct sigset_s * ss); */ - -/* int sigaddset (struct sigset_s * ss, int signo); */ - - - -#endif /*W32_PTH_H*/ diff --git a/jnlib/w32-reg.c b/jnlib/w32-reg.c new file mode 100644 index 000000000..b7a383e3f --- /dev/null +++ b/jnlib/w32-reg.c @@ -0,0 +1,184 @@ +/* w32-reg.c - MS-Windows Registry access + * Copyright (C) 1999, 2002, 2007 Free Software Foundation, Inc. + * + * This file is part of JNLIB. + * + * JNLIB 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. + * + * JNLIB 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., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#include <config.h> +#ifdef HAVE_W32_SYSTEM + /* This module is only used in this environment */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdarg.h> +#include <windows.h> + +#include "libjnlib-config.h" +#include "w32help.h" + +static HKEY +get_root_key(const char *root) +{ + HKEY root_key; + + if (!root) + root_key = HKEY_CURRENT_USER; + else if (!strcmp( root, "HKEY_CLASSES_ROOT" ) ) + root_key = HKEY_CLASSES_ROOT; + else if (!strcmp( root, "HKEY_CURRENT_USER" ) ) + root_key = HKEY_CURRENT_USER; + else if (!strcmp( root, "HKEY_LOCAL_MACHINE" ) ) + root_key = HKEY_LOCAL_MACHINE; + else if (!strcmp( root, "HKEY_USERS" ) ) + root_key = HKEY_USERS; + else if (!strcmp( root, "HKEY_PERFORMANCE_DATA" ) ) + root_key = HKEY_PERFORMANCE_DATA; + else if (!strcmp( root, "HKEY_CURRENT_CONFIG" ) ) + root_key = HKEY_CURRENT_CONFIG; + else + return NULL; + + return root_key; +} + + +/* Return a string from the Win32 Registry or NULL in case of error. + Caller must release the return value. A NULL for root is an alias + for HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE in turn. */ +char * +read_w32_registry_string (const char *root, const char *dir, const char *name) +{ + HKEY root_key, key_handle; + DWORD n1, nbytes, type; + char *result = NULL; + + if ( !(root_key = get_root_key(root) ) ) + return NULL; + + if ( RegOpenKeyEx( root_key, dir, 0, KEY_READ, &key_handle ) ) + { + if (root) + return NULL; /* No need for a RegClose, so return immediately. */ + /* It seems to be common practise to fall back to HKLM. */ + if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, dir, 0, KEY_READ, &key_handle) ) + return NULL; /* Still no need for a RegClose. */ + } + + nbytes = 1; + if (RegQueryValueEx( key_handle, name, 0, NULL, NULL, &nbytes ) ) + goto leave; + result = jnlib_malloc ((n1=nbytes+1)); + if (!result) + goto leave; + if (RegQueryValueEx( key_handle, name, 0, &type, result, &n1 )) + { + jnlib_free (result); + result = NULL; + goto leave; + } + result[nbytes] = 0; /* Make sure it is a string. */ + if (type == REG_EXPAND_SZ && strchr (result, '%')) + { + char *tmp; + + n1 += 1000; + tmp = jnlib_malloc (n1+1); + if (!tmp) + goto leave; + nbytes = ExpandEnvironmentStrings (result, tmp, n1); + if (nbytes && nbytes > n1) + { + jnlib_free (tmp); + n1 = nbytes; + tmp = jnlib_malloc (n1 + 1); + if (!tmp) + goto leave; + nbytes = ExpandEnvironmentStrings (result, tmp, n1); + if (nbytes && nbytes > n1) + { + /* Oops - truncated, better don't expand at all. */ + jnlib_free (tmp); + goto leave; + } + tmp[nbytes] = 0; + jnlib_free (result); + result = tmp; + } + else if (nbytes) + { + /* Okay, reduce the length. */ + tmp[nbytes] = 0; + jnlib_free (result); + result = jnlib_malloc (strlen (tmp)+1); + if (!result) + result = tmp; + else + { + strcpy (result, tmp); + jnlib_free (tmp); + } + } + else + { + /* Error - don't expand. */ + jnlib_free (tmp); + } + } + + leave: + RegCloseKey (key_handle); + return result; +} + + +int +write_w32_registry_string (const char *root, const char *dir, + const char *name, const char *value) +{ + HKEY root_key, reg_key; + + if ( !(root_key = get_root_key(root) ) ) + return -1; + + if ( RegOpenKeyEx( root_key, dir, 0, KEY_WRITE, ®_key ) + != ERROR_SUCCESS ) + return -1; + + if ( RegSetValueEx (reg_key, name, 0, REG_SZ, (BYTE *)value, + strlen( value ) ) != ERROR_SUCCESS ) + { + if ( RegCreateKey( root_key, name, ®_key ) != ERROR_SUCCESS ) + { + RegCloseKey(reg_key); + return -1; + } + if ( RegSetValueEx (reg_key, name, 0, REG_SZ, (BYTE *)value, + strlen( value ) ) != ERROR_SUCCESS ) + { + RegCloseKey(reg_key); + return -1; + } + } + + RegCloseKey (reg_key); + + return 0; +} + +#endif /*HAVE_W32_SYSTEM*/ diff --git a/jnlib/w32help.h b/jnlib/w32help.h new file mode 100644 index 000000000..cb1dafcf5 --- /dev/null +++ b/jnlib/w32help.h @@ -0,0 +1,41 @@ +/* w32help.h - W32 speicif functions + * Copyright (C) 2007 Free Software Foundation, Inc. + * + * This file is part of JNLIB. + * + * JNLIB 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. + * + * JNLIB 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., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef LIBJNLIB_W32HELP_H +#define LIBJNLIB_W32HELP_H +#ifdef HAVE_W32_SYSTEM + +/*-- w32-reg.c --*/ +char *read_w32_registry_string (const char *root, + const char *dir, const char *name ); +int write_w32_registry_string (const char *root, const char *dir, + const char *name, const char *value); + +#ifdef USE_SIMPLE_GETTEXT +int set_gettext_file (const char *filename, const char *regkey); +const char *gettext (const char *msgid ); +const char *ngettext (const char *msgid1, const char *msgid2, + unsigned long int n); +#endif /*USE_SIMPLE_GETTEXT*/ + + +#endif /*HAVE_W32_SYSTEM*/ +#endif /*LIBJNLIB_MISCHELP_H*/ diff --git a/kbx/ChangeLog b/kbx/ChangeLog index ead879615..169374d73 100644 --- a/kbx/ChangeLog +++ b/kbx/ChangeLog @@ -1,3 +1,7 @@ +2007-06-06 Werner Koch <wk@g10code.com> + + * kbxutil.c (i18n_init): Remove. + 2007-03-20 Werner Koch <wk@g10code.com> * keybox.h (KEYBOX_FLAG_BLOB_SECRET, KEYBOX_FLAG_BLOB_EPHEMERAL): diff --git a/kbx/kbxutil.c b/kbx/kbxutil.c index 809612f00..ebc69fa61 100644 --- a/kbx/kbxutil.c +++ b/kbx/kbxutil.c @@ -123,20 +123,6 @@ my_strusage( int level ) } -static void -i18n_init(void) -{ -#ifdef USE_SIMPLE_GETTEXT - set_gettext_file( PACKAGE_GT ); -#else -#ifdef ENABLE_NLS - setlocale( LC_ALL, "" ); - bindtextdomain( PACKAGE_GT, LOCALEDIR ); - textdomain( PACKAGE_GT ); -#endif -#endif -} - /* Used by gcry for logging */ static void my_gcry_logger (void *dummy, int level, const char *fmt, va_list arg_ptr) diff --git a/keyserver/ChangeLog b/keyserver/ChangeLog index 65e8f6213..c738b82d5 100644 --- a/keyserver/ChangeLog +++ b/keyserver/ChangeLog @@ -1,3 +1,9 @@ +2007-06-06 Werner Koch <wk@g10code.com> + + * gpgkeys_ldap.c (send_key, send_key_keyserver): Rename eof to + r_eof as some Windows file has such a symbol. + (main): Likewise. + 2007-05-07 Werner Koch <wk@g10code.com> * Makefile.am (gpg2keys_ldap_LDADD): Add GPG_ERROR_LIBS. diff --git a/keyserver/gpgkeys_ldap.c b/keyserver/gpgkeys_ldap.c index c409c3435..93b24844a 100644 --- a/keyserver/gpgkeys_ldap.c +++ b/keyserver/gpgkeys_ldap.c @@ -575,7 +575,7 @@ free_mod_values(LDAPMod *mod) } static int -send_key(int *eof) +send_key(int *r_eof) { int err,begin=0,end=0,keysize=1,ret=KEYSERVER_INTERNAL_ERROR; char *dn=NULL,line[MAX_LINE],*key=NULL; @@ -631,14 +631,14 @@ send_key(int *eof) { /* i.e. eof before the INFO BEGIN was found. This isn't an error. */ - *eof=1; + *r_eof=1; ret=KEYSERVER_OK; goto fail; } if(strlen(keyid)!=16) { - *eof=1; + *r_eof=1; ret=KEYSERVER_KEY_INCOMPLETE; goto fail; } @@ -678,7 +678,7 @@ send_key(int *eof) if(!end) { fprintf(console,"gpgkeys: no INFO %s END found\n",keyid); - *eof=1; + *r_eof=1; ret=KEYSERVER_KEY_INCOMPLETE; goto fail; } @@ -699,7 +699,7 @@ send_key(int *eof) { /* i.e. eof before the KEY BEGIN was found. This isn't an error. */ - *eof=1; + *r_eof=1; ret=KEYSERVER_OK; goto fail; } @@ -733,7 +733,7 @@ send_key(int *eof) if(!end) { fprintf(console,"gpgkeys: no KEY %s END found\n",keyid); - *eof=1; + *r_eof=1; ret=KEYSERVER_KEY_INCOMPLETE; goto fail; } @@ -791,7 +791,7 @@ send_key(int *eof) } static int -send_key_keyserver(int *eof) +send_key_keyserver(int *r_eof) { int err,begin=0,end=0,keysize=1,ret=KEYSERVER_INTERNAL_ERROR; char *dn=NULL,line[MAX_LINE],*key[2]={NULL,NULL}; @@ -840,7 +840,7 @@ send_key_keyserver(int *eof) { /* i.e. eof before the KEY BEGIN was found. This isn't an error. */ - *eof=1; + *r_eof=1; ret=KEYSERVER_OK; goto fail; } @@ -871,7 +871,7 @@ send_key_keyserver(int *eof) if(!end) { fprintf(console,"gpgkeys: no KEY %s END found\n",keyid); - *eof=1; + *r_eof=1; ret=KEYSERVER_KEY_INCOMPLETE; goto fail; } @@ -2272,7 +2272,7 @@ main(int argc,char *argv[]) } else if(opt->action==KS_SEND) { - int eof=0; + int eof_seen = 0; do { @@ -2280,16 +2280,16 @@ main(int argc,char *argv[]) if(real_ldap) { - if(send_key(&eof)!=KEYSERVER_OK) + if (send_key(&eof_seen) != KEYSERVER_OK) failed++; } else { - if(send_key_keyserver(&eof)!=KEYSERVER_OK) + if (send_key_keyserver(&eof_seen) != KEYSERVER_OK) failed++; } } - while(!eof); + while (!eof_seen); } else if(opt->action==KS_SEARCH) { diff --git a/m4/ChangeLog b/m4/ChangeLog index 99403382c..8c5ffeb7b 100644 --- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,3 +1,12 @@ +2007-05-30 Werner Koch <wk@g10code.com> + + * gnupg-pth.m4: Remove W32 kludge. + +2007-05-29 Werner Koch <wk@g10code.com> + + * longlong.m4, ulonglong.m4: Remove. We now require autoconf + 2.61. + 2007-05-15 Werner Koch <wk@g10code.com> * estream.m4: New. diff --git a/m4/gnupg-pth.m4 b/m4/gnupg-pth.m4 index 759ba8038..6dc9e0ee4 100644 --- a/m4/gnupg-pth.m4 +++ b/m4/gnupg-pth.m4 @@ -73,13 +73,11 @@ AC_DEFUN([GNUPG_PTH_VERSION_CHECK], ]) -# + # GNUPG_PATH_PTH([MINIMUM_VERSION]) # -# This is a special version of the check whioch assumes that a -# emulation for W32 systems is available. The test assumes that -# $have_w32_system has already been set. On return $have_pth is set -# as well as HAVE_PTH is defined and PTH_CLFAGS and PTH_LIBS are AS_SUBST. +# On return $have_pth is set as well as HAVE_PTH is defined and +# PTH_CLFAGS and PTH_LIBS are AS_SUBST. # AC_DEFUN([GNUPG_PATH_PTH], [ AC_ARG_WITH(pth-prefix, @@ -91,9 +89,7 @@ AC_DEFUN([GNUPG_PATH_PTH], fi AC_PATH_PROG(PTH_CONFIG, pth-config, no) tmp=ifelse([$1], ,1.3.7,$1) - test -z "$have_w32_system" && have_w32_system="no" - if test "$have_w32_system" = no; then - if test "$PTH_CONFIG" != "no"; then + if test "$PTH_CONFIG" != "no"; then GNUPG_PTH_VERSION_CHECK($tmp) if test $have_pth = yes; then PTH_CFLAGS=`$PTH_CONFIG --cflags` @@ -102,12 +98,6 @@ AC_DEFUN([GNUPG_PATH_PTH], AC_DEFINE(HAVE_PTH, 1, [Defined if the GNU Pth is available]) fi - fi - else - have_pth=yes - PTH_CFLAGS="" - PTH_LIBS="" - AC_DEFINE(HAVE_PTH, 1) fi AC_SUBST(PTH_CFLAGS) AC_SUBST(PTH_LIBS) diff --git a/m4/longlong.m4 b/m4/longlong.m4 deleted file mode 100644 index 3716c09f6..000000000 --- a/m4/longlong.m4 +++ /dev/null @@ -1,48 +0,0 @@ -# longlong.m4 serial 8 -dnl Copyright (C) 1999-2006 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Paul Eggert. - -# Define HAVE_LONG_LONG_INT if 'long long int' works. -# This fixes a bug in Autoconf 2.60, but can be removed once we -# assume 2.61 everywhere. - -# Note: If the type 'long long int' exists but is only 32 bits large -# (as on some very old compilers), AC_TYPE_LONG_LONG_INT will not be -# defined. In this case you can treat 'long long int' like 'long int'. - -AC_DEFUN([AC_TYPE_LONG_LONG_INT], -[ - AC_CACHE_CHECK([for long long int], [ac_cv_type_long_long_int], - [AC_LINK_IFELSE( - [AC_LANG_PROGRAM( - [[long long int ll = 9223372036854775807ll; - long long int nll = -9223372036854775807LL; - typedef int a[((-9223372036854775807LL < 0 - && 0 < 9223372036854775807ll) - ? 1 : -1)]; - int i = 63;]], - [[long long int llmax = 9223372036854775807ll; - return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i) - | (llmax / ll) | (llmax % ll));]])], - [ac_cv_type_long_long_int=yes], - [ac_cv_type_long_long_int=no])]) - if test $ac_cv_type_long_long_int = yes; then - AC_DEFINE([HAVE_LONG_LONG_INT], 1, - [Define to 1 if the system has the type `long long int'.]) - fi -]) - -# This macro is obsolescent and should go away soon. -AC_DEFUN([gl_AC_TYPE_LONG_LONG], -[ - AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) - ac_cv_type_long_long=$ac_cv_type_long_long_int - if test $ac_cv_type_long_long = yes; then - AC_DEFINE(HAVE_LONG_LONG, 1, - [Define if you have the 'long long' type.]) - fi -]) diff --git a/m4/ulonglong.m4 b/m4/ulonglong.m4 deleted file mode 100644 index 9fae98e3a..000000000 --- a/m4/ulonglong.m4 +++ /dev/null @@ -1,48 +0,0 @@ -# ulonglong.m4 serial 6 -dnl Copyright (C) 1999-2006 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -dnl From Paul Eggert. - -# Define HAVE_UNSIGNED_LONG_LONG_INT if 'unsigned long long int' works. -# This fixes a bug in Autoconf 2.60, but can be removed once we -# assume 2.61 everywhere. - -# Note: If the type 'unsigned long long int' exists but is only 32 bits -# large (as on some very old compilers), AC_TYPE_UNSIGNED_LONG_LONG_INT -# will not be defined. In this case you can treat 'unsigned long long int' -# like 'unsigned long int'. - -AC_DEFUN([AC_TYPE_UNSIGNED_LONG_LONG_INT], -[ - AC_CACHE_CHECK([for unsigned long long int], - [ac_cv_type_unsigned_long_long_int], - [AC_LINK_IFELSE( - [AC_LANG_PROGRAM( - [[unsigned long long int ull = 18446744073709551615ULL; - typedef int a[(18446744073709551615ULL <= (unsigned long long int) -1 - ? 1 : -1)]; - int i = 63;]], - [[unsigned long long int ullmax = 18446744073709551615ull; - return (ull << 63 | ull >> 63 | ull << i | ull >> i - | ullmax / ull | ullmax % ull);]])], - [ac_cv_type_unsigned_long_long_int=yes], - [ac_cv_type_unsigned_long_long_int=no])]) - if test $ac_cv_type_unsigned_long_long_int = yes; then - AC_DEFINE([HAVE_UNSIGNED_LONG_LONG_INT], 1, - [Define to 1 if the system has the type `unsigned long long int'.]) - fi -]) - -# This macro is obsolescent and should go away soon. -AC_DEFUN([gl_AC_TYPE_UNSIGNED_LONG_LONG], -[ - AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT]) - ac_cv_type_unsigned_long_long=$ac_cv_type_unsigned_long_long_int - if test $ac_cv_type_unsigned_long_long = yes; then - AC_DEFINE(HAVE_UNSIGNED_LONG_LONG, 1, - [Define if you have the 'unsigned long long' type.]) - fi -]) diff --git a/scd/ChangeLog b/scd/ChangeLog index c0141c74a..2e9024e20 100644 --- a/scd/ChangeLog +++ b/scd/ChangeLog @@ -1,3 +1,13 @@ +2007-06-06 Werner Koch <wk@g10code.com> + + * app-openpgp.c (do_sign): Fix arithmetic on void*. + + * app.c (dump_mutex_state) [W32]: Handle the W32Pth case. + + * apdu.c: Remove dynload.h. + + * scdaemon.c (i18n_init): Remove. + 2007-04-20 Werner Koch <wk@g10code.com> * sc-copykeys.c (my_gcry_logger): Removed. diff --git a/scd/apdu.c b/scd/apdu.c index a45f0a3e9..57faa7006 100644 --- a/scd/apdu.c +++ b/scd/apdu.c @@ -62,7 +62,6 @@ #endif /* GNUPG_MAJOR_VERSION != 1 */ #include "apdu.h" -#include "dynload.h" #include "ccid-driver.h" diff --git a/scd/app-openpgp.c b/scd/app-openpgp.c index a02ff0396..2b7263171 100644 --- a/scd/app-openpgp.c +++ b/scd/app-openpgp.c @@ -2223,13 +2223,13 @@ do_sign (app_t app, const char *keyidstr, int hashalgo, else if (indatalen == (15 + 20) && hashalgo == GCRY_MD_SHA1 && !memcmp (indata, sha1_prefix, 15)) { - indata += 15; + indata = (const char*)indata + 15; indatalen -= 15; } else if (indatalen == (15 + 20) && hashalgo == GCRY_MD_RMD160 && !memcmp (indata, rmd160_prefix, 15)) { - indata += 15; + indata = (const char*)indata + 15; indatalen -= 15; } else @@ -107,12 +107,16 @@ unlock_reader (int slot) static void dump_mutex_state (pth_mutex_t *m) { +#ifdef _W32_PTH_H + log_printf ("unknown under W32"); +#else if (!(m->mx_state & PTH_MUTEX_INITIALIZED)) log_printf ("not_initialized"); else if (!(m->mx_state & PTH_MUTEX_LOCKED)) log_printf ("not_locked"); else log_printf ("locked tid=0x%lx count=%lu", (long)m->mx_owner, m->mx_count); +#endif } diff --git a/scd/scdaemon.c b/scd/scdaemon.c index b87c0f3e5..ea97a392c 100644 --- a/scd/scdaemon.c +++ b/scd/scdaemon.c @@ -205,21 +205,6 @@ my_strusage (int level) -static void -i18n_init (void) -{ -#ifdef USE_SIMPLE_GETTEXT - set_gettext_file( PACKAGE_GT ); -#else -#ifdef ENABLE_NLS - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE_GT, LOCALEDIR); - textdomain (PACKAGE_GT); -#endif -#endif -} - - /* Setup the debugging. With a LEVEL of NULL only the active debug diff --git a/sm/ChangeLog b/sm/ChangeLog index ddd392280..20c7460be 100644 --- a/sm/ChangeLog +++ b/sm/ChangeLog @@ -1,3 +1,13 @@ +2007-06-06 Werner Koch <wk@g10code.com> + + * qualified.c (gpgsm_not_qualified_warning) [!ENABLE_NLS]: Do not + define orig_codeset. + * certdump.c (gpgsm_format_keydesc) [!ENABLE_NLS]: Do not define + orig_codeset. + (format_name_writer): Define only if funopen et al is available. + + * gpgsm.c (i18n_init): Remove. + 2007-05-29 Werner Koch <wk@g10code.com> * export.c (gpgsm_p12_export): Print passphrase encoding info only diff --git a/sm/certdump.c b/sm/certdump.c index f5fff38c4..743b4dd41 100644 --- a/sm/certdump.c +++ b/sm/certdump.c @@ -735,6 +735,7 @@ gpgsm_es_print_name (estream_t fp, const char *name) +#if defined (HAVE_FOPENCOOKIE) || defined (HAVE_FUNOPEN) /* A cookie structure used for the memory stream. */ struct format_name_cookie { @@ -769,6 +770,8 @@ format_name_writer (void *cookie, const char *buffer, size_t size) return size; } +#endif /*HAVE_FOPENCOOKIE || HAVE_FUNOPEN*/ + /* Format NAME which is expected to be in rfc2253 format into a better human readable format. Caller must free the returned string. NULL @@ -890,7 +893,9 @@ gpgsm_format_keydesc (ksba_cert_t cert) char created[20]; char *sn; ksba_sexp_t sexp; +#ifdef ENABLE_NLS char *orig_codeset = NULL; +#endif name = ksba_cert_get_subject (cert, 0); subject = name? gpgsm_format_name2 (name, 0) : NULL; diff --git a/sm/gpgsm.c b/sm/gpgsm.c index 924286f8f..71559c326 100644 --- a/sm/gpgsm.c +++ b/sm/gpgsm.c @@ -601,21 +601,6 @@ set_binary (FILE *fp) static void -i18n_init(void) -{ -#ifdef USE_SIMPLE_GETTEXT - set_gettext_file (PACKAGE_GT); -#else -# ifdef ENABLE_NLS - setlocale (LC_ALL, "" ); - bindtextdomain (PACKAGE_GT, LOCALEDIR); - textdomain (PACKAGE_GT); -# endif -#endif -} - - -static void wrong_args (const char *text) { fputs (_("usage: gpgsm [options] "), stderr); diff --git a/sm/qualified.c b/sm/qualified.c index 4a9c81ddb..0eabeeba4 100644 --- a/sm/qualified.c +++ b/sm/qualified.c @@ -290,7 +290,9 @@ gpgsm_not_qualified_warning (ctrl_t ctrl, ksba_cert_t cert) gpg_error_t err; char *name, *subject, *buffer, *p; const char *s; +#ifdef ENABLE_NLS char *orig_codeset = NULL; +#endif if (!opt.qualsig_approval) return 0; diff --git a/tools/ChangeLog b/tools/ChangeLog index 6ee23ccc5..a75a2b963 100644 --- a/tools/ChangeLog +++ b/tools/ChangeLog @@ -1,3 +1,14 @@ +2007-06-06 Werner Koch <wk@g10code.com> + + * Makefile.am (bin_PROGRAMS) [W32]: Do not build gpgparsemail. + + * gpgconf-comp.c [W32]: Do not include pwd.h and grp.h. + (key_matches_user_or_group) [W32]: For now always return false. + + * symcryptrun.c (i18n_init): Remove. + * gpgconf.c (i18n_init): Remove. + * gpg-connect-agent.c (i18n_init): Remove. + 2007-05-19 Marcus Brinkmann <marcus@g10code.de> * symcryptrun.c (confucius_get_pass): Free ORIG_CODESET on error. diff --git a/tools/Makefile.am b/tools/Makefile.am index 8bd20c5a3..5728c4ff9 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -43,10 +43,9 @@ else symcryptrun = endif -bin_PROGRAMS = gpgconf gpg-connect-agent gpgkey2ssh ${symcryptrun} \ - gpgparsemail +bin_PROGRAMS = gpgconf gpg-connect-agent gpgkey2ssh ${symcryptrun} if !HAVE_W32_SYSTEM -bin_PROGRAMS += watchgnupg +bin_PROGRAMS += watchgnupg gpgparsemail endif noinst_PROGRAMS = clean-sat mk-tdata make-dns-cert gpgsplit diff --git a/tools/gpg-connect-agent.c b/tools/gpg-connect-agent.c index 98a13de11..219d7d01f 100644 --- a/tools/gpg-connect-agent.c +++ b/tools/gpg-connect-agent.c @@ -142,21 +142,6 @@ my_strusage( int level ) } -/* Initialize the gettext system. */ -static void -i18n_init(void) -{ -#ifdef USE_SIMPLE_GETTEXT - set_gettext_file (PACKAGE_GT); -#else -# ifdef ENABLE_NLS - setlocale (LC_ALL, "" ); - bindtextdomain (PACKAGE_GT, LOCALEDIR); - textdomain (PACKAGE_GT); -# endif -#endif -} - /* Store an inquire response pattern. Note, that this function may change the content of LINE. We assume that leading white spaces are already removed. */ diff --git a/tools/gpgconf-comp.c b/tools/gpgconf-comp.c index 580972aef..16fa3ad1a 100644 --- a/tools/gpgconf-comp.c +++ b/tools/gpgconf-comp.c @@ -33,8 +33,10 @@ #include <time.h> #include <stdarg.h> #include <signal.h> +#ifndef HAVE_W32_SYSTEM #include <pwd.h> #include <grp.h> +#endif /* For log_logv(), asctimestamp(), gnupg_get_time (). */ #define JNLIB_NEED_LOG_LOGV @@ -2574,6 +2576,9 @@ gc_component_change_options (int component, FILE *in) static int key_matches_user_or_group (char *user) { +#ifdef HAVE_W32_SYSTEM +# warning We need a real user and group lookup. +#else char *group; int n; @@ -2641,7 +2646,7 @@ key_matches_user_or_group (char *user) if (!strcmp (group, my_supgroups[n])) return 1; /* Found. */ } - +#endif return 0; /* No match. */ } diff --git a/tools/gpgconf.c b/tools/gpgconf.c index 6d73e88e0..c06db5225 100644 --- a/tools/gpgconf.c +++ b/tools/gpgconf.c @@ -104,22 +104,6 @@ my_strusage( int level ) } -/* Initialize the gettext system. */ -static void -i18n_init(void) -{ -#ifdef USE_SIMPLE_GETTEXT - set_gettext_file (PACKAGE_GT); -#else -# ifdef ENABLE_NLS - setlocale (LC_ALL, "" ); - bindtextdomain (PACKAGE_GT, LOCALEDIR); - textdomain (PACKAGE_GT); -# endif -#endif -} - - /* gpgconf main. */ int main (int argc, char **argv) diff --git a/tools/symcryptrun.c b/tools/symcryptrun.c index 119121208..f8de30fd9 100644 --- a/tools/symcryptrun.c +++ b/tools/symcryptrun.c @@ -223,21 +223,6 @@ my_strusage (int level) } -/* Initialize the gettext system. */ -static void -i18n_init(void) -{ -#ifdef USE_SIMPLE_GETTEXT - set_gettext_file (PACKAGE_GT); -#else -# ifdef ENABLE_NLS - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE_GT, LOCALEDIR); - textdomain (PACKAGE_GT); -# endif -#endif -} - /* This is in the GNU C library in unistd.h. */ |