From 4b845615fa11e0e7488cc279a2986167fba0522c Mon Sep 17 00:00:00 2001 From: Darshit Shah Date: Thu, 4 Dec 2014 18:36:54 +0530 Subject: [PATCH] Define MIN and MAx macros in a single location MIN and MAx are macros that a developer will universally expect throughout the source. Yet, they were being defined in multiple places across the source. Instead, define them in a single location in the common wget.h header file and use them consistently everywhere. --- src/ChangeLog | 6 ++++++ src/gnutls.c | 5 ----- src/http.c | 8 -------- src/progress.c | 7 ------- src/retr.c | 4 ---- src/wget.h | 5 +++++ 6 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 81c6d362..e2b3c305 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2014-12-04 Darshit Shah + + * wget.h: Define MIX and MAX macros globally for all files + * gnutls.c, retr.c: Delete declaration of MIN macro + * http.c, progress.c: Delete declaration of MIN and MAX macros + 2014-12-03 Gisle Vanem * openssl.c (ssl_init): Fix C89 warning diff --git a/src/gnutls.c b/src/gnutls.c index 0757cfc8..604a46e3 100644 --- a/src/gnutls.c +++ b/src/gnutls.c @@ -229,11 +229,6 @@ struct wgnutls_transport_context int peeklen; }; -#ifndef MIN -# define MIN(i, j) ((i) <= (j) ? (i) : (j)) -#endif - - static int wgnutls_read_timeout (int fd, char *buf, int bufsize, void *arg, double timeout) { diff --git a/src/http.c b/src/http.c index 1a6cd391..ee17bce1 100644 --- a/src/http.c +++ b/src/http.c @@ -81,11 +81,6 @@ static bool known_authentication_scheme_p (const char *, const char *); static void ensure_extension (struct http_stat *, const char *, int *); static void load_cookies (void); -#ifndef MIN -# define MIN(x, y) ((x) > (y) ? (y) : (x)) -#endif - - static bool cookies_loaded_p; static struct cookie_jar *wget_cookie_jar; @@ -1161,9 +1156,6 @@ append_value_to_filename (char **filename, param_token const * const value, url_unescape (*filename + original_length); } -#undef MAX -#define MAX(p, q) ((p) > (q) ? (p) : (q)) - /* Parse the contents of the `Content-Disposition' header, extracting the information useful to Wget. Content-Disposition is a header borrowed from MIME; when used in HTTP, it typically serves for diff --git a/src/progress.c b/src/progress.c index 479eaffa..132a8e50 100644 --- a/src/progress.c +++ b/src/progress.c @@ -896,13 +896,6 @@ get_eta (int *bcd) are confused when they see strchr (s, '\0') in the code. */ #define move_to_end(s) s = strchr (s, '\0'); -#ifndef MAX -# define MAX(a, b) ((a) >= (b) ? (a) : (b)) -#endif -#ifndef MIN -# define MIN(a, b) ((a) <= (b) ? (a) : (b)) -#endif - static void create_image (struct bar_progress *bp, double dl_total_time, bool done) { diff --git a/src/retr.c b/src/retr.c index 1bcaae7a..f12c50fb 100644 --- a/src/retr.c +++ b/src/retr.c @@ -136,10 +136,6 @@ limit_bandwidth (wgint bytes, struct ptimer *timer) limit_data.chunk_start = ptimer_read (timer); } -#ifndef MIN -# define MIN(i, j) ((i) <= (j) ? (i) : (j)) -#endif - /* Write data in BUF to OUT. However, if *SKIP is non-zero, skip that amount of data and decrease SKIP. Increment *TOTAL by the amount of data written. If OUT2 is not NULL, also write BUF to OUT2. diff --git a/src/wget.h b/src/wget.h index 6edbfb8c..cddacdc8 100644 --- a/src/wget.h +++ b/src/wget.h @@ -317,6 +317,11 @@ typedef double SUM_SIZE_INT; in base 10. 24082 / 10000 = 8*log_{10}(2). */ #define MAX_INT_TO_STRING_LEN(x) ((sizeof(x) * 24082 / 10000) + 2) +/* Find the minimum or maximum of two provided values */ +# define MIN(i, j) ((i) <= (j) ? (i) : (j)) +# define MAX(i, j) ((i) >= (j) ? (i) : (j)) + + extern const char *exec_name; extern const char *program_name; extern const char *program_argstring;