From: Simon Josefsson Date: Tue, 17 Aug 2004 08:45:00 +0000 (+0000) Subject: Use minmax.h from gnulib instead of GMIN/GMAX. X-Git-Tag: gnutls_1_0_20~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3756e804dacc637e8a00ff57ab2b80945abdb8c3;p=thirdparty%2Fgnutls.git Use minmax.h from gnulib instead of GMIN/GMAX. --- diff --git a/configure.in b/configure.in index 262e162567..30dbf91de6 100644 --- a/configure.in +++ b/configure.in @@ -608,7 +608,7 @@ AC_MSG_RESULT([*** gl_SOURCE_BASE(gl) gl_M4_BASE(gl/m4) -gl_MODULES(getline error exit progname getpass-gnu) +gl_MODULES(getline error exit progname getpass-gnu minmax) gl_INIT AC_MSG_RESULT([*** diff --git a/gl/Makefile.am b/gl/Makefile.am index b20d924c29..f59ed59af8 100644 --- a/gl/Makefile.am +++ b/gl/Makefile.am @@ -10,7 +10,7 @@ # Generated by gnulib-tool. # # Invoked as: gnulib-tool --import -# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --libtool error exit extensions getline getpass-gnu gettext progname stdbool unlocked-io +# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --libtool error exit extensions getline getpass-gnu gettext minmax progname stdbool unlocked-io AUTOMAKE_OPTIONS = 1.8 gnits @@ -36,6 +36,8 @@ libgnu_la_SOURCES += getpass.h libgnu_la_SOURCES += gettext.h +libgnu_la_SOURCES += minmax.h + libgnu_la_SOURCES += progname.h progname.c BUILT_SOURCES += $(STDBOOL_H) diff --git a/gl/m4/gnulib.m4 b/gl/m4/gnulib.m4 index 9992333439..fe1625e28a 100644 --- a/gl/m4/gnulib.m4 +++ b/gl/m4/gnulib.m4 @@ -8,7 +8,7 @@ # Generated by gnulib-tool. # # Invoked as: gnulib-tool --import -# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --libtool error exit extensions getline getpass-gnu gettext progname stdbool unlocked-io +# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --libtool error exit extensions getline getpass-gnu gettext minmax progname stdbool unlocked-io AC_DEFUN([gl_EARLY], [ diff --git a/gl/minmax.h b/gl/minmax.h new file mode 100644 index 0000000000..0e505109e7 --- /dev/null +++ b/gl/minmax.h @@ -0,0 +1,53 @@ +/* MIN, MAX macros. + Copyright (C) 1995, 1998, 2001, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#ifndef _MINMAX_H +#define _MINMAX_H + +/* Note: MIN, MAX are also defined in on some systems + (glibc, IRIX, HP-UX, OSF/1). Therefore you might get warnings about + MIN, MAX macro redefinitions on some systems; the workaround is to + #include this file as the last one among the #include list. */ + +/* Before we define the following symbols we get the file + since otherwise we get redefinitions on some systems. */ +#include + +/* Note: MIN and MAX should be used with two arguments of the + same type. They might not return the minimum and maximum of their two + arguments, if the arguments have different types or have unusual + floating-point values. For example, on a typical host with 32-bit 'int', + 64-bit 'long long', and 64-bit IEEE 754 'double' types: + + MAX (-1, 2147483648) returns 4294967295. + MAX (9007199254740992.0, 9007199254740993) returns 9007199254740992.0. + MAX (NaN, 0.0) returns 0.0. + MAX (+0.0, -0.0) returns -0.0. + + and in each case the answer is in some sense bogus. */ + +/* MAX(a,b) returns the maximum of A and B. */ +#ifndef MAX +# define MAX(a,b) ((a) > (b) ? (a) : (b)) +#endif + +/* MIN(a,b) returns the minimum of A and B. */ +#ifndef MIN +# define MIN(a,b) ((a) < (b) ? (a) : (b)) +#endif + +#endif /* _MINMAX_H */ diff --git a/lib/Makefile.am b/lib/Makefile.am index 4614a06b89..ced7323778 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,4 +1,4 @@ -INCLUDES = -I$(top_srcdir)/crypto -I$(top_srcdir)/libextra -I$(srcdir)/minitasn1 -I$(top_srcdir)/libextra/openpgp/ -I$(top_srcdir)/libextra/opencdk -I$(srcdir)/x509 -I$(top_srcdir)/includes $(LIBOPENCDK_CFLAGS) $(LIBTASN1_CFLAGS) $(LIBGCRYPT_CFLAGS) +INCLUDES = -I$(top_srcdir)/crypto -I$(top_srcdir)/gl -I$(top_srcdir)/libextra -I$(srcdir)/minitasn1 -I$(top_srcdir)/libextra/openpgp/ -I$(top_srcdir)/libextra/opencdk -I$(srcdir)/x509 -I$(top_srcdir)/includes $(LIBOPENCDK_CFLAGS) $(LIBTASN1_CFLAGS) $(LIBGCRYPT_CFLAGS) bin_SCRIPTS = libgnutls-config m4datadir = $(datadir)/aclocal diff --git a/lib/auth_srp_passwd.c b/lib/auth_srp_passwd.c index 56af4f0d85..1e547dd0b1 100644 --- a/lib/auth_srp_passwd.c +++ b/lib/auth_srp_passwd.c @@ -210,7 +210,7 @@ static int pwd_read_conf(const char *pconf_file, SRP_PWD_ENTRY * entry, while ((line[i] != ':') && (line[i] != '\0') && (i < sizeof(line))) { i++; } - if (strncmp(indexstr, line, GMAX(i, len)) == 0) { + if (strncmp(indexstr, line, MAX(i, len)) == 0) { if ((index = pwd_put_values2(entry, line)) >= 0) return 0; else { @@ -304,7 +304,7 @@ int _gnutls_srp_pwd_read_entry(gnutls_session_t state, char *username, i++; } - if (strncmp(username, line, GMAX(i, len)) == 0) { + if (strncmp(username, line, MAX(i, len)) == 0) { if ((index = pwd_put_values(entry, line)) >= 0) { /* Keep the last index in memory, so we can retrieve fake parameters (g,n) * when the user does not exist. diff --git a/lib/ext_srp.c b/lib/ext_srp.c index 8bb1cbc7de..50f8668df1 100644 --- a/lib/ext_srp.c +++ b/lib/ext_srp.c @@ -100,7 +100,7 @@ int _gnutls_srp_send_params(gnutls_session_t session, opaque * data, return 0; if (cred->username != NULL) { /* send username */ - len = GMIN(strlen(cred->username), 255); + len = MIN(strlen(cred->username), 255); if (data_size < len + 1) { gnutls_assert(); @@ -129,7 +129,7 @@ int _gnutls_srp_send_params(gnutls_session_t session, opaque * data, return 0; } - len = GMIN(strlen(username), 255); + len = MIN(strlen(username), 255); if (data_size < len + 1) { gnutls_free(username); diff --git a/lib/gnutls_buffers.c b/lib/gnutls_buffers.c index ec48505118..d22722db5c 100644 --- a/lib/gnutls_buffers.c +++ b/lib/gnutls_buffers.c @@ -392,7 +392,7 @@ ssize_t _gnutls_io_read_buffered(gnutls_session_t session, opaque ** iptr, /* calculate the actual size, ie. get the minimum of the * buffered data and the requested data. */ - min = GMIN(session->internals.record_recv_buffer.length, sizeOfPtr); + min = MIN(session->internals.record_recv_buffer.length, sizeOfPtr); if (min > 0) { /* if we have enough buffered data * then just return them. @@ -485,7 +485,7 @@ ssize_t _gnutls_io_read_buffered(gnutls_session_t session, opaque ** iptr, if (ret < 0 || ret2 < 0) { gnutls_assert(); /* that's because they are initialized to 0 */ - return GMIN(ret, ret2); + return MIN(ret, ret2); } ret += ret2; diff --git a/lib/gnutls_num.h b/lib/gnutls_num.h index 2c49ddb50f..e14c829d54 100644 --- a/lib/gnutls_num.h +++ b/lib/gnutls_num.h @@ -1,4 +1,5 @@ /* + * Copyright (C) 2004 Simon Josefsson * Copyright (C) 2000,2003 Nikos Mavroyanopoulos * * This file is part of GNUTLS. @@ -20,8 +21,7 @@ #include -#define GMIN(x,y) ((xy)?x:y) +#include #define rotl32(x,n) (((x) << ((uint16)(n))) | ((x) >> (32 - (uint16)(n)))) #define rotr32(x,n) (((x) >> ((uint16)(n))) | ((x) << (32 - (uint16)(n)))) diff --git a/lib/gnutls_pk.c b/lib/gnutls_pk.c index c853ae79f7..d11af60349 100644 --- a/lib/gnutls_pk.c +++ b/lib/gnutls_pk.c @@ -129,7 +129,7 @@ int _gnutls_pkcs1_rsa_encrypt(gnutls_datum_t * ciphertext, if (i < 2) ps[i] = rnd[i]; else - ps[i] = GMAX(rnd[2] + ps[i - 1] + ps[i - 2], rnd[1]); + ps[i] = MAX(rnd[2] + ps[i - 1] + ps[i - 2], rnd[1]); } } break; diff --git a/lib/gnutls_str.c b/lib/gnutls_str.c index ad30a94799..48a84b985f 100644 --- a/lib/gnutls_str.c +++ b/lib/gnutls_str.c @@ -123,12 +123,12 @@ int _gnutls_string_copy_str(gnutls_string * dest, const char *src) return src_len; } else { dest->data = - dest->realloc_func(dest->data, GMAX(src_len, MIN_CHUNK)); + dest->realloc_func(dest->data, MAX(src_len, MIN_CHUNK)); if (dest->data == NULL) { gnutls_assert(); return GNUTLS_E_MEMORY_ERROR; } - dest->max_length = GMAX(MIN_CHUNK, src_len); + dest->max_length = MAX(MIN_CHUNK, src_len); memcpy(dest->data, src, src_len); dest->length = src_len; @@ -149,7 +149,7 @@ int _gnutls_string_append_str(gnutls_string * dest, const char *src) return tot_len; } else { size_t new_len = - GMAX(src_len, MIN_CHUNK) + GMAX(dest->max_length, MIN_CHUNK); + MAX(src_len, MIN_CHUNK) + MAX(dest->max_length, MIN_CHUNK); dest->data = dest->realloc_func(dest->data, new_len); if (dest->data == NULL) { @@ -177,7 +177,7 @@ int _gnutls_string_append_data(gnutls_string * dest, const void *data, return tot_len; } else { size_t new_len = - GMAX(data_size, MIN_CHUNK) + GMAX(dest->max_length, MIN_CHUNK); + MAX(data_size, MIN_CHUNK) + MAX(dest->max_length, MIN_CHUNK); dest->data = dest->realloc_func(dest->data, new_len); if (dest->data == NULL) { diff --git a/lib/x509/dn.c b/lib/x509/dn.c index 184dcf318f..ff7493b24c 100644 --- a/lib/x509/dn.c +++ b/lib/x509/dn.c @@ -58,7 +58,7 @@ static char *str_escape(char *str, char *buffer, unsigned int buffer_size) if (str == NULL || buffer == NULL) return NULL; - str_length = GMIN(strlen(str), buffer_size - 1); + str_length = MIN(strlen(str), buffer_size - 1); for (i = j = 0; i < str_length; i++) { if (str[i] == ',' || str[i] == '+' || str[i] == '"' diff --git a/lib/x509/pkcs12.c b/lib/x509/pkcs12.c index 3bd761bd4c..68fcbae08b 100644 --- a/lib/x509/pkcs12.c +++ b/lib/x509/pkcs12.c @@ -345,7 +345,7 @@ _pkcs12_decode_safe_contents(const gnutls_datum_t * content, goto cleanup; } - bag->bag_elements = GMIN(MAX_BAG_ELEMENTS, count); + bag->bag_elements = MIN(MAX_BAG_ELEMENTS, count); for (i = 0; i < bag->bag_elements; i++) { diff --git a/lib/x509/privkey_pkcs8.c b/lib/x509/privkey_pkcs8.c index c83054a4de..b210964937 100644 --- a/lib/x509/privkey_pkcs8.c +++ b/lib/x509/privkey_pkcs8.c @@ -1483,7 +1483,7 @@ static int generate_key(schema_id schema, if (schema == PBES2) kdf_params->salt_size = - GMIN(sizeof(kdf_params->salt), (uint) (10 + (rnd[1] % 10))); + MIN(sizeof(kdf_params->salt), (uint) (10 + (rnd[1] % 10))); else kdf_params->salt_size = 8; diff --git a/lib/x509/sign.c b/lib/x509/sign.c index 2cce692920..d63d4b8015 100644 --- a/lib/x509/sign.c +++ b/lib/x509/sign.c @@ -32,7 +32,7 @@ #include #include #include -#include /* GMAX */ +#include /* MAX */ #include #include #include diff --git a/lib/x509/verify.c b/lib/x509/verify.c index b6f08b32a6..f924987dc5 100644 --- a/lib/x509/verify.c +++ b/lib/x509/verify.c @@ -29,7 +29,7 @@ #include #include #include -#include /* GMAX */ +#include /* MAX */ #include #include #include diff --git a/libextra/Makefile.am b/libextra/Makefile.am index 7a3c62bbcb..740a6c47f3 100644 --- a/libextra/Makefile.am +++ b/libextra/Makefile.am @@ -1,4 +1,4 @@ -INCLUDES = -I$(top_srcdir)/crypto -I$(top_srcdir)/lib -I$(top_srcdir)/includes -I$(top_srcdir)/lib/minitasn1 $(LIBOPENCDK_CFLAGS) $(LIBGCRYPT_CFLAGS) $(LIBTASN1_CFLAGS) -I$(srcdir)/opencdk -I$(srcdir)/openpgp +INCLUDES = -I$(top_srcdir)/crypto -I$(top_srcdir)/gl -I$(top_srcdir)/lib -I$(top_srcdir)/includes -I$(top_srcdir)/lib/minitasn1 $(LIBOPENCDK_CFLAGS) $(LIBGCRYPT_CFLAGS) $(LIBTASN1_CFLAGS) -I$(srcdir)/opencdk -I$(srcdir)/openpgp AM_CFLAGS = -DVERSION=\"gnutls/opencdk\" bin_SCRIPTS = libgnutls-extra-config DIST_SUBDIRS = openpgp opencdk