[Zlib-devel] [PATCH 10/12] add ZLIB_LEVEL environmental variable

Jim Kukunas james.t.kukunas at linux.intel.com
Fri Dec 13 18:13:19 EST 2013


The goal is to provide a way for a system administrator
to easily override the deflate level. This environmental
variable is checked in deflateInit, and takes precedence
over the level set by the api.
---
 deflate.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/deflate.c b/deflate.c
index e571be5..a8b559f 100644
--- a/deflate.c
+++ b/deflate.c
@@ -50,6 +50,7 @@
 /* @(#) $Id$ */
 
 #include "deflate.h"
+#include <errno.h>
 
 const char deflate_copyright[] =
    " deflate 1.2.8 Copyright 1995-2013 Jean-loup Gailly and Mark Adler ";
@@ -260,6 +261,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
     unsigned window_padding = 0;
     deflate_state *s;
     int wrap = 1;
+    const char *level_env;
     static const char my_version[] = ZLIB_VERSION;
 
     ushf *overlay;
@@ -299,6 +301,17 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
     if (level == Z_DEFAULT_COMPRESSION) level = 6;
 #endif
 
+    if ((level_env = getenv("ZLIB_LEVEL"))) {
+        long t;
+        char *end;
+
+        errno = 0;
+        t = strtol(level_env, &end, 0);
+        if (errno || level_env == end || t > 9 || t < 0)
+            return Z_STREAM_ERROR;
+        level = t;
+    }
+
     if (windowBits < 0) { /* suppress zlib wrapper */
         wrap = 0;
         windowBits = -windowBits;
-- 
1.7.1





More information about the Zlib-devel mailing list