nginx-0.1.9-RELEASE import

    *) Bugfix: the proxied request was sent without arguments if the
       request contains "//", "/./", "/../" or "%XX".

    *) Bugfix: the large compressed responses may be transferred not
       completely.

    *) Bugfix: the files bigger than 2G was not transferred on Linux that
       does not support sendfile64().

    *) Bugfix: while the build configuration on Linux the
       --with-poll_module parameter was required; the bug had appeared in
       0.1.8.
diff --git a/auto/cc/bcc b/auto/cc/bcc
index a76b68f..4b88129 100644
--- a/auto/cc/bcc
+++ b/auto/cc/bcc
@@ -34,10 +34,10 @@
 
 
 # precompiled headers
-CORE_DEPS="$CORE_DEPS $OBJS/ngx_config.csm"
-NGX_PCH="$OBJS/ngx_config.csm"
-NGX_BUILD_PCH="-H=$OBJS/ngx_config.csm"
-NGX_USE_PCH="-Hu -H=$OBJS/ngx_config.csm"
+CORE_DEPS="$CORE_DEPS $NGX_OBJS/ngx_config.csm"
+NGX_PCH="$NGX_OBJS/ngx_config.csm"
+NGX_BUILD_PCH="-H=$NGX_OBJS/ngx_config.csm"
+NGX_USE_PCH="-Hu -H=$NGX_OBJS/ngx_config.csm"
 
 
 # Win32 GUI mode application
@@ -45,11 +45,11 @@
 
 
 # the resource file
-NGX_RES="$OBJS/nginx.res"
-NGX_RCC="brcc32 -fo$OBJS/nginx.res \$(CORE_INCS) $NGX_WIN32_RC"
+NGX_RES="$NGX_OBJS/nginx.res"
+NGX_RCC="brcc32 -fo$NGX_OBJS/nginx.res \$(CORE_INCS) $NGX_WIN32_RC"
 # the pragma allows to link the resource file using bcc32 and
 # to avoid the direct ilink32 calling and the c0w32.obj's WinMain/main problem
-NGX_PRAGMA="#pragma resource \"$OBJS/nginx.res\""
+NGX_PRAGMA="#pragma resource \"$NGX_OBJS/nginx.res\""
 
 
 ngx_include_opt="-I"
diff --git a/auto/cc/conf b/auto/cc/conf
index c1f577e..0a5db9e 100644
--- a/auto/cc/conf
+++ b/auto/cc/conf
@@ -92,11 +92,11 @@
 CFLAGS="$CFLAGS $NGX_CC_OPT"
 
 
-if [ "$PLATFORM" != win32 ]; then
+if [ "$NGX_PLATFORM" != win32 ]; then
 
     if test -n "$NGX_LD_OPT"; then
         ngx_feature=--with-ld-opt=\"$NGX_LD_OPT\"
-        ngx_feature_name="DUMMY"
+        ngx_feature_name=
         ngx_feature_run=no
         ngx_feature_incs=
         ngx_feature_libs=
@@ -111,7 +111,7 @@
     fi
 
     ngx_feature="gcc variadic macros"
-    ngx_feature_name="HAVE_GCC_VARIADIC_MACROS"
+    ngx_feature_name="NGX_HAVE_GCC_VARIADIC_MACROS"
     ngx_feature_run=yes
     ngx_feature_incs="#include <stdio.h>
 #define var(dummy, args...)  sprintf(args)"
@@ -123,7 +123,7 @@
 
 
     ngx_feature="C99 variadic macros"
-    ngx_feature_name="HAVE_C99_VARIADIC_MACROS"
+    ngx_feature_name="NGX_HAVE_C99_VARIADIC_MACROS"
     ngx_feature_run=yes
     ngx_feature_incs="#include <stdio.h>
 #define var(dummy, ...) sprintf(__VA_ARGS__)"
@@ -135,7 +135,7 @@
 
 
 #    ngx_feature="inline"
-#    ngx_feature_name="DUMMY"
+#    ngx_feature_name=
 #    ngx_feature_run=no
 #    ngx_feature_incs="int inline f(void) { return 1 }"
 #    ngx_feature_libs=
diff --git a/auto/cc/icc b/auto/cc/icc
index 89c6f35..a32eec4 100644
--- a/auto/cc/icc
+++ b/auto/cc/icc
@@ -18,7 +18,7 @@
 IPO="-ipo -ipo_obj"
 CFLAGS="$CFLAGS $IPO"
 CORE_LINK="$CORE_LINK $IPO"
-CORE_LINK="$CORE_LINK -opt_report_file=$OBJS/opt_report_file"
+CORE_LINK="$CORE_LINK -opt_report_file=$NGX_OBJS/opt_report_file"
 
 case $CPU in
     pentium)
diff --git a/auto/cc/msvc b/auto/cc/msvc
index 8272cac..0fa1a2c 100644
--- a/auto/cc/msvc
+++ b/auto/cc/msvc
@@ -77,15 +77,15 @@
 
 # precompiled headers
 if [ $NGX_CC_NAME != msvc7 ]; then
-    CORE_DEPS="$CORE_DEPS $OBJS/ngx_config.pch"
-    NGX_PCH="$OBJS/ngx_config.pch"
-    NGX_BUILD_PCH="-Ycngx_config.h -Fp$OBJS/ngx_config.pch"
-    NGX_USE_PCH="-Yungx_config.h -Fp$OBJS/ngx_config.pch"
+    CORE_DEPS="$CORE_DEPS $NGX_OBJS/ngx_config.pch"
+    NGX_PCH="$NGX_OBJS/ngx_config.pch"
+    NGX_BUILD_PCH="-Ycngx_config.h -Fp$NGX_OBJS/ngx_config.pch"
+    NGX_USE_PCH="-Yungx_config.h -Fp$NGX_OBJS/ngx_config.pch"
 fi
 
 
 # the resource file
-NGX_RES="$OBJS/nginx.res"
+NGX_RES="$NGX_OBJS/nginx.res"
 NGX_RCC="rc -fo$NGX_RES \$(CORE_INCS) $NGX_WIN32_RC"
 CORE_LINK="$NGX_RES $CORE_LINK"
 
diff --git a/auto/cc/owc b/auto/cc/owc
index 789ffad..88ffdb1 100644
--- a/auto/cc/owc
+++ b/auto/cc/owc
@@ -63,10 +63,10 @@
 
 
 # the precompiled headers 
-CORE_DEPS="$CORE_DEPS $OBJS/ngx_config.pch"
-NGX_PCH="$OBJS/ngx_config.pch"
-NGX_BUILD_PCH="-fhq=$OBJS/ngx_config.pch"
-NGX_USE_PCH="-fh=$OBJS/ngx_config.pch"
+CORE_DEPS="$CORE_DEPS $NGX_OBJS/ngx_config.pch"
+NGX_PCH="$NGX_OBJS/ngx_config.pch"
+NGX_BUILD_PCH="-fhq=$NGX_OBJS/ngx_config.pch"
+NGX_USE_PCH="-fh=$NGX_OBJS/ngx_config.pch"
 
 
 LINK="\$(CC)"
@@ -76,7 +76,8 @@
 
 
 # the resource file
-NGX_RCC="wrc \$(CORE_INCS) -fo=$OBJS/nginx.res $NGX_WIN32_RC $OBJS/nginx.exe"
+NGX_RCC="wrc \$(CORE_INCS) -fo=$NGX_OBJS/nginx.res "
+NGX_RCC="$NGX_RCC $NGX_WIN32_RC $NGX_OBJS/nginx.exe"
 
 
 ngx_include_opt="-i="
diff --git a/auto/configure b/auto/configure
index d5cc7e0..0cd17ea 100755
--- a/auto/configure
+++ b/auto/configure
@@ -7,26 +7,26 @@
 . auto/init
 . auto/sources
 
-test -d $OBJS || mkdir $OBJS
+test -d $NGX_OBJS || mkdir $NGX_OBJS
 
 echo > $NGX_AUTO_HEADERS_H
 echo > $NGX_AUTO_CONFIG_H
 echo > $NGX_AUTOCONF_ERR
 
 
-if [ $DEBUG = YES ]; then
+if [ $NGX_DEBUG = YES ]; then
     have=NGX_DEBUG . auto/have
 fi
 
 
-if [ "$PLATFORM" != win32 ]; then
+if [ "$NGX_PLATFORM" != win32 ]; then
     . auto/headers
 fi
 
 . auto/cc/conf
 . auto/os/conf
 
-if [ "$PLATFORM" != win32 ]; then
+if [ "$NGX_PLATFORM" != win32 ]; then
     . auto/threads
 fi
 
@@ -37,21 +37,21 @@
 . auto/lib/make
 . auto/install
 
-if [ "$PLATFORM" != win32 ]; then
+if [ "$NGX_PLATFORM" != win32 ]; then
     . auto/unix
 fi
 
 # STUB
 . auto/stubs
 
-have=NGX_PREFIX value="\"$PREFIX/\"" . auto/define
-have=NGX_SBIN_PATH value="\"$SBIN_PATH\"" . auto/define
-have=NGX_CONF_PATH value="\"$CONF_PATH\"" . auto/define
-have=NGX_PID_PATH value="\"$PID_PATH\"" . auto/define
-if [ ".$ERROR_LOG_PATH" != "." ]; then
-    have=NGX_ERROR_LOG_PATH value="\"$ERROR_LOG_PATH\"" . auto/define
+have=NGX_PREFIX value="\"$NGX_PREFIX/\"" . auto/define
+have=NGX_SBIN_PATH value="\"$NGX_SBIN_PATH\"" . auto/define
+have=NGX_CONF_PATH value="\"$NGX_CONF_PATH\"" . auto/define
+have=NGX_PID_PATH value="\"$NGX_PID_PATH\"" . auto/define
+if test -n "$NGX_ERROR_LOG_PATH"; then
+    have=NGX_ERROR_LOG_PATH value="\"$NGX_ERROR_LOG_PATH\"" . auto/define
 fi
-have=NGX_HTTP_LOG_PATH value="\"$HTTP_LOG_PATH\"" . auto/define
+have=NGX_HTTP_LOG_PATH value="\"$NGX_HTTP_LOG_PATH\"" . auto/define
 
 have=NGX_USER value="\"$NGX_USER\"" . auto/define
 have=NGX_GROUP value="\"$NGX_GROUP\"" . auto/define
diff --git a/auto/endianess b/auto/endianess
index 640b465..578dd45 100644
--- a/auto/endianess
+++ b/auto/endianess
@@ -25,7 +25,7 @@
 if [ -x $NGX_AUTOTEST ]; then
     if $NGX_AUTOTEST 2>&1 > /dev/null; then
         echo " little endianess"
-        have=HAVE_LITTLE_ENDIAN . auto/have
+        have=NGX_HAVE_LITTLE_ENDIAN . auto/have
     else
         echo " big endianess"
     fi
diff --git a/auto/feature b/auto/feature
index 410f539..0fbbe84 100644
--- a/auto/feature
+++ b/auto/feature
@@ -14,9 +14,7 @@
 ngx_found=no
 
 if test -n "$ngx_feature_name"; then
-    ngx_have_feature=`echo NGX_$ngx_feature_name | tr '[a-z]' '[A-Z]'`
-    # STUB
-    ngx_have_feature0=`echo HAVE_$ngx_feature_name | tr '[a-z]' '[A-Z]'`
+    ngx_have_feature=`echo $ngx_feature_name | tr '[a-z]' '[A-Z]'`
 fi
 
 cat << END > $NGX_AUTOTEST.c
@@ -51,11 +49,6 @@
                have=$ngx_have_feature . auto/have
            fi
 
-           #STUB
-           if test -n "$ngx_feature_name"; then
-               have=$ngx_have_feature0 . auto/have
-           fi
-
        else
            echo " found but is not working"
        fi
@@ -68,11 +61,6 @@
            have=$ngx_have_feature . auto/have
        fi
 
-       #STUB
-       if test -n "$ngx_feature_name"; then
-           have=$ngx_have_feature0 . auto/have
-       fi
-
     fi
 
 else
diff --git a/auto/func b/auto/func
deleted file mode 100644
index 970d634..0000000
--- a/auto/func
+++ /dev/null
@@ -1,43 +0,0 @@
-
-# Copyright (C) Igor Sysoev
-
-
-echo $ngx_n "checking for $ngx_func ..." $ngx_c
-echo >> $NGX_ERR
-echo "checking for $ngx_func" >> $NGX_ERR
-
-ngx_found=no
-
-func=`echo $ngx_func | sed -e 's/()$//' | tr '[a-z]' '[A-Z]'`
-
-cat << END > $NGX_AUTOTEST.c
-
-#include <sys/types.h>
-$NGX_UNISTD_H
-$ngx_func_inc
-
-int main() {
-    $ngx_func_test;
-    return 0;
-}
-
-END
-
-test="$CC_WARN $CC_TEST_FLAGS -o $NGX_AUTOTEST $NGX_AUTOTEST.c $ngx_func_libs"
-eval "$test >> $NGX_ERR 2>&1"
-
-if [ -x $NGX_AUTOTEST ]; then
-    echo " found"
-    have=HAVE_$func . auto/have
-    ngx_found=yes
-
-else
-    echo " not found"
-    echo "---------" >> $NGX_ERR
-    cat $NGX_AUTOTEST.c >> $NGX_ERR
-    echo "---------" >> $NGX_ERR
-    echo $test >> $NGX_ERR
-    echo "---------" >> $NGX_ERR
-fi
-
-rm $NGX_AUTOTEST*
diff --git a/auto/init b/auto/init
index 080cc28..0b33c3b 100644
--- a/auto/init
+++ b/auto/init
@@ -12,9 +12,8 @@
 NGX_AUTOCONF_ERR=$NGX_OBJS/autoconf.err
 
 # STUBs
-OBJS=$NGX_OBJS
-NGX_ERR=$OBJS/autoconf.err
-MAKEFILE=$OBJS/Makefile
+NGX_ERR=$NGX_OBJS/autoconf.err
+MAKEFILE=$NGX_OBJS/Makefile
 
 
 NGX_PCH=
@@ -54,9 +53,9 @@
 	rm -rf Makefile $NGX_OBJS
 
 upgrade:
-	$SBIN_PATH -t
-	kill -USR2 \`cat $PID_PATH\`
+	$NGX_SBIN_PATH -t
+	kill -USR2 \`cat $NGX_PID_PATH\`
 	sleep 1
-	test -f $PID_PATH.newbin
-	kill -WINCH \`cat $PID_PATH\`
+	test -f $NGX_PID_PATH.newbin
+	kill -WINCH \`cat $NGX_PID_PATH\`
 END
diff --git a/auto/install b/auto/install
index bae092b..7a26d04 100644
--- a/auto/install
+++ b/auto/install
@@ -2,40 +2,40 @@
 # Copyright (C) Igor Sysoev
 
 
-cat << END                                                        >> $MAKEFILE
+cat << END                                                    >> $NGX_MAKEFILE
 
 install:
-	test -d $PREFIX || mkdir -p $PREFIX
+	test -d $NGX_PREFIX || mkdir -p $NGX_PREFIX
 
-	test -d `dirname $SBIN_PATH` || mkdir -p `dirname $SBIN_PATH`
-	test ! -f $SBIN_PATH || mv $SBIN_PATH $SBIN_PATH.old
-	cp $OBJS/nginx $SBIN_PATH
+	test -d `dirname $NGX_SBIN_PATH` || mkdir -p `dirname $NGX_SBIN_PATH`
+	test ! -f $NGX_SBIN_PATH || mv $NGX_SBIN_PATH $NGX_SBIN_PATH.old
+	cp $NGX_OBJS/nginx $NGX_SBIN_PATH
 
-	test -d `dirname $CONF_PATH` || mkdir -p `dirname $CONF_PATH`
+	test -d `dirname $NGX_CONF_PATH` || mkdir -p `dirname $NGX_CONF_PATH`
 
-	cp conf/koi-win `dirname $CONF_PATH`
+	cp conf/koi-win `dirname $NGX_CONF_PATH`
 
-	test -f `dirname $CONF_PATH`/mime.types || \
-		cp conf/mime.types `dirname $CONF_PATH`/mime.types
-	cp conf/mime.types `dirname $CONF_PATH`/mime.types.default
+	test -f `dirname $NGX_CONF_PATH`/mime.types || \
+		cp conf/mime.types `dirname $NGX_CONF_PATH`/mime.types
+	cp conf/mime.types `dirname $NGX_CONF_PATH`/mime.types.default
 
-	test -f $CONF_PATH || cp conf/nginx.conf $CONF_PATH
-	cp conf/nginx.conf `dirname $CONF_PATH`/nginx.conf.default
+	test -f $NGX_CONF_PATH || cp conf/nginx.conf $NGX_CONF_PATH
+	cp conf/nginx.conf `dirname $NGX_CONF_PATH`/nginx.conf.default
 
-	test -d `dirname $PID_PATH` || mkdir -p `dirname $PID_PATH`
+	test -d `dirname $NGX_PID_PATH` || mkdir -p `dirname $NGX_PID_PATH`
 
-	test -d `dirname $HTTP_LOG_PATH` || mkdir -p `dirname $HTTP_LOG_PATH`
+	test -d `dirname $NGX_HTTP_LOG_PATH` || \
+		mkdir -p `dirname $NGX_HTTP_LOG_PATH`
 
-	test -d $PREFIX/html || cp -r html $PREFIX
-
-	#test -d $PREFIX/temp || mkdir -p $PREFIX/temp
+	test -d $NGX_PREFIX/html || cp -r html $NGX_PREFIX
 END
 
 
-if [ ".$ERROR_LOG_PATH" != "." ]; then
-    cat << END                                                    >> $MAKEFILE
+if test -n "$NGX_ERROR_LOG_PATH"; then
+    cat << END                                                >> $NGX_MAKEFILE
 
-	test -d `dirname $ERROR_LOG_PATH` || mkdir -p `dirname $ERROR_LOG_PATH`
+	test -d `dirname $NGX_ERROR_LOG_PATH` || \
+		mkdir -p `dirname $NGX_ERROR_LOG_PATH`
 END
 
 fi
diff --git a/auto/lib/md5/conf b/auto/lib/md5/conf
index 27fd641..8122423 100644
--- a/auto/lib/md5/conf
+++ b/auto/lib/md5/conf
@@ -7,7 +7,7 @@
     if grep MD5_Init $MD5/md5.h >/dev/null; then
         # OpenSSL md5
         OPENSSL_MD5=YES
-        have=HAVE_OPENSSL_MD5 . auto/have
+        have=NGX_HAVE_OPENSSL_MD5 . auto/have
     else
         # rsaref md5
         OPENSSL_MD5=NO
@@ -43,13 +43,13 @@
 
 else
 
-    if [ $PLATFORM != win32 ]; then
+    if [ $NGX_PLATFORM != win32 ]; then
         MD5=NO
 
         # Solaris 8/9
 
         ngx_feature="rsaref md5 library"
-        ngx_feature_name="rsaref_md5"
+        ngx_feature_name=
         ngx_feature_run=no
         ngx_feature_incs="#include <md5.h>"
         ngx_feature_libs="-lmd5"
@@ -66,7 +66,7 @@
             # FreeBSD
 
             ngx_feature="rsaref md library"
-            ngx_feature_name="rsaref_md5"
+            ngx_feature_name=
             ngx_feature_run=no
             ngx_feature_incs="#include <md5.h>"
             ngx_feature_libs="-lmd"
@@ -87,7 +87,7 @@
                # OpenSSL crypto library
 
                ngx_feature="OpenSSL md5 crypto library"
-               ngx_feature_name="OpenSSL_md5"
+               ngx_feature_name="NGX_OPENSSL_MD5"
                ngx_feature_run=no
                ngx_feature_incs="#include <openssl/md5.h>"
                ngx_feature_libs="-lcrypto"
@@ -98,7 +98,7 @@
 
 
         if [ $ngx_found = yes ]; then
-            have=HAVE_OPENSSL_MD5_H . auto/have
+            have=NGX_HAVE_OPENSSL_MD5_H . auto/have
             CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
             MD5=YES
             MD5_LIB=crypto
diff --git a/auto/lib/md5/make b/auto/lib/md5/make
index 5dfddfa..b333d4d 100644
--- a/auto/lib/md5/make
+++ b/auto/lib/md5/make
@@ -25,7 +25,7 @@
 done=NO
 
 
-case $PLATFORM in
+case $NGX_PLATFORM in
 
     win32)
         cp auto/lib/md5/$ngx_makefile $MD5
diff --git a/auto/lib/openssl/conf b/auto/lib/openssl/conf
index 8ef4f3a..0a70f33 100644
--- a/auto/lib/openssl/conf
+++ b/auto/lib/openssl/conf
@@ -18,11 +18,11 @@
 
 else
 
-    if [ $PLATFORM != win32 ]; then
+    if [ $NGX_PLATFORM != win32 ]; then
         OPENSSL=NO
 
         ngx_feature="OpenSSL library"
-        ngx_feature_name="OpenSSL"
+        ngx_feature_name="NGX_OPENSSL"
         ngx_feature_run=no
         ngx_feature_incs="#include <openssl/ssl.h>"
         ngx_feature_libs="-lssl -lcrypto"
@@ -30,7 +30,6 @@
         . auto/feature
 
         if [ $ngx_found = yes ]; then
-            have=NGX_OPENSSL . auto/have
             CORE_DEPS="$CORE_DEPS $OPENSSL_DEPS"
             CORE_SRCS="$CORE_SRCS $OPENSSL_SRCS"
             CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
diff --git a/auto/lib/openssl/make b/auto/lib/openssl/make
index 5e931cb..28ab003 100644
--- a/auto/lib/openssl/make
+++ b/auto/lib/openssl/make
@@ -2,7 +2,7 @@
 # Copyright (C) Igor Sysoev
 
 
-case $PLATFORM in
+case $NGX_PLATFORM in
     *)
         echo "$OPENSSL/libssl.a:"                                 >> $MAKEFILE
         echo "	cd $OPENSSL \\"                                   >> $MAKEFILE
diff --git a/auto/lib/pcre/conf b/auto/lib/pcre/conf
index cf26be2..168acba 100644
--- a/auto/lib/pcre/conf
+++ b/auto/lib/pcre/conf
@@ -42,14 +42,14 @@
 
 else
 
-    if [ $PLATFORM != win32 ]; then
+    if [ $NGX_PLATFORM != win32 ]; then
         PCRE=NO
 
         # FreeBSD PCRE port requires --with-cc-opt="-I /usr/local/include"
         #                            --with-ld-opt="-L /usr/local/lib"
         
         ngx_feature="PCRE library"
-        ngx_feature_name="PCRE"
+        ngx_feature_name="NGX_PCRE"
         ngx_feature_run=no
         ngx_feature_incs="#include <pcre.h>"
         ngx_feature_libs="-lpcre"
diff --git a/auto/lib/pcre/make b/auto/lib/pcre/make
index a60fedb..27d774b 100644
--- a/auto/lib/pcre/make
+++ b/auto/lib/pcre/make
@@ -22,7 +22,7 @@
 esac
 
 
-case $PLATFORM in
+case $NGX_PLATFORM in
 
     win32)
         cp auto/lib/pcre/patch.pcre.in $PCRE
diff --git a/auto/lib/zlib/conf b/auto/lib/zlib/conf
index 797a2d3..8edd3f3 100644
--- a/auto/lib/zlib/conf
+++ b/auto/lib/zlib/conf
@@ -37,13 +37,13 @@
 
 else
 
-    if [ $PLATFORM != win32 ]; then
+    if [ $NGX_PLATFORM != win32 ]; then
         ZLIB=NO
 
         # FreeBSD, Solaris, Linux
 
         ngx_feature="zlib library"
-        ngx_feature_name="zlib"
+        ngx_feature_name=
         ngx_feature_run=no
         ngx_feature_incs="#include <zlib.h>"
         ngx_feature_libs="-lz"
diff --git a/auto/lib/zlib/make b/auto/lib/zlib/make
index 2e5ea84..1884b50 100644
--- a/auto/lib/zlib/make
+++ b/auto/lib/zlib/make
@@ -26,7 +26,7 @@
 done=NO
 
 
-case $PLATFORM in
+case $NGX_PLATFORM in
 
     win32)
         cp auto/lib/zlib/$ngx_makefile $ZLIB
diff --git a/auto/make b/auto/make
index 55f36c9..9b6e4be 100644
--- a/auto/make
+++ b/auto/make
@@ -2,10 +2,11 @@
 # Copyright (C) Igor Sysoev
 
 
-mkdir -p $OBJS/src/core $OBJS/src/event $OBJS/src/event/modules \
-         $OBJS/src/os/unix $OBJS/src/os/win32 \
-         $OBJS/src/http $OBJS/src/http/modules $OBJS/src/http/modules/proxy \
-         $OBJS/src/imap
+mkdir -p $NGX_OBJS/src/core $NGX_OBJS/src/event $NGX_OBJS/src/event/modules \
+         $NGX_OBJS/src/os/unix $NGX_OBJS/src/os/win32 \
+         $NGX_OBJS/src/http $NGX_OBJS/src/http/modules \
+	 $NGX_OBJS/src/http/modules/proxy \
+         $NGX_OBJS/src/imap
 
 
 ngx_objs_dir=$NGX_OBJS$ngx_regex_dirsep
@@ -33,7 +34,7 @@
 
 # ALL_INCS, required by OpenWatcom C precompiled headers
 
-ngx_incs=`echo $CORE_INCS $OBJS $HTTP_INCS $IMAP_INCS\
+ngx_incs=`echo $CORE_INCS $NGX_OBJS $HTTP_INCS $IMAP_INCS\
     | sed -e "s/  *\([^ ][^ ]*\)/$ngx_regex_cont$ngx_include_opt\1/g" \
           -e "s/\//$ngx_regex_dirsep/g"`
 
@@ -53,7 +54,7 @@
     | sed -e "s/  *\([^ ][^ ]*\)/$ngx_regex_cont\1/g" \
           -e "s/\//$ngx_regex_dirsep/g"`
 
-ngx_incs=`echo $CORE_INCS $OBJS \
+ngx_incs=`echo $CORE_INCS $NGX_OBJS \
     | sed -e "s/  *\([^ ][^ ]*\)/$ngx_regex_cont$ngx_include_opt\1/g" \
           -e "s/\//$ngx_regex_dirsep/g"`
 
@@ -287,13 +288,13 @@
 # the precompiled headers
 
 if test -n "$NGX_PCH"; then
-    echo "#include <ngx_config.h>" > $OBJS/ngx_pch.c
+    echo "#include <ngx_config.h>" > $NGX_OBJS/ngx_pch.c
 
-    ngx_pch="src/core/ngx_config.h $OS_CONFIG $OBJS/ngx_auto_config.h"
+    ngx_pch="src/core/ngx_config.h $OS_CONFIG $NGX_OBJS/ngx_auto_config.h"
     ngx_pch=`echo "$NGX_PCH:	$ngx_pch" | sed -e "s/\//$ngx_regex_dirsep/g"`
 
     ngx_src="\$(CC) \$(CFLAGS) $NGX_BUILD_PCH $ngx_compile_opt \$(ALL_INCS)"
-    ngx_src="$ngx_src $ngx_objout$OBJS/ngx_pch.obj $OBJS/ngx_pch.c"
+    ngx_src="$ngx_src $ngx_objout$NGX_OBJS/ngx_pch.obj $NGX_OBJS/ngx_pch.c"
     ngx_src=`echo $ngx_src | sed -e "s/\//$ngx_regex_dirsep/g"`
 
     cat << END                                                >> $NGX_MAKEFILE
diff --git a/auto/modules b/auto/modules
index e9a42e3..f02e803 100644
--- a/auto/modules
+++ b/auto/modules
@@ -7,7 +7,7 @@
 fi
 
 if [ $EVENT_SELECT = YES ]; then
-    have=HAVE_SELECT . auto/have
+    have=NGX_HAVE_SELECT . auto/have
     CORE_SRCS="$CORE_SRCS $SELECT_SRCS"
     EVENT_MODULES="$EVENT_MODULES $SELECT_MODULE"
 fi
@@ -18,29 +18,29 @@
 fi
 
 if [ $EVENT_POLL = YES ]; then
-    have=HAVE_POLL . auto/have
+    have=NGX_HAVE_POLL . auto/have
     CORE_SRCS="$CORE_SRCS $POLL_SRCS"
     EVENT_MODULES="$EVENT_MODULES $POLL_MODULE"
 fi
 
 
-if [ $TEST_BUILD_DEVPOLL = YES ]; then
-    have=HAVE_DEVPOLL . auto/have
-    have=TEST_BUILD_DEVPOLL . auto/have
+if [ $NGX_TEST_BUILD_DEVPOLL = YES ]; then
+    have=NGX_HAVE_DEVPOLL . auto/have
+    have=NGX_TEST_BUILD_DEVPOLL . auto/have
     EVENT_MODULES="$EVENT_MODULES $DEVPOLL_MODULE"
     CORE_SRCS="$CORE_SRCS $DEVPOLL_SRCS"
 fi
 
-if [ $TEST_BUILD_EPOLL = YES ]; then
-    have=HAVE_EPOLL . auto/have
-    have=TEST_BUILD_EPOLL . auto/have
+if [ $NGX_TEST_BUILD_EPOLL = YES ]; then
+    have=NGX_HAVE_EPOLL . auto/have
+    have=NGX_TEST_BUILD_EPOLL . auto/have
     EVENT_MODULES="$EVENT_MODULES $EPOLL_MODULE"
     CORE_SRCS="$CORE_SRCS $EPOLL_SRCS"
 fi
 
-if [ $TEST_BUILD_RTSIG = YES ]; then
-    have=HAVE_RTSIG . auto/have
-    have=TEST_BUILD_RTSIG . auto/have
+if [ $NGX_TEST_BUILD_RTSIG = YES ]; then
+    have=NGX_HAVE_RTSIG . auto/have
+    have=NGX_TEST_BUILD_RTSIG . auto/have
     EVENT_MODULES="$EVENT_MODULES $RTSIG_MODULE"
     CORE_SRCS="$CORE_SRCS $RTSIG_SRCS"
 fi
@@ -135,8 +135,11 @@
     HTTP_SRCS="$HTTP_SRCS $HTTP_PROXY_SRCS"
 fi
 
-if [ -r $OBJS/auto ]; then
-    . $OBJS/auto
+# STUB
+#HTTP_SRCS="$HTTP_SRCS $HTPP_FILE_CACHE_SRCS"
+
+if [ -r $NGX_OBJS/auto ]; then
+    . $NGX_OBJS/auto
 fi
 
 modules="$CORE_MODULES $EVENT_MODULES"
diff --git a/auto/options b/auto/options
index 06488c8..266ea31 100644
--- a/auto/options
+++ b/auto/options
@@ -4,29 +4,29 @@
 
 help=no
 
-PREFIX=
-SBIN_PATH=
-CONF_PATH=
-ERROR_LOG_PATH=
-PID_PATH=
+NGX_PREFIX=
+NGX_SBIN_PATH=
+NGX_CONF_PATH=
+NGX_ERROR_LOG_PATH=
+NGX_PID_PATH=
 NGX_USER=
 NGX_GROUP=
-HTTP_LOG_PATH=
+NGX_HTTP_LOG_PATH=
 
 CC=${CC:-gcc}
 CPP=
 NGX_OBJS=objs
 
-DEBUG=NO
+NGX_DEBUG=NO
 NGX_CC_OPT=
 NGX_LD_OPT=
 CPU=NO
 
-TEST_BUILD_DEVPOLL=NO
-TEST_BUILD_EPOLL=NO
-TEST_BUILD_RTSIG=NO
+NGX_TEST_BUILD_DEVPOLL=NO
+NGX_TEST_BUILD_EPOLL=NO
+NGX_TEST_BUILD_RTSIG=NO
 
-PLATFORM=
+NGX_PLATFORM=
 NGX_WINE=
 
 EVENT_FOUND=NO
@@ -52,7 +52,7 @@
 
 IMAP=NO
 
-MODULES=
+NGX_MODULES=
 
 USE_PCRE=NO
 PCRE=NONE
@@ -82,15 +82,15 @@
     case "$option" in
         --help)                          help=yes                   ;;
 
-        --prefix=*)                      PREFIX="$value"            ;;
-        --sbin-path=*)                   SBIN_PATH="$value"         ;;
-        --conf-path=*)                   CONF_PATH="$value"         ;;
-        --error-log-path=*)              ERROR_LOG_PATH="$value"    ;;
-        --pid-path=*)                    PID_PATH="$value"          ;;
+        --prefix=*)                      NGX_PREFIX="$value"        ;;
+        --sbin-path=*)                   NGX_SBIN_PATH="$value"     ;;
+        --conf-path=*)                   NGX_CONF_PATH="$value"     ;;
+        --error-log-path=*)              NGX_ERROR_LOG_PATH="$value";;
+        --pid-path=*)                    NGX_PID_PATH="$value"      ;;
         --user=*)                        NGX_USER="$value"          ;;
         --group=*)                       NGX_GROUP="$value"         ;;
 
-        --crossbuild=*)                  PLATFORM="$value"          ;;
+        --crossbuild=*)                  NGX_PLATFORM="$value"      ;;
 
         --builddir=*)                    NGX_OBJS="$value"          ;;
 
@@ -105,7 +105,7 @@
         --with-threads)                  USE_THREADS="pthreads"     ;;
 
         --without-http)                  HTTP=NO                    ;;
-        --http-log-path=*)               HTTP_LOG_PATH="$value"     ;;
+        --http-log-path=*)               NGX_HTTP_LOG_PATH="$value" ;;
 
         --with-http_ssl_module)          HTTP_SSL=YES               ;;
         --without-http_charset_module)   HTTP_CHARSET=NO            ;;
@@ -127,7 +127,7 @@
         --with-cc-opt=*)                 NGX_CC_OPT="$value"        ;;
         --with-ld-opt=*)                 NGX_LD_OPT="$value"        ;;
         --with-cpu-opt=*)                CPU="$value"               ;;
-        --with-debug)                    DEBUG=YES                  ;;
+        --with-debug)                    NGX_DEBUG=YES              ;;
 
         --without-pcre)                  USE_PCRE=DISABLED          ;;
         --with-pcre=*)                   PCRE="$value"              ;;
@@ -143,9 +143,9 @@
         --with-zlib-opt=*)               ZLIB_OPT="$value"          ;;
         --with-zlib-asm=*)               ZLIB_ASM="$value"          ;;
 
-        --test-build-devpoll)            TEST_BUILD_DEVPOLL=YES     ;;
-        --test-build-epoll)              TEST_BUILD_EPOLL=YES       ;;
-        --test-build-rtsig)              TEST_BUILD_RTSIG=YES       ;;
+        --test-build-devpoll)            NGX_TEST_BUILD_DEVPOLL=YES ;;
+        --test-build-epoll)              NGX_TEST_BUILD_EPOLL=YES   ;;
+        --test-build-rtsig)              NGX_TEST_BUILD_RTSIG=YES   ;;
 
         *)
             echo "$0: error: invalid option \"$option\""
@@ -202,13 +202,13 @@
 fi
 
 
-if [ ".$PLATFORM" = ".win32" ]; then
+if [ ".$NGX_PLATFORM" = ".win32" ]; then
     NGX_WINE=$WINE
 fi
 
 
-if test -z "$PREFIX"; then
-    PREFIX=/usr/local/nginx
+if test -z "$NGX_PREFIX"; then
+    NGX_PREFIX=/usr/local/nginx
 fi
 
 
@@ -217,75 +217,75 @@
 fi
 
 
-case ".$SBIN_PATH" in
+case ".$NGX_SBIN_PATH" in
     ./*)
     ;;
 
     .)
-        SBIN_PATH=$PREFIX/sbin/nginx
+        NGX_SBIN_PATH=$NGX_PREFIX/sbin/nginx
     ;;
 
     *)
-        SBIN_PATH=$PREFIX/$SBIN_PATH
+        NGX_SBIN_PATH=$NGX_PREFIX/$NGX_SBIN_PATH
     ;;
 esac
 
 
-case ".$CONF_PATH" in
+case ".$NGX_CONF_PATH" in
     ./*)
     ;;
 
     .)
-        CONF_PATH=$PREFIX/conf/nginx.conf
+        NGX_CONF_PATH=$NGX_PREFIX/conf/nginx.conf
     ;;
 
     *)
-        CONF_PATH=$PREFIX/$CONF_PATH
+        NGX_CONF_PATH=$NGX_PREFIX/$NGX_CONF_PATH
     ;;
 esac
 
 
-case ".$PID_PATH" in
+case ".$NGX_PID_PATH" in
     ./*)
     ;;
 
     .)
-        PID_PATH=$PREFIX/logs/nginx.pid
+        NGX_PID_PATH=$NGX_PREFIX/logs/nginx.pid
     ;;
 
     *)
-        PID_PATH=$PREFIX/$PID_PATH
+        NGX_PID_PATH=$NGX_PREFIX/$NGX_PID_PATH
     ;;
 esac
 
 
-case ".$ERROR_LOG_PATH" in
+case ".$NGX_ERROR_LOG_PATH" in
     ./*)
     ;;
 
     .)
-        ERROR_LOG_PATH=$PREFIX/logs/error.log
+        NGX_ERROR_LOG_PATH=$NGX_PREFIX/logs/error.log
     ;;
 
     .stderr)
-        ERROR_LOG_PATH=
+        NGX_ERROR_LOG_PATH=
     ;;
 
     *)
-        ERROR_LOG_PATH=$PREFIX/$ERROR_LOG_PATH
+        NGX_ERROR_LOG_PATH=$NGX_PREFIX/$NGX_ERROR_LOG_PATH
     ;;
 esac
 
 
-case ".$HTTP_LOG_PATH" in
+case ".$NGX_HTTP_LOG_PATH" in
     ./*)
     ;;
 
     .)
-        HTTP_LOG_PATH=$PREFIX/logs/access.log
+        NGX_HTTP_LOG_PATH=$NGX_PREFIX/logs/access.log
     ;;
 
     *)
-        HTTP_LOG_PATH=$PREFIX/$HTTP_LOG_PATH
+        NGX_HTTP_LOG_PATH=$NGX_PREFIX/$NGX_HTTP_LOG_PATH
     ;;
 esac
diff --git a/auto/os/conf b/auto/os/conf
index 5dcf400..568b718 100644
--- a/auto/os/conf
+++ b/auto/os/conf
@@ -2,7 +2,7 @@
 # Copyright (C) Igor Sysoev
 
 
-if [ ".$PLATFORM" = "." ]; then
+if test -z "$NGX_PLATFORM"; then
     echo "checking for OS"
 
     SYSTEM=`uname -s 2>/dev/null`
@@ -11,12 +11,12 @@
 
     echo " + $SYSTEM $RELEASE $MACHINE"
 
-    PLATFORM="$SYSTEM:$RELEASE:$MACHINE";
+    NGX_PLATFORM="$SYSTEM:$RELEASE:$MACHINE";
 else
-    echo "building for $PLATFORM"
+    echo "building for $NGX_PLATFORM"
 fi
 
-case $PLATFORM in
+case $NGX_PLATFORM in
 
     FreeBSD:* | DragonFly:*)
         . auto/os/freebsd
@@ -43,7 +43,7 @@
 esac
 
 
-if [ $PLATFORM != win32 ]; then
+if [ $NGX_PLATFORM != win32 ]; then
 
     if test -z "$NGX_USER"; then
         NGX_USER=nobody
@@ -52,7 +52,7 @@
 
 
     ngx_feature="/dev/poll"
-    ngx_feature_name="devpoll"
+    ngx_feature_name="NGX_HAVE_DEVPOLL"
     ngx_feature_run=no
     ngx_feature_incs="#include <sys/devpoll.h>"
     ngx_feature_libs=
@@ -65,7 +65,6 @@
     . auto/feature
 
     if [ $ngx_found = yes ]; then
-        have=HAVE_DEVPOLL . auto/have
         CORE_SRCS="$CORE_SRCS $DEVPOLL_SRCS"
         EVENT_MODULES="$EVENT_MODULES $DEVPOLL_MODULE"
         EVENT_FOUND=YES
@@ -74,7 +73,7 @@
 
     if test -z "$NGX_KQUEUE_CHECKED"; then
         ngx_feature="kqueue"
-        ngx_feature_name="kqueue"
+        ngx_feature_name="NGX_HAVE_KQUEUE"
         ngx_feature_run=no
         ngx_feature_incs="#include <sys/event.h>"
         ngx_feature_libs=
@@ -83,14 +82,13 @@
 
         if [ $ngx_found = yes ]; then
 
-            have=HAVE_KQUEUE . auto/have
-            have=HAVE_CLEAR_EVENT . auto/have
+            have=NGX_HAVE_CLEAR_EVENT . auto/have
             EVENT_MODULES="$EVENT_MODULES $KQUEUE_MODULE"
             CORE_SRCS="$CORE_SRCS $KQUEUE_SRCS"
             EVENT_FOUND=YES
 
             ngx_feature="kqueue's NOTE_LOWAT"
-            ngx_feature_name="HAVE_LOWAT_EVENT"
+            ngx_feature_name="NGX_HAVE_LOWAT_EVENT"
             ngx_feature_run=no
             ngx_feature_incs="#include <sys/event.h>"
             ngx_feature_libs=
diff --git a/auto/os/freebsd b/auto/os/freebsd
index ba2e188..e35b933 100644
--- a/auto/os/freebsd
+++ b/auto/os/freebsd
@@ -45,7 +45,7 @@
 if [ $osreldate -gt 300007 ]; then
     echo " + using sendfile()"
 
-    have=HAVE_SENDFILE . auto/have
+    have=NGX_HAVE_SENDFILE . auto/have
     CORE_SRCS="$CORE_SRCS $FREEBSD_SENDFILE_SRCS"
 fi
 
@@ -57,8 +57,8 @@
 then
     echo " + using kqueue"
 
-    have=HAVE_KQUEUE . auto/have
-    have=HAVE_CLEAR_EVENT . auto/have
+    have=NGX_HAVE_KQUEUE . auto/have
+    have=NGX_HAVE_CLEAR_EVENT . auto/have
     EVENT_MODULES="$EVENT_MODULES $KQUEUE_MODULE"
     CORE_SRCS="$CORE_SRCS $KQUEUE_SRCS"
     EVENT_FOUND=YES
@@ -73,7 +73,7 @@
      -o $version -ge 500018 ]
 then
     echo " + using kqueue's NOTE_LOWAT"
-    have=HAVE_LOWAT_EVENT . auto/have
+    have=NGX_HAVE_LOWAT_EVENT . auto/have
 fi
 
 
@@ -85,7 +85,7 @@
 #
 #    if [ $version -gt 460101 ]; then
 #        echo " + kqueue's EVFILT_SIGNAL is safe"
-#        have=HAVE_SAFE_EVFILT_SIGNAL . auto/have
+#        have=NGX_HAVE_SAFE_EVFILT_SIGNAL . auto/have
 #    else
 #        echo "$0: error: the kqueue's EVFILT_SIGNAL is unsafe on this"
 #        echo "FreeBSD version, so --with-threads=rfork could not be used"
@@ -100,7 +100,7 @@
     if [ \( $version -lt 500000 -a $version -ge 430000 \) \
          -o $version -ge 500014 ]
     then
-        have=HAVE_AIO . auto/have
+        have=NGX_HAVE_AIO . auto/have
         EVENT_MODULES="$EVENT_MODULES $AIO_MODULE"
         CORE_SRCS="$CORE_SRCS $AIO_SRCS"
     else
diff --git a/auto/os/linux b/auto/os/linux
index e4cbd6d..687377b 100644
--- a/auto/os/linux
+++ b/auto/os/linux
@@ -37,7 +37,8 @@
 
 if [ $version -ge 131609 -o $EVENT_RTSIG = YES ]; then
     echo " + using rt signals"
-    have=HAVE_RTSIG . auto/have
+    have=NGX_HAVE_RTSIG . auto/have
+    have=NGX_HAVE_POLL . auto/have
     EVENT_MODULES="$EVENT_MODULES $RTSIG_MODULE"
     CORE_SRCS="$CORE_SRCS $RTSIG_SRCS"
     EVENT_FOUND=YES
@@ -47,7 +48,7 @@
 # epoll, EPOLLET version
 
 ngx_feature="epoll"
-ngx_feature_name="epoll"
+ngx_feature_name="NGX_HAVE_EPOLL"
 ngx_feature_run=no
 ngx_feature_incs="#include <sys/epoll.h>"
 ngx_feature_libs=
@@ -60,8 +61,7 @@
 . auto/feature
 
 if [ $ngx_found = yes ]; then
-    have=HAVE_EPOLL . auto/have
-    have=HAVE_CLEAR_EVENT . auto/have
+    have=NGX_HAVE_CLEAR_EVENT . auto/have
     CORE_SRCS="$CORE_SRCS $EPOLL_SRCS"
     EVENT_MODULES="$EVENT_MODULES $EPOLL_MODULE"
     EVENT_FOUND=YES
@@ -72,7 +72,7 @@
 
 CC_AUX_FLAGS="-D_GNU_SOURCE"
 ngx_feature="sendfile()"
-ngx_feature_name="sendfile"
+ngx_feature_name="NGX_HAVE_SENDFILE"
 ngx_feature_run=no
 ngx_feature_incs="#include <sys/sendfile.h>"
 ngx_feature_libs=
@@ -90,7 +90,7 @@
 
 CC_AUX_FLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64"
 ngx_feature="sendfile64()"
-ngx_feature_name="HAVE_SENDFILE64"
+ngx_feature_name="NGX_HAVE_SENDFILE64"
 ngx_feature_run=no
 ngx_feature_incs="#include <sys/sendfile.h>"
 ngx_feature_libs=
@@ -105,7 +105,7 @@
 # prctl(PR_SET_DUMPABLE)
 
 ngx_feature="prctl(PR_SET_DUMPABLE)"
-ngx_feature_name="HAVE_PR_SET_DUMPABLE"
+ngx_feature_name="NGX_HAVE_PR_SET_DUMPABLE"
 ngx_feature_run=yes
 ngx_feature_incs="#include <sys/prctl.h>"
 ngx_feature_libs=
diff --git a/auto/os/solaris b/auto/os/solaris
index 62708cd..723ad84 100644
--- a/auto/os/solaris
+++ b/auto/os/solaris
@@ -23,7 +23,7 @@
 CC_AUX_FLAGS="-D_FILE_OFFSET_BITS=64 -lrt"
 
 
-case $PLATFORM in
+case $NGX_PLATFORM in
 
     *:sun4u)
         # "-mcpu=v9" enables the "casa" assembler instruction
@@ -43,7 +43,7 @@
 
 
 ngx_feature="sendfilev()"
-ngx_feature_name="sendfile"
+ngx_feature_name="NGX_HAVE_SENDFILE"
 ngx_feature_run=no
 ngx_feature_incs="#include <sys/sendfile.h>"
 ngx_feature_libs="-lsendfile"
@@ -54,7 +54,6 @@
 
 
 if [ $ngx_found = yes ]; then
-    have=HAVE_SENDFILE . auto/have
     CORE_SRCS="$CORE_SRCS $SOLARIS_SENDFILEV_SRCS"
     CORE_LIBS="$CORE_LIBS -lsendfile"
 fi
diff --git a/auto/os/win32 b/auto/os/win32
index dfbb246..5567535 100644
--- a/auto/os/win32
+++ b/auto/os/win32
@@ -26,5 +26,5 @@
     EVENT_MODULES="$EVENT_MODULES $SELECT_MODULE"
 fi
 
-have=HAVE_AIO . auto/have
-have=HAVE_IOCP . auto/have
+have=NGX_HAVE_AIO . auto/have
+have=NGX_HAVE_IOCP . auto/have
diff --git a/auto/summary b/auto/summary
index b8fb81d..39a1599 100644
--- a/auto/summary
+++ b/auto/summary
@@ -95,14 +95,14 @@
 fi
 
 
-echo "  nginx path prefix: $PREFIX"
-echo "  nginx binary file: $SBIN_PATH"
-echo "  nginx configuration file: $CONF_PATH"
-echo "  nginx pid file: $PID_PATH"
-if [ ".$ERROR_LOG_PATH" != "." ]; then
-    echo "  nginx error log file: $ERROR_LOG_PATH"
+echo "  nginx path prefix: $NGX_PREFIX"
+echo "  nginx binary file: $NGX_SBIN_PATH"
+echo "  nginx configuration file: $NGX_CONF_PATH"
+echo "  nginx pid file: $NGX_PID_PATH"
+if test -n "$NGX_ERROR_LOG_PATH"; then
+    echo "  nginx error log file: $NGX_ERROR_LOG_PATH"
 else
     echo "  nginx logs errors to stderr"
 fi
-echo "  nginx http access log file: $HTTP_LOG_PATH"
+echo "  nginx http access log file: $NGX_HTTP_LOG_PATH"
 echo
diff --git a/auto/threads b/auto/threads
index a12eed3..da03036 100644
--- a/auto/threads
+++ b/auto/threads
@@ -9,7 +9,7 @@
         CORE_DEPS="$CORE_DEPS $FREEBSD_RFORK_DEPS"
         CORE_SRCS="$CORE_SRCS $FREEBSD_RFORK_SRCS"
 
-        case $PLATFORM in
+        case $NGX_PLATFORM in
             *:i386)
                 if [ \( $version -gt 500000 -a $version -lt 501000 \) \
                      -o $version -lt 491000 ]
@@ -42,7 +42,7 @@
     ;;
 
     libc_r)
-        case $PLATFORM in
+        case $NGX_PLATFORM in
             FreeBSD:[34]*)
                 have=NGX_THREADS . auto/have
                 CFLAGS="$CFLAGS -pthread"
diff --git a/auto/unix b/auto/unix
index f0e7f2e..7cd1dfe 100755
--- a/auto/unix
+++ b/auto/unix
@@ -74,7 +74,7 @@
 
 
 ngx_feature="setproctitle()"
-ngx_feature_name="HAVE_SETPROCTITLE"
+ngx_feature_name="NGX_HAVE_SETPROCTITLE"
 ngx_feature_run=no
 ngx_feature_incs=
 ngx_feature_libs=
@@ -83,7 +83,7 @@
 
 
 ngx_feature="pread()"
-ngx_feature_name="pread"
+ngx_feature_name="NGX_HAVE_PREAD"
 ngx_feature_run=no
 ngx_feature_incs=
 ngx_feature_libs=
@@ -92,7 +92,7 @@
 
 
 ngx_feature="pwrite()"
-ngx_feature_name="pwrite"
+ngx_feature_name="NGX_HAVE_PWRITE"
 ngx_feature_run=no
 ngx_feature_incs=
 ngx_feature_libs=
@@ -101,7 +101,7 @@
 
 
 ngx_feature="strerror_r()"
-ngx_feature_name="strerror_r"
+ngx_feature_name="NGX_HAVE_STRERROR_R"
 ngx_feature_run=yes
 ngx_feature_incs="#include <string.h>"
 ngx_feature_libs=
@@ -113,7 +113,7 @@
 # GNU style strerror_r() returns not length, but pointer
 
 ngx_feature="gnu style strerror_r()"
-ngx_feature_name="gnu_strerror_r"
+ngx_feature_name="NGX_HAVE_GNU_STRERROR_R"
 ngx_feature_run=yes
 ngx_feature_incs="#include <string.h>"
 ngx_feature_libs=
@@ -123,7 +123,7 @@
 
 
 ngx_feature="localtime_r()"
-ngx_feature_name="localtime_r"
+ngx_feature_name="NGX_HAVE_LOCALTIME_R"
 ngx_feature_run=no
 ngx_feature_incs="#include <time.h>"
 ngx_feature_libs=
@@ -132,7 +132,7 @@
 
 
 ngx_feature="posix_memalign()"
-ngx_feature_name="posix_memalign"
+ngx_feature_name="NGX_HAVE_POSIX_MEMALIGN"
 ngx_feature_run=no
 ngx_feature_incs="#include <stdlib.h>"
 ngx_feature_libs=
@@ -141,7 +141,7 @@
 
 
 ngx_feature="memalign()"
-ngx_feature_name="memalign"
+ngx_feature_name="NGX_HAVE_MEMALIGN"
 ngx_feature_run=no
 ngx_feature_incs="#include <stdlib.h>"
 ngx_feature_libs=
@@ -150,7 +150,7 @@
 
 
 ngx_feature="sched_yield()"
-ngx_feature_name="HAVE_SCHED_YIELD"
+ngx_feature_name="NGX_HAVE_SCHED_YIELD"
 ngx_feature_run=no
 ngx_feature_incs="#include <sched.h>"
 ngx_feature_libs=
@@ -159,7 +159,7 @@
 
 
 ngx_feature="mmap(MAP_ANON|MAP_SHARED)"
-ngx_feature_name="MAP_ANON"
+ngx_feature_name="NGX_HAVE_MAP_ANON"
 ngx_feature_run=yes
 ngx_feature_incs="#include <sys/mman.h>"
 ngx_feature_libs=
@@ -171,7 +171,7 @@
 
 
 ngx_feature='mmap("/dev/zero", MAP_SHARED)'
-ngx_feature_name="MAP_DEVZERO"
+ngx_feature_name="NGX_HAVE_MAP_DEVZERO"
 ngx_feature_run=yes
 ngx_feature_incs="#include <sys/mman.h>
 #include <sys/stat.h>
@@ -185,7 +185,7 @@
 
 
 ngx_feature="System V shared memory"
-ngx_feature_name="SYSVSHM"
+ngx_feature_name="NGX_HAVE_SYSVSHM"
 ngx_feature_run=yes
 ngx_feature_incs="#include <sys/ipc.h>
 #include <sys/shm.h>"
@@ -198,7 +198,7 @@
 
 
 ngx_feature="struct msghdr.msg_control"
-ngx_feature_name="msghdr_msg_control"
+ngx_feature_name="NGX_HAVE_MSGHDR_MSG_CONTROL"
 ngx_feature_run=no
 ngx_feature_incs="#include <sys/socket.h>"
 ngx_feature_libs=
@@ -207,7 +207,7 @@
 
 
 ngx_feature="ioctl(FIONBIO)"
-ngx_feature_name="FIONBIO"
+ngx_feature_name="NGX_HAVE_FIONBIO"
 ngx_feature_run=no
 ngx_feature_incs="#include <sys/ioctl.h>
 $NGX_INCLUDE_SYS_FILIO_H"
@@ -217,7 +217,7 @@
 
 
 ngx_feature="struct tm.tm_gmtoff"
-ngx_feature_name="gmtoff"
+ngx_feature_name="NGX_HAVE_GMTOFF"
 ngx_feature_run=no
 ngx_feature_incs="#include <time.h>"
 ngx_feature_libs=
diff --git a/docs/xml/nginx/changes.xml b/docs/xml/nginx/changes.xml
index 43fda88..f460dbb 100644
--- a/docs/xml/nginx/changes.xml
+++ b/docs/xml/nginx/changes.xml
@@ -6,6 +6,54 @@
             title="nginx">
 
 
+<changes ver="0.1.9" date="25.11.2004">
+
+<change type="bugfix">
+<para lang="ru">
+ÅÓÌÉ × ÚÁÐÒÏÓÅ ÅÓÔØ "//", "/./", "/../" ÉÌÉ "%XX", ÔÏ ÐÒÏËÓÉÒÕÅÍÙÊ
+ÚÁÐÒÏÓ ÐÅÒÅÄÁ×ÁÌÓÑ ÂÅÚ ÁÒÇÕÍÅÎÔÏ×.
+</para>
+<para lang="en">
+the proxied request was sent without arguments if the request contains
+"//", "/./", "/../" or "%XX".
+</para>
+</change>
+
+<change type="bugfix">
+<para lang="ru">
+ÐÒÉ ÓÖÁÔÉÉ ÂÏÌØÛÉÈ ÏÔ×ÅÔÏ× ÉÎÏÇÄÁ ÏÎÉ ÐÅÒÅÄÁ×ÁÌÉÓØ ÎÅ ÐÏÌÎÏÓÔØÀ.
+</para>
+<para lang="en">
+the large compressed responses may be transferred not completely.
+</para>
+</change>
+
+<change type="bugfix">
+<para lang="ru">
+ÎÅ ÐÅÒÅÄÁ×ÁÌÉÓØ ÆÁÊÌÙ ÂÏÌØÛÅ 2G ÎÁ Linux, ÎÅÐÏÄÄÅÒÖÉ×ÁÀÝÅÍ sendfile64().
+</para>
+<para lang="en">
+the files bigger than 2G was not transferred on Linux that does not support
+sendfile64().
+</para>
+</change>
+
+<change type="bugfix">
+<para lang="ru">
+ÎÁ Linux ÐÒÉ ËÏÎÆÉÇÕÒÁÃÉÉ ÓÂÏÒËÉ ÎÕÖÎÏ ÂÙÌÏ ÏÂÑÚÁÔÅÌØÎÏ ÉÓÐÏÌØÚÏ×ÁÔØ
+ÐÁÒÁÍÅÔÒ --with-poll_module;
+ÏÛÉÂËÁ ÐÏÑ×ÉÌÁÓØ × 0.1.8.
+</para>
+<para lang="en">
+while the build configuration on Linux the --with-poll_module parameter
+was required;
+bug appeared in 0.1.8.
+</para>
+</change>
+
+</changes>
+
+
 <changes ver="0.1.8" date="20.11.2004">
 
 <change type="bugfix">
diff --git a/src/core/nginx.c b/src/core/nginx.c
index 53ac666..887fc79 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -112,7 +112,7 @@
 
 
 
-int main(int argc, char *const *argv, char *const *envp)
+int main(int argc, char *const *argv)
 {
     ngx_int_t         i;
     ngx_log_t        *log;
diff --git a/src/core/nginx.h b/src/core/nginx.h
index 5f2339b..d737d6b 100644
--- a/src/core/nginx.h
+++ b/src/core/nginx.h
@@ -8,7 +8,7 @@
 #define _NGINX_H_INCLUDED_
 
 
-#define NGINX_VER          "nginx/0.1.8"
+#define NGINX_VER          "nginx/0.1.9"
 
 #define NGINX_VAR          "NGINX"
 #define NGX_NEWPID_EXT     ".newbin"
diff --git a/src/core/ngx_buf.c b/src/core/ngx_buf.c
index 7d37989..dedf444 100644
--- a/src/core/ngx_buf.c
+++ b/src/core/ngx_buf.c
@@ -140,7 +140,7 @@
             break;
         }
 
-#if (HAVE_WRITE_ZEROCOPY)
+#if (NGX_HAVE_WRITE_ZEROCOPY)
         if ((*busy)->buf->zerocopy_busy) {
             break;
         }
diff --git a/src/core/ngx_config.h b/src/core/ngx_config.h
index 43fd985..916b1b5 100644
--- a/src/core/ngx_config.h
+++ b/src/core/ngx_config.h
@@ -11,6 +11,13 @@
 #include <ngx_auto_headers.h>
 
 
+#if ((__GNU__ == 2) && (__GNUC_MINOR__ < 8))
+#define NGX_MAX_UINT32_VALUE  0xffffffffLL
+#else
+#define NGX_MAX_UINT32_VALUE  0xffffffff
+#endif
+
+
 #if defined __DragonFly__ && !defined __FreeBSD__
 #define __FreeBSD__        4
 #define __FreeBSD_version  480101
@@ -127,12 +134,5 @@
 #define NGX_MAXHOSTNAMELEN MAXHOSTNAMELEN
 */
 
-#if ((__GNU__ == 2) && (__GNUC_MINOR__ < 8))
-#define NGX_MAX_UINT32_VALUE  0xffffffffLL
-#else
-#define NGX_MAX_UINT32_VALUE  0xffffffff
-#endif
-
-
 
 #endif /* _NGX_CONFIG_H_INCLUDED_ */
diff --git a/src/core/ngx_connection.h b/src/core/ngx_connection.h
index e2257ac..40f19a8 100644
--- a/src/core/ngx_connection.h
+++ b/src/core/ngx_connection.h
@@ -48,7 +48,7 @@
     unsigned          nonblocking_accept:1;
     unsigned          nonblocking:1;
     unsigned          shared:1;    /* shared between threads or processes */
-#if (HAVE_DEFERRED_ACCEPT)
+#if (NGX_HAVE_DEFERRED_ACCEPT)
     unsigned          deferred_accept:1;
 #endif
 
@@ -101,7 +101,7 @@
     ngx_ssl_t          *ssl;
 #endif
 
-#if (HAVE_IOCP)
+#if (NGX_HAVE_IOCP)
     struct sockaddr    *local_sockaddr;
     socklen_t           local_socklen;
 #endif
@@ -122,7 +122,7 @@
     unsigned            tcp_nodelay:1;
     signed              tcp_nopush:2;
 
-#if (HAVE_IOCP)
+#if (NGX_HAVE_IOCP)
     unsigned            accept_context_updated:1;
 #endif
 
diff --git a/src/core/ngx_output_chain.c b/src/core/ngx_output_chain.c
index d2fbf12..1c367cc 100644
--- a/src/core/ngx_output_chain.c
+++ b/src/core/ngx_output_chain.c
@@ -9,11 +9,18 @@
 #include <ngx_event.h>
 
 
-#define NGX_NONE      1
+#if 0
+#define NGX_SENDFILE_LIMIT  4096
+#endif
+
+
+#define NGX_NONE            1
 
 
 static ngx_inline ngx_int_t
     ngx_output_chain_need_to_copy(ngx_output_chain_ctx_t *ctx, ngx_buf_t *buf);
+static ngx_int_t ngx_output_chain_add_copy(ngx_pool_t *pool,
+                                          ngx_chain_t **chain, ngx_chain_t *in);
 static ngx_int_t ngx_output_chain_copy_buf(ngx_buf_t *dst, ngx_buf_t *src,
                                            ngx_uint_t sendfile);
 
@@ -26,17 +33,20 @@
 
     if (ctx->in == NULL && ctx->busy == NULL) {
 
-       /*
-        * the short path for the case when the ctx->in and ctx->busy chains
-        * are empty, the incoming chain is empty too or has the single buf
-        * that does not require the copy
-        */
+        /*
+         * the short path for the case when the ctx->in and ctx->busy chains
+         * are empty, the incoming chain is empty too or has the single buf
+         * that does not require the copy
+         */
 
         if (in == NULL) {
             return ctx->output_filter(ctx->filter_ctx, in);
         }
 
         if (in->next == NULL
+#if (NGX_SENDFILE_LIMIT)
+            && !(in->buf->in_file && in->buf->file_last > NGX_SENDFILE_LIMIT)
+#endif
             && (!ngx_output_chain_need_to_copy(ctx, in->buf)))
         {
             return ctx->output_filter(ctx->filter_ctx, in);
@@ -46,7 +56,7 @@
     /* add the incoming buf to the chain ctx->in */
 
     if (in) {
-        if (ngx_chain_add_copy(ctx->pool, &ctx->in, in) == NGX_ERROR) {
+        if (ngx_output_chain_add_copy(ctx->pool, &ctx->in, in) == NGX_ERROR) {
             return NGX_ERROR;
         }
     }
@@ -191,11 +201,23 @@
 static ngx_inline ngx_int_t
     ngx_output_chain_need_to_copy(ngx_output_chain_ctx_t *ctx, ngx_buf_t *buf)
 {
+    ngx_uint_t  sendfile;
+
     if (ngx_buf_special(buf)) {
         return 0;
     }
 
-    if (!ctx->sendfile) {
+    sendfile = ctx->sendfile;
+
+#if (NGX_SENDFILE_LIMIT)
+
+    if (buf->in_file && buf->file_pos >= NGX_SENDFILE_LIMIT) {
+        sendfile = 0;
+    }
+
+#endif
+
+    if (!sendfile) {
 
         if (!ngx_buf_in_memory(buf)) {
             return 1;
@@ -216,6 +238,71 @@
 }
 
 
+static ngx_int_t ngx_output_chain_add_copy(ngx_pool_t *pool,
+                                           ngx_chain_t **chain, ngx_chain_t *in)
+{
+    ngx_chain_t  *cl, **ll;
+#if (NGX_SENDFILE_LIMIT)
+    ngx_buf_t    *b, *buf;
+#endif
+
+    ll = chain;
+
+    for (cl = *chain; cl; cl = cl->next) {
+        ll = &cl->next;
+    }
+
+    while (in) {
+
+        if (!(cl = ngx_alloc_chain_link(pool))) {
+            return NGX_ERROR;
+        }
+
+#if (NGX_SENDFILE_LIMIT)
+
+        buf = in->buf;
+
+        if (buf->in_file
+            && buf->file_pos < NGX_SENDFILE_LIMIT
+            && buf->file_last > NGX_SENDFILE_LIMIT)
+        {
+            if (!(b = ngx_calloc_buf(pool))) {
+                return NGX_ERROR;
+            }
+
+            ngx_memcpy(b, buf, sizeof(ngx_buf_t));
+
+            if (ngx_buf_in_memory(buf)) {
+                buf->pos += (ssize_t) (NGX_SENDFILE_LIMIT - buf->file_pos);
+                b->last = buf->pos;
+            }
+
+            buf->file_pos = NGX_SENDFILE_LIMIT;
+            b->file_last = NGX_SENDFILE_LIMIT;
+
+            cl->buf = b;
+
+        } else {
+            cl->buf = buf;
+            in = in->next;
+        }
+
+#else
+        cl->buf = in->buf;
+        in = in->next;
+
+#endif
+
+        *ll = cl;
+        ll = &cl->next;
+    }
+
+    *ll = NULL;
+
+    return NGX_OK;
+}
+
+
 static ngx_int_t ngx_output_chain_copy_buf(ngx_buf_t *dst, ngx_buf_t *src,
                                            ngx_uint_t sendfile)
 {
@@ -228,6 +315,14 @@
         size = dst->end - dst->pos;
     }
 
+#if (NGX_SENDFILE_LIMIT)
+
+    if (src->in_file && src->file_pos >= NGX_SENDFILE_LIMIT) {
+        sendfile = 0;
+    }
+
+#endif
+
     if (ngx_buf_in_memory(src)) {
         ngx_memcpy(dst->pos, src->pos, size);
         src->pos += size;
diff --git a/src/core/ngx_times.c b/src/core/ngx_times.c
index f06d644..5ca235c 100644
--- a/src/core/ngx_times.c
+++ b/src/core/ngx_times.c
@@ -162,12 +162,12 @@
     ngx_cached_http_time.data = p;
 
 
-#if (HAVE_GETTIMEZONE)
+#if (NGX_HAVE_GETTIMEZONE)
 
     ngx_gmtoff = ngx_gettimezone();
     ngx_gmtime(s + ngx_gmtoff * 60, &tm);
 
-#elif (HAVE_GMTOFF)
+#elif (NGX_HAVE_GMTOFF)
 
     ngx_localtime(&tm);
     ngx_gmtoff = tm.ngx_tm_gmtoff / 60;
diff --git a/src/event/modules/ngx_aio_module.c b/src/event/modules/ngx_aio_module.c
index 398c571..bdd31cf 100644
--- a/src/event/modules/ngx_aio_module.c
+++ b/src/event/modules/ngx_aio_module.c
@@ -9,7 +9,7 @@
 #include <ngx_event.h>
 #include <ngx_aio.h>
 
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
 #include <ngx_kqueue_module.h>
 #endif
 
@@ -27,7 +27,7 @@
     ngx_aio_read_chain,
     ngx_aio_write,
     ngx_aio_write_chain,
-    NGX_HAVE_ZEROCOPY
+    0
 };
 
 
@@ -64,7 +64,7 @@
 
 
 
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
 
 static int ngx_aio_init(ngx_cycle_t *cycle)
 {
@@ -152,7 +152,7 @@
     return ngx_kqueue_module_ctx.actions.process_events(cycle);
 }
 
-#endif /* HAVE_KQUEUE */
+#endif /* NGX_HAVE_KQUEUE */
 
 
 #if 0
diff --git a/src/event/modules/ngx_devpoll_module.c b/src/event/modules/ngx_devpoll_module.c
index 663e2bf..1a48cec 100644
--- a/src/event/modules/ngx_devpoll_module.c
+++ b/src/event/modules/ngx_devpoll_module.c
@@ -9,7 +9,7 @@
 #include <ngx_event.h>
 
 
-#if (TEST_BUILD_DEVPOLL)
+#if (NGX_TEST_BUILD_DEVPOLL)
 
 /* Solaris declarations */
 
diff --git a/src/event/modules/ngx_epoll_module.c b/src/event/modules/ngx_epoll_module.c
index 8096932..a2eeab0 100644
--- a/src/event/modules/ngx_epoll_module.c
+++ b/src/event/modules/ngx_epoll_module.c
@@ -9,7 +9,7 @@
 #include <ngx_event.h>
 
 
-#if (TEST_BUILD_EPOLL)
+#if (NGX_TEST_BUILD_EPOLL)
 
 /* epoll declarations */
 
@@ -168,7 +168,7 @@
 
     ngx_event_actions = ngx_epoll_module_ctx.actions;
 
-#if (HAVE_CLEAR_EVENT)
+#if (NGX_HAVE_CLEAR_EVENT)
     ngx_event_flags = NGX_USE_CLEAR_EVENT
 #else
     ngx_event_flags = NGX_USE_LEVEL_EVENT
diff --git a/src/event/modules/ngx_kqueue_module.c b/src/event/modules/ngx_kqueue_module.c
index e0fae6f..49c22a9 100644
--- a/src/event/modules/ngx_kqueue_module.c
+++ b/src/event/modules/ngx_kqueue_module.c
@@ -189,7 +189,7 @@
     ngx_event_actions = ngx_kqueue_module_ctx.actions;
 
     ngx_event_flags = NGX_USE_ONESHOT_EVENT
-#if (HAVE_CLEAR_EVENT)
+#if (NGX_HAVE_CLEAR_EVENT)
                      |NGX_USE_CLEAR_EVENT
 #else
                      |NGX_USE_LEVEL_EVENT
diff --git a/src/event/modules/ngx_rtsig_module.c b/src/event/modules/ngx_rtsig_module.c
index 3c0ea95..d017f05 100644
--- a/src/event/modules/ngx_rtsig_module.c
+++ b/src/event/modules/ngx_rtsig_module.c
@@ -9,7 +9,7 @@
 #include <ngx_event.h>
 
 
-#if (TEST_BUILD_RTSIG)
+#if (NGX_TEST_BUILD_RTSIG)
 
 #define F_SETSIG       10
 #define SIGRTMIN       33
@@ -217,7 +217,7 @@
         return NGX_ERROR;
     }
 
-#if (HAVE_ONESIGFD)
+#if (NGX_HAVE_ONESIGFD)
     if (fcntl(c->fd, F_SETAUXFL, O_ONESIGFD) == -1) {
         ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno,
                       "fcntl(F_SETAUXFL) failed");
diff --git a/src/event/modules/ngx_select_module.c b/src/event/modules/ngx_select_module.c
index 14e6f81..0554ee9 100644
--- a/src/event/modules/ngx_select_module.c
+++ b/src/event/modules/ngx_select_module.c
@@ -258,7 +258,7 @@
     ngx_connection_t         *c;
     ngx_epoch_msec_t          delta;
     struct timeval            tv, *tp;
-#if (HAVE_SELECT_CHANGE_TIMEOUT)
+#if (NGX_HAVE_SELECT_CHANGE_TIMEOUT)
     static ngx_epoch_msec_t   deltas = 0;
 #endif
 
@@ -362,7 +362,7 @@
         err = 0;
     }
 
-#if (HAVE_SELECT_CHANGE_TIMEOUT)
+#if (NGX_HAVE_SELECT_CHANGE_TIMEOUT)
 
     if (timer != NGX_TIMER_INFINITE) {
         delta = timer - (tv.tv_sec * 1000 + tv.tv_usec / 1000);
@@ -403,7 +403,7 @@
         }
     }
 
-#else /* !(HAVE_SELECT_CHANGE_TIMEOUT) */
+#else /* !(NGX_HAVE_SELECT_CHANGE_TIMEOUT) */
 
     ngx_gettimeofday(&tv);
     ngx_time_update(tv.tv_sec);
@@ -427,7 +427,7 @@
         }
     }
 
-#endif /* HAVE_SELECT_CHANGE_TIMEOUT */
+#endif /* NGX_HAVE_SELECT_CHANGE_TIMEOUT */
 
     ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
                    "select ready %d", ready);
diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c
index b3bf530..bd451bc 100644
--- a/src/event/ngx_event.c
+++ b/src/event/ngx_event.c
@@ -371,7 +371,7 @@
 
         rev->accept = 1;
 
-#if (HAVE_DEFERRED_ACCEPT)
+#if (NGX_HAVE_DEFERRED_ACCEPT)
         rev->deferred_accept = s[i].deferred_accept;
 #endif
 
@@ -719,7 +719,7 @@
     rtsig = 0;
     fd = 0;
 
-#if (HAVE_EPOLL) && !(TEST_BUILD_EPOLL)
+#if (NGX_HAVE_EPOLL) && !(NGX_TEST_BUILD_EPOLL)
 
     fd = epoll_create(100);
 
@@ -735,7 +735,7 @@
 
 #endif
 
-#if (HAVE_RTSIG)
+#if (NGX_HAVE_RTSIG)
 
     if (module == NULL) {
         connections = DEFAULT_CONNECTIONS;
@@ -745,21 +745,21 @@
 
 #endif
 
-#if (HAVE_DEVPOLL)
+#if (NGX_HAVE_DEVPOLL)
 
     connections = DEFAULT_CONNECTIONS;
     module = &ngx_devpoll_module;
 
 #endif
 
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
 
     connections = DEFAULT_CONNECTIONS;
     module = &ngx_kqueue_module;
 
 #endif
 
-#if (HAVE_SELECT)
+#if (NGX_HAVE_SELECT)
 
     if (module == NULL) {
 
diff --git a/src/event/ngx_event.h b/src/event/ngx_event.h
index 44728e3..d156a63 100644
--- a/src/event/ngx_event.h
+++ b/src/event/ngx_event.h
@@ -15,7 +15,7 @@
 #define NGX_INVALID_INDEX  0xd0d0d0d0
 
 
-#if (HAVE_IOCP)
+#if (NGX_HAVE_IOCP)
 
 typedef struct {
     WSAOVERLAPPED    ovlp;
@@ -86,7 +86,7 @@
     unsigned         accept_context_updated:1;
 #endif
 
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
     unsigned         kq_vnode:1;
 
     /* the pending errno reported by kqueue */
@@ -107,7 +107,7 @@
      *   accept:     1 if accept many, 0 otherwise
      */
 
-#if (HAVE_KQUEUE) || (HAVE_IOCP)
+#if (NGX_HAVE_KQUEUE) || (NGX_HAVE_IOCP)
     int              available;
 #else
     unsigned         available:1;
@@ -117,9 +117,9 @@
     ngx_event_handler_pt  event_handler;
 
 
-#if (HAVE_AIO)
+#if (NGX_HAVE_AIO)
 
-#if (HAVE_IOCP)
+#if (NGX_HAVE_IOCP)
     ngx_event_ovlp_t ovlp;
 #else
     struct aiocb     aiocb;
@@ -154,12 +154,12 @@
     unsigned         posted_timedout:1;
     unsigned         posted_eof:1;
 
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
     /* the pending errno reported by kqueue */
     int              posted_errno;
 #endif
 
-#if (HAVE_KQUEUE) || (HAVE_IOCP)
+#if (NGX_HAVE_KQUEUE) || (NGX_HAVE_IOCP)
     int              posted_available;
 #else
     unsigned         posted_available:1;
@@ -272,7 +272,7 @@
 
 /*
  * Need to add socket or handle only once - i/o completion port.
- * It also requires HAVE_AIO and NGX_USE_AIO_EVENT to be set.
+ * It also requires NGX_HAVE_AIO and NGX_USE_AIO_EVENT to be set.
  */
 #define NGX_USE_IOCP_EVENT       0x00000200
 
@@ -296,7 +296,7 @@
 #define NGX_VNODE_EVENT    0
 
 
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
 
 #define NGX_READ_EVENT     EVFILT_READ
 #define NGX_WRITE_EVENT    EVFILT_WRITE
@@ -325,7 +325,7 @@
 #define NGX_DISABLE_EVENT  EV_DISABLE
 
 
-#elif (HAVE_DEVPOLL)
+#elif (NGX_HAVE_DEVPOLL)
 
 #define NGX_READ_EVENT     POLLIN
 #define NGX_WRITE_EVENT    POLLOUT
@@ -334,7 +334,7 @@
 #define NGX_ONESHOT_EVENT  1
 
 
-#elif (HAVE_EPOLL)
+#elif (NGX_HAVE_EPOLL)
 
 #define NGX_READ_EVENT     EPOLLIN
 #define NGX_WRITE_EVENT    EPOLLOUT
@@ -347,7 +347,7 @@
 #endif
 
 
-#elif (HAVE_POLL)
+#elif (NGX_HAVE_POLL)
 
 #define NGX_READ_EVENT     POLLIN
 #define NGX_WRITE_EVENT    POLLOUT
@@ -364,10 +364,10 @@
 #define NGX_LEVEL_EVENT    0
 #define NGX_ONESHOT_EVENT  1
 
-#endif /* HAVE_KQUEUE */
+#endif /* NGX_HAVE_KQUEUE */
 
 
-#if (HAVE_IOCP)
+#if (NGX_HAVE_IOCP)
 #define NGX_IOCP_ACCEPT      0
 #define NGX_IOCP_IO          1
 #define NGX_IOCP_CONNECT     2
diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c
index b5c5b72..294f3b4 100644
--- a/src/event/ngx_event_openssl.c
+++ b/src/event/ngx_event_openssl.c
@@ -9,7 +9,7 @@
 #include <ngx_event.h>
 
 
-static ngx_int_t ngx_ssl_write(ngx_connection_t *c, u_char *data, size_t size);
+static ssize_t ngx_ssl_write(ngx_connection_t *c, u_char *data, size_t size);
 
 
 ngx_int_t ngx_ssl_init(ngx_log_t *log)
@@ -58,7 +58,7 @@
 }
 
 
-ngx_int_t ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size)
+ssize_t ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size)
 {
     int         n, sslerr;
     ngx_err_t   err;
@@ -239,7 +239,7 @@
 }
 
 
-static ngx_int_t ngx_ssl_write(ngx_connection_t *c, u_char *data, size_t size)
+static ssize_t ngx_ssl_write(ngx_connection_t *c, u_char *data, size_t size)
 {
     int         n, sslerr;
     ngx_err_t   err;
diff --git a/src/event/ngx_event_openssl.h b/src/event/ngx_event_openssl.h
index 69d8d12..dbdb5f7 100644
--- a/src/event/ngx_event_openssl.h
+++ b/src/event/ngx_event_openssl.h
@@ -41,7 +41,7 @@
 
 #define ngx_ssl_handshake(c)     NGX_OK
 
-ngx_int_t ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size);
+ssize_t ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size);
 ngx_chain_t *ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in,
                                 off_t limit);
 ngx_int_t ngx_ssl_shutdown(ngx_connection_t *c);
diff --git a/src/event/ngx_event_pipe.c b/src/event/ngx_event_pipe.c
index a2edc71..3ca8a0c 100644
--- a/src/event/ngx_event_pipe.c
+++ b/src/event/ngx_event_pipe.c
@@ -132,7 +132,7 @@
                 p->upstream_eof = 1;
                 p->read = 1;
 
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
                 if (p->upstream->read->kq_errno) {
                     p->upstream->read->error = 1;
                     p->upstream_error = 1;
diff --git a/src/event/ngx_event_posted.c b/src/event/ngx_event_posted.c
index aed07fa..a99a434 100644
--- a/src/event/ngx_event_posted.c
+++ b/src/event/ngx_event_posted.c
@@ -120,7 +120,7 @@
             ev->ready |= ev->posted_ready;
             ev->timedout |= ev->posted_timedout;
             ev->pending_eof |= ev->posted_eof;
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
             ev->kq_errno |= ev->posted_errno;
 #endif
             if (ev->posted_available) {
@@ -130,7 +130,7 @@
             ev->posted_ready = 0;
             ev->posted_timedout = 0;
             ev->posted_eof = 0;
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
             ev->posted_errno = 0;
 #endif
             ev->posted_available = 0;
diff --git a/src/http/modules/ngx_http_gzip_filter.c b/src/http/modules/ngx_http_gzip_filter.c
index f8980af..b093d58 100644
--- a/src/http/modules/ngx_http_gzip_filter.c
+++ b/src/http/modules/ngx_http_gzip_filter.c
@@ -237,14 +237,14 @@
 
 static u_char  gzheader[10] = { 0x1f, 0x8b, Z_DEFLATED, 0, 0, 0, 0, 0, 0, 3 };
 
-#if (HAVE_LITTLE_ENDIAN)
+#if (NGX_HAVE_LITTLE_ENDIAN)
 
 struct gztrailer {
     uint32_t  crc32;
     uint32_t  zlen;
 };
 
-#else /* HAVE_BIG_ENDIAN */
+#else /* NGX_HAVE_BIG_ENDIAN */
 
 struct gztrailer {
     u_char  crc32[4];
@@ -437,7 +437,8 @@
 static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r,
                                            ngx_chain_t *in)
 {
-    int                    rc, wbits, memlevel, last;
+    int                    rc, wbits, memlevel;
+    ngx_int_t              last;
     struct gztrailer      *trailer;
     ngx_buf_t             *b;
     ngx_chain_t           *cl;
@@ -469,7 +470,7 @@
         /*
          * We preallocate a memory for zlib in one buffer (200K-400K), this
          * dicreases a number of malloc() and free() calls and also probably
-         * dicreases a number of syscalls (sbrk() or so).
+         * dicreases a number of syscalls (sbrk() and so on).
          * Besides we free this memory as soon as the gzipping will complete
          * and do not wait while a whole response will be sent to a client.
          *
@@ -512,8 +513,19 @@
         }
         cl->buf = b;
         cl->next = NULL;
-        ctx->out = cl;
-        ctx->last_out = &cl->next;
+
+        /*
+         * We pass the gzheader to the next filter now to avoid its linking
+         * to the ctx->busy chain.  zlib does not usually output the compressed
+         * data in the initial iterations, so the gzheader that was linked
+         * to the ctx->busy chain would be flushed by ngx_http_write_filter().
+         */
+
+        if (ngx_http_next_body_filter(r, cl) == NGX_ERROR) {
+            return ngx_http_gzip_error(ctx);
+        }
+
+        ctx->last_out = &ctx->out;
 
         ctx->crc32 = crc32(0L, Z_NULL, 0);
         ctx->flush = Z_NO_FLUSH;
@@ -727,7 +739,7 @@
                     b->last += 8;
                 }
 
-#if (HAVE_LITTLE_ENDIAN)
+#if (NGX_HAVE_LITTLE_ENDIAN)
                 trailer->crc32 = ctx->crc32;
                 trailer->zlen = ctx->zin;
 #else
@@ -763,7 +775,7 @@
             }
         }
 
-        if (last == NGX_AGAIN) {
+        if (last == NGX_AGAIN && !ctx->done) {
             return NGX_AGAIN;
         }
 
@@ -881,7 +893,9 @@
 {
     deflateEnd(&ctx->zstream);
 
-    ngx_pfree(ctx->request->pool, ctx->preallocated);
+    if (ctx->preallocated) {
+        ngx_pfree(ctx->request->pool, ctx->preallocated);
+    }
 
     ctx->zstream.avail_in = 0;
     ctx->zstream.avail_out = 0;
diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_handler.c
index 013f62b..3386953 100644
--- a/src/http/modules/ngx_http_index_handler.c
+++ b/src/http/modules/ngx_http_index_handler.c
@@ -10,19 +10,19 @@
 
 
 typedef struct {
-    ngx_array_t             indices;
-    size_t                  max_index_len;
-    ngx_http_cache_hash_t  *index_cache;
+    ngx_array_t              indices;
+    size_t                   max_index_len;
+    ngx_http_cache_hash_t   *index_cache;
 } ngx_http_index_loc_conf_t;
 
 
 typedef struct {
-    ngx_uint_t         index;
-    u_char            *last;
-    ngx_str_t          path;
-    ngx_str_t          redirect;
-    ngx_http_cache_t  *cache;
-    unsigned           tested:1;
+    ngx_uint_t               index;
+    u_char                  *last;
+    ngx_str_t                path;
+    ngx_str_t                redirect;
+    ngx_http_cache_entry_t  *cache;
+    ngx_uint_t               tested; /* unsigned  tested:1 */
 } ngx_http_index_ctx_t;
 
 
diff --git a/src/http/modules/proxy/ngx_http_proxy_cache.c b/src/http/modules/proxy/ngx_http_proxy_cache.c
index f0b56f5..86b8424 100644
--- a/src/http/modules/proxy/ngx_http_proxy_cache.c
+++ b/src/http/modules/proxy/ngx_http_proxy_cache.c
@@ -297,7 +297,7 @@
 
     if (rc == NGX_AGAIN) {
 
-        if ((ngx_event_flags & (NGX_USE_CLEAR_EVENT|NGX_HAVE_KQUEUE_EVENT))
+        if ((ngx_event_flags & (NGX_USE_CLEAR_EVENT|NGX_USE_KQUEUE_EVENT))
             && !p->request->connection->write->active)
         {
             /*
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c
index c0a8cf3..425a1a6 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.c
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.c
@@ -414,7 +414,7 @@
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, 0,
                    "http proxy check client, write event:%d", ev->write);
 
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
 
     if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
 
@@ -563,9 +563,9 @@
      */
 
 #if 0
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
 
-    if ((ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) && rev->kq_eof) {
+    if ((ngx_event_flags & NGX_USE_KQUEUE_EVENT) && rev->kq_eof) {
         ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock);
 
         ngx_del_timer(rev);
@@ -1400,7 +1400,7 @@
         return NGX_CONF_ERROR;
     }
 
-#elif !(HAVE_SO_SNDLOWAT)
+#elif !(NGX_HAVE_SO_SNDLOWAT)
 
     ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
                        "\"proxy_send_lowat\" is not supported, ignored");
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.h b/src/http/modules/proxy/ngx_http_proxy_handler.h
index 094ee3b..8ab88ad 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.h
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.h
@@ -142,7 +142,7 @@
 
 
 typedef struct {
-    ngx_http_cache_ctx_t             ctx;
+    ngx_http_cache_t                 ctx;
     ngx_uint_t                       status;
     ngx_str_t                        status_line;
 
diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c
index 0852a42..23d40c4 100644
--- a/src/http/modules/proxy/ngx_http_proxy_upstream.c
+++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c
@@ -782,7 +782,7 @@
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
                    "http proxy send request");
 
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
 
     if ((ngx_event_flags & NGX_USE_KQUEUE_EVENT)
         && !p->request_sent
@@ -1287,8 +1287,8 @@
         header->length = r->headers_out.content_length_n;
         p->cache->ctx.length = r->headers_out.content_length_n;
 
-        header->key_len = p->cache->ctx.key.len;
-        ngx_memcpy(&header->key, p->cache->ctx.key.data, header->key_len);
+        header->key_len = p->cache->ctx.key0.len;
+        ngx_memcpy(&header->key, p->cache->ctx.key0.data, header->key_len);
         header->key[header->key_len] = LF;
     }
 
diff --git a/src/http/ngx_http_cache.c b/src/http/ngx_http_cache.c
index 22572a5..abdeae9 100644
--- a/src/http/ngx_http_cache.c
+++ b/src/http/ngx_http_cache.c
@@ -63,7 +63,7 @@
 
             c[i].refs++;
 
-            if ((!(c[i].notify && (ngx_event_flags & NGX_HAVE_KQUEUE_EVENT)))
+            if ((!(c[i].notify && (ngx_event_flags & NGX_USE_KQUEUE_EVENT)))
                 && (ngx_cached_time - c[i].updated >= hash->update))
             {
                 c[i].expired = 1;
diff --git a/src/http/ngx_http_cache.h b/src/http/ngx_http_cache.h
index 40f4852..aa66902 100644
--- a/src/http/ngx_http_cache.h
+++ b/src/http/ngx_http_cache.h
@@ -14,11 +14,12 @@
 
 
 /*
- * The 7 uses before an allocation.
+ * The 3 bits allows the 7 uses before the cache entry allocation.
  * We can use maximum 7 bits, i.e up to the 127 uses.
  */
 #define NGX_HTTP_CACHE_LAZY_ALLOCATION_BITS  3
 
+
 typedef struct {
     uint32_t         crc;
     ngx_str_t        key;
@@ -45,7 +46,7 @@
         off_t        size;
         ngx_str_t    value;
     } data;
-} ngx_http_cache_t;
+} ngx_http_cache_entry_t;
 
 
 typedef struct {
@@ -62,7 +63,7 @@
 #define NGX_HTTP_CACHE_NELTS  4
 
 typedef struct {
-    ngx_http_cache_t         *elts;
+    ngx_http_cache_entry_t   *elts;
     size_t                    hash;
     size_t                    nelts;
     time_t                    life;
@@ -76,9 +77,9 @@
 
 typedef struct {
     ngx_http_cache_hash_t    *hash;
-    ngx_http_cache_t         *cache;
+    ngx_http_cache_entry_t   *cache;
     ngx_file_t                file;
-    ngx_str_t                 key;
+    ngx_array_t               key;
     uint32_t                  crc;
     u_char                    md5[16];
     ngx_path_t               *path;
@@ -90,7 +91,10 @@
     ssize_t                   header_size;
     size_t                    file_start;
     ngx_log_t                *log;
-} ngx_http_cache_ctx_t;
+
+    /* STUB */
+    ngx_str_t                 key0;
+} ngx_http_cache_t;
 
 
 
@@ -99,6 +103,8 @@
 #define NGX_HTTP_CACHE_THE_SAME  3
 
 
+#if 0
+
 ngx_http_cache_t *ngx_http_cache_get(ngx_http_cache_hash_t *cache,
                                      ngx_http_cleanup_t *cleanup,
                                      ngx_str_t *key, uint32_t *crc);
@@ -127,5 +133,7 @@
 
 char *ngx_http_set_cache_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
 
+#endif
+
 
 #endif /* _NGX_HTTP_CACHE_H_INCLUDED_ */
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index c764b2a..c4cb8b9 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -1828,7 +1828,7 @@
         return NGX_CONF_ERROR;
     }
 
-#elif !(HAVE_SO_SNDLOWAT)
+#elif !(NGX_HAVE_SO_SNDLOWAT)
 
     ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
                        "\"send_lowat\" is not supported, ignored");
diff --git a/src/http/ngx_http_file_cache.c b/src/http/ngx_http_file_cache.c
index 8f920d2..1b258c9 100644
--- a/src/http/ngx_http_file_cache.c
+++ b/src/http/ngx_http_file_cache.c
@@ -9,19 +9,20 @@
 #include <ngx_http.h>
 
 
-#if (HAVE_OPENSSL_MD5_H)
+#if (NGX_HAVE_OPENSSL_MD5_H)
 #include <openssl/md5.h>
 #else
 #include <md5.h>
 #endif
 
-#if (HAVE_OPENSSL_MD5)
+#if (NGX_OPENSSL_MD5)
 #define  MD5Init    MD5_Init
 #define  MD5Update  MD5_Update
 #define  MD5Final   MD5_Final
 #endif
 
 
+#if 0
 
 int ngx_http_cache_get_file(ngx_http_request_t *r, ngx_http_cache_ctx_t *ctx)
 {
@@ -237,3 +238,5 @@
 
     return NGX_OK;
 }
+
+#endif
diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c
index bfe5efb..a4e7d80 100644
--- a/src/http/ngx_http_parse.c
+++ b/src/http/ngx_http_parse.c
@@ -686,7 +686,7 @@
 
     ch = *p++;
 
-    while (p < r->uri_start + r->uri.len + 1 && r->args_start == NULL) {
+    while (p < r->uri_end && r->args_start == NULL) {
 
         /*
          * we use "ch = *p++" inside the cycle but this operation is safe
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index a2cf1a0..b6013fc 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -532,6 +532,7 @@
                 r->uri.len = r->uri_end - r->uri_start;
             }
 
+
             if (r->complex_uri || r->quoted_uri) {
 
                 if (!(r->uri.data = ngx_palloc(r->pool, r->uri.len + 1))) {
@@ -557,6 +558,7 @@
                 r->uri.data = r->uri_start;
             }
 
+
             r->unparsed_uri.len = r->uri_end - r->uri_start;
             r->unparsed_uri.data = r->uri_start;
 
@@ -1751,7 +1753,7 @@
 
     ctx = (ngx_http_log_ctx_t *) rev->log->data;
 
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
 
     if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
         if (rev->pending_eof) {
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
index 31b1187..141daa1 100644
--- a/src/http/ngx_http_request.h
+++ b/src/http/ngx_http_request.h
@@ -220,7 +220,7 @@
 
         struct {
             ngx_http_cache_hash_t   *hash;
-            ngx_http_cache_t        *cache;
+            ngx_http_cache_entry_t  *cache;
         } cache;
     } data;
 
@@ -254,7 +254,7 @@
     void                    **srv_conf;
     void                    **loc_conf;
 
-    ngx_http_cache_t         *cache;
+    ngx_http_cache_entry_t   *cache;
 
     ngx_file_t                file;
 
diff --git a/src/os/unix/ngx_aio_read.c b/src/os/unix/ngx_aio_read.c
index d011054..2a66eb8 100644
--- a/src/os/unix/ngx_aio_read.c
+++ b/src/os/unix/ngx_aio_read.c
@@ -9,7 +9,7 @@
 #include <ngx_event.h>
 #include <ngx_aio.h>
 
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
 #include <ngx_kqueue_module.h>
 #endif
 
@@ -46,7 +46,7 @@
         rev->aiocb.aio_buf = buf;
         rev->aiocb.aio_nbytes = size;
 
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
         rev->aiocb.aio_sigevent.sigev_notify_kqueue = ngx_kqueue;
         rev->aiocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
         rev->aiocb.aio_sigevent.sigev_value.sigval_ptr = rev;
diff --git a/src/os/unix/ngx_aio_write.c b/src/os/unix/ngx_aio_write.c
index f102ba3..1d8c1aa 100644
--- a/src/os/unix/ngx_aio_write.c
+++ b/src/os/unix/ngx_aio_write.c
@@ -9,7 +9,7 @@
 #include <ngx_event.h>
 #include <ngx_aio.h>
 
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
 #include <ngx_kqueue_module.h>
 #endif
 
@@ -43,7 +43,7 @@
         wev->aiocb.aio_buf = buf;
         wev->aiocb.aio_nbytes = size;
 
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
         wev->aiocb.aio_sigevent.sigev_notify_kqueue = ngx_kqueue;
         wev->aiocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
         wev->aiocb.aio_sigevent.sigev_value.sigval_ptr = wev;
diff --git a/src/os/unix/ngx_alloc.c b/src/os/unix/ngx_alloc.c
index 7ec4f87..258a10f 100644
--- a/src/os/unix/ngx_alloc.c
+++ b/src/os/unix/ngx_alloc.c
@@ -40,7 +40,7 @@
 }
 
 
-#if (HAVE_POSIX_MEMALIGN)
+#if (NGX_HAVE_POSIX_MEMALIGN)
 
 void *ngx_memalign(size_t alignment, size_t size, ngx_log_t *log)
 {
@@ -58,7 +58,7 @@
     return p;
 }
 
-#elif (HAVE_MEMALIGN)
+#elif (NGX_HAVE_MEMALIGN)
 
 void *ngx_memalign(size_t alignment, size_t size, ngx_log_t *log)
 {
diff --git a/src/os/unix/ngx_alloc.h b/src/os/unix/ngx_alloc.h
index 0084c2c..66562a1 100644
--- a/src/os/unix/ngx_alloc.h
+++ b/src/os/unix/ngx_alloc.h
@@ -25,7 +25,7 @@
  * allocations bigger than page size at the page boundary.
  */
 
-#if (HAVE_POSIX_MEMALIGN || HAVE_MEMALIGN)
+#if (NGX_HAVE_POSIX_MEMALIGN || NGX_HAVE_MEMALIGN)
 
 void *ngx_memalign(size_t alignment, size_t size, ngx_log_t *log);
 
diff --git a/src/os/unix/ngx_channel.c b/src/os/unix/ngx_channel.c
index 0bfbd0d..b1b36c5 100644
--- a/src/os/unix/ngx_channel.c
+++ b/src/os/unix/ngx_channel.c
@@ -17,7 +17,7 @@
     struct iovec        iov[1];
     struct msghdr       msg;
 
-#if (HAVE_MSGHDR_MSG_CONTROL)
+#if (NGX_HAVE_MSGHDR_MSG_CONTROL)
 
     union {
         struct cmsghdr  cm;
@@ -83,7 +83,7 @@
     struct iovec        iov[1];
     struct msghdr       msg;
 
-#if (HAVE_MSGHDR_MSG_CONTROL)
+#if (NGX_HAVE_MSGHDR_MSG_CONTROL)
     union {
         struct cmsghdr  cm;
         char            space[CMSG_SPACE(sizeof(int))];
@@ -100,7 +100,7 @@
     msg.msg_iov = iov;
     msg.msg_iovlen = 1;
 
-#if (HAVE_MSGHDR_MSG_CONTROL)
+#if (NGX_HAVE_MSGHDR_MSG_CONTROL)
     msg.msg_control = (caddr_t) &cmsg;
     msg.msg_controllen = sizeof(cmsg);
 #else
@@ -131,7 +131,7 @@
         return NGX_ERROR;
     }
 
-#if (HAVE_MSGHDR_MSG_CONTROL)
+#if (NGX_HAVE_MSGHDR_MSG_CONTROL)
 
     if (ch->command == NGX_CMD_OPEN_CHANNEL) {
 
diff --git a/src/os/unix/ngx_errno.c b/src/os/unix/ngx_errno.c
index ced0eaf..607b361 100644
--- a/src/os/unix/ngx_errno.c
+++ b/src/os/unix/ngx_errno.c
@@ -8,7 +8,7 @@
 #include <ngx_core.h>
 
 
-#if (NGX_STRERROR_R)
+#if (NGX_HAVE_STRERROR_R)
 
 u_char *ngx_strerror_r(int err, u_char *errstr, size_t size)
 {
@@ -28,7 +28,7 @@
     return errstr;
 }
 
-#elif (NGX_GNU_STRERROR_R)
+#elif (NGX_HAVE_GNU_STRERROR_R)
 
 /* Linux strerror_r() */
 
diff --git a/src/os/unix/ngx_errno.h b/src/os/unix/ngx_errno.h
index e87ec5f..c1c5801 100644
--- a/src/os/unix/ngx_errno.h
+++ b/src/os/unix/ngx_errno.h
@@ -46,7 +46,7 @@
 #define ngx_set_socket_errno(err)  errno = err
 
 
-#if (HAVE_STRERROR_R || HAVE_GNU_STRERROR_R)
+#if (NGX_HAVE_STRERROR_R || NGX_HAVE_GNU_STRERROR_R)
 
 u_char *ngx_strerror_r(int err, u_char *errstr, size_t size);
 
diff --git a/src/os/unix/ngx_files.c b/src/os/unix/ngx_files.c
index 52aa9b6..e67b2ca 100644
--- a/src/os/unix/ngx_files.c
+++ b/src/os/unix/ngx_files.c
@@ -15,7 +15,7 @@
     ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0,
                    "read: %d, %p, %uz, %O", file->fd, buf, size, offset);
 
-#if (NGX_PREAD)
+#if (NGX_HAVE_PREAD)
 
     n = pread(file->fd, buf, size, offset);
 
@@ -60,7 +60,7 @@
     ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0,
                    "write: %d, %p, %uz, %O", file->fd, buf, size, offset);
 
-#if (NGX_PWRITE)
+#if (NGX_HAVE_PWRITE)
 
     n = pwrite(file->fd, buf, size, offset);
 
diff --git a/src/os/unix/ngx_freebsd_config.h b/src/os/unix/ngx_freebsd_config.h
index 7f3b286..35bf1f5 100644
--- a/src/os/unix/ngx_freebsd_config.h
+++ b/src/os/unix/ngx_freebsd_config.h
@@ -60,23 +60,23 @@
 #include <ngx_auto_config.h>
 
 
-#if (HAVE_POLL)
+#if (NGX_HAVE_POLL)
 #include <poll.h>
 #endif
 
 
-#if (HAVE_AIO)
+#if (NGX_HAVE_AIO)
 #include <aio.h>
 #endif
 
 
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
 #include <sys/event.h>
 #endif
 
 
-#if defined SO_ACCEPTFILTER && !defined HAVE_DEFERRED_ACCEPT
-#define HAVE_DEFERRED_ACCEPT  1
+#if defined SO_ACCEPTFILTER && !defined NGX_HAVE_DEFERRED_ACCEPT
+#define NGX_HAVE_DEFERRED_ACCEPT  1
 #endif
 
 
@@ -91,8 +91,8 @@
 #endif
 
 
-#ifndef HAVE_INHERITED_NONBLOCK
-#define HAVE_INHERITED_NONBLOCK  1
+#ifndef NGX_HAVE_INHERITED_NONBLOCK
+#define NGX_HAVE_INHERITED_NONBLOCK  1
 #endif
 
 
diff --git a/src/os/unix/ngx_freebsd_init.c b/src/os/unix/ngx_freebsd_init.c
index faf8e9f..b76dc0c 100644
--- a/src/os/unix/ngx_freebsd_init.c
+++ b/src/os/unix/ngx_freebsd_init.c
@@ -30,7 +30,7 @@
     ngx_unix_recv,
     ngx_readv_chain,
     ngx_unix_send,
-#if (HAVE_SENDFILE)
+#if (NGX_HAVE_SENDFILE)
     ngx_freebsd_sendfile_chain,
     NGX_IO_SENDFILE
 #else
@@ -128,7 +128,7 @@
     version = ngx_freebsd_kern_osreldate;
 
 
-#if (HAVE_SENDFILE)
+#if (NGX_HAVE_SENDFILE)
 
     /*
      * The determination of the sendfile() "nbytes bug" is complex enough.
@@ -161,7 +161,7 @@
 
 #endif
 
-#endif /* HAVE_SENDFILE */
+#endif /* NGX_HAVE_SENDFILE */
 
 
     if ((version < 500000 && version >= 440003) || version >= 500017) {
diff --git a/src/os/unix/ngx_freebsd_rfork_thread.c b/src/os/unix/ngx_freebsd_rfork_thread.c
index b64325b..5dfd468 100644
--- a/src/os/unix/ngx_freebsd_rfork_thread.c
+++ b/src/os/unix/ngx_freebsd_rfork_thread.c
@@ -381,7 +381,7 @@
                 return NGX_AGAIN;
             }
 
-            if (ngx_freebsd_hw_ncpu > 1 && tries++ < 1000) {
+            if (ngx_ncpu > 1 && tries++ < 1000) {
 
                 /* the spinlock is used only on the SMP system */
 
@@ -581,7 +581,7 @@
     }
 
     cv->signo = NGX_CV_SIGNAL;
-    cv->tid = 0;
+    cv->tid = -1;
     cv->log = log;
     cv->kq = -1;
 
@@ -640,6 +640,8 @@
             ngx_log_error(NGX_LOG_ALERT, cv->log, ngx_errno, "kevent() failed");
             return NGX_ERROR;
         }
+
+        cv->tid = ngx_thread_self();
     }
 
     if (ngx_mutex_unlock(m) == NGX_ERROR) {
@@ -714,6 +716,10 @@
                    "cv %p to signal %P %d",
                    cv, cv->tid, cv->signo);
 
+    if (cv->tid == -1) {
+        return NGX_OK;
+    }
+
     if (kill(cv->tid, cv->signo) == -1) {
 
         err = ngx_errno;
diff --git a/src/os/unix/ngx_freebsd_sendfile_chain.c b/src/os/unix/ngx_freebsd_sendfile_chain.c
index 192a1a1..f86e1c0 100644
--- a/src/os/unix/ngx_freebsd_sendfile_chain.c
+++ b/src/os/unix/ngx_freebsd_sendfile_chain.c
@@ -55,7 +55,7 @@
         return in;
     }
 
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
 
     if ((ngx_event_flags & NGX_USE_KQUEUE_EVENT) && wev->pending_eof) {
         ngx_log_error(NGX_LOG_INFO, c->log, wev->kq_errno,
diff --git a/src/os/unix/ngx_linux_config.h b/src/os/unix/ngx_linux_config.h
index 57ee505..620b59d 100644
--- a/src/os/unix/ngx_linux_config.h
+++ b/src/os/unix/ngx_linux_config.h
@@ -56,35 +56,37 @@
 #include <sys/prctl.h>
 #endif
 
+
 #if (NGX_HAVE_SENDFILE64)
 #include <sys/sendfile.h>
 #else
 extern ssize_t sendfile(int s, int fd, int32_t *offset, size_t size);
+#define NGX_SENDFILE_LIMIT  (NGX_MAX_UINT32_VALUE + 1)
 #endif
 
 
-#if (HAVE_POLL)
+#if (NGX_HAVE_POLL)
 #include <poll.h>
 #endif
 
 
-#if (HAVE_EPOLL)
+#if (NGX_HAVE_EPOLL)
 #include <sys/epoll.h>
-#endif /* HAVE_EPOLL */
-
-
-#if defined TCP_DEFER_ACCEPT && !defined HAVE_DEFERRED_ACCEPT
-#define HAVE_DEFERRED_ACCEPT  1
 #endif
 
 
-#ifndef HAVE_INHERITED_NONBLOCK
-#define HAVE_INHERITED_NONBLOCK  0
+#if defined TCP_DEFER_ACCEPT && !defined NGX_HAVE_DEFERRED_ACCEPT
+#define NGX_HAVE_DEFERRED_ACCEPT  1
 #endif
 
 
-#ifndef HAVE_SELECT_CHANGE_TIMEOUT
-#define HAVE_SELECT_CHANGE_TIMEOUT   1
+#ifndef NGX_HAVE_INHERITED_NONBLOCK
+#define NGX_HAVE_INHERITED_NONBLOCK  0
+#endif
+
+
+#ifndef NGX_HAVE_SELECT_CHANGE_TIMEOUT
+#define NGX_HAVE_SELECT_CHANGE_TIMEOUT   1
 #endif
 
 #ifndef NGX_SETPROCTITLE_USES_ENV
diff --git a/src/os/unix/ngx_linux_init.c b/src/os/unix/ngx_linux_init.c
index 397d342..9c1c847 100644
--- a/src/os/unix/ngx_linux_init.c
+++ b/src/os/unix/ngx_linux_init.c
@@ -18,7 +18,7 @@
     ngx_unix_recv,
     ngx_readv_chain,
     ngx_unix_send,
-#if (HAVE_SENDFILE)
+#if (NGX_HAVE_SENDFILE)
     ngx_linux_sendfile_chain,
     NGX_IO_SENDFILE
 #else
diff --git a/src/os/unix/ngx_linux_sendfile_chain.c b/src/os/unix/ngx_linux_sendfile_chain.c
index ad40f55..bcf9d4c 100644
--- a/src/os/unix/ngx_linux_sendfile_chain.c
+++ b/src/os/unix/ngx_linux_sendfile_chain.c
@@ -13,7 +13,7 @@
  * On Linux up to 2.4.21 sendfile() (syscall #187) works with 32-bit
  * offsets only and the including <sys/sendfile.h> breaks the compiling
  * if off_t is 64 bit wide.  So we use own sendfile() definition where offset
- * parameter is int32_t and use sendfile() with the file parts below 2G.
+ * parameter is int32_t and use sendfile() for the file parts below 2G only.
  *
  * Linux 2.4.21 has a new sendfile64() syscall #239.
  */
diff --git a/src/os/unix/ngx_os.h b/src/os/unix/ngx_os.h
index dc9f7a8..ee91df3 100644
--- a/src/os/unix/ngx_os.h
+++ b/src/os/unix/ngx_os.h
@@ -15,18 +15,6 @@
 #define NGX_IO_SENDFILE    1
 #define NGX_IO_ZEROCOPY    2
 
-#if (HAVE_SENDFILE)
-#define NGX_HAVE_SENDFILE  NGX_IO_SENDFILE
-#else
-#define NGX_HAVE_SENDFILE  0
-#endif
-
-#if (HAVE_ZEROCOPY)
-#define NGX_HAVE_ZEROCOPY  NGX_IO_ZEROCOPY
-#else
-#define NGX_HAVE_ZEROCOPY  0
-#endif
-
 
 typedef ssize_t (*ngx_recv_pt)(ngx_connection_t *c, u_char *buf, size_t size);
 typedef ssize_t (*ngx_recv_chain_pt)(ngx_connection_t *c, ngx_chain_t *in);
diff --git a/src/os/unix/ngx_posix_config.h b/src/os/unix/ngx_posix_config.h
index b187236..f9c91a4 100644
--- a/src/os/unix/ngx_posix_config.h
+++ b/src/os/unix/ngx_posix_config.h
@@ -70,17 +70,17 @@
 #include <ngx_auto_config.h>
 
 
-#if (HAVE_POLL)
+#if (NGX_HAVE_POLL)
 #include <poll.h>
 #endif
 
 
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
 #include <sys/event.h>
 #endif
 
 
-#if (HAVE_DEVPOLL)
+#if (NGX_HAVE_DEVPOLL)
 #include <sys/ioctl.h>
 #include <sys/devpoll.h>
 #endif
diff --git a/src/os/unix/ngx_posix_init.c b/src/os/unix/ngx_posix_init.c
index 19d65a4..56be0ce 100644
--- a/src/os/unix/ngx_posix_init.c
+++ b/src/os/unix/ngx_posix_init.c
@@ -121,7 +121,7 @@
 
     ngx_max_sockets = rlmt.rlim_cur;
 
-#if (HAVE_INHERITED_NONBLOCK)
+#if (NGX_HAVE_INHERITED_NONBLOCK)
     ngx_inherited_nonblocking = 1;
 #else
     ngx_inherited_nonblocking = 0;
diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c
index 37b2ef1..3d1c51b 100644
--- a/src/os/unix/ngx_process_cycle.c
+++ b/src/os/unix/ngx_process_cycle.c
@@ -607,6 +607,10 @@
 
 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
 {
+    ngx_int_t          n;
+    ngx_err_t          err;
+    ngx_core_conf_t   *ccf;
+
     ngx_worker_process_init(cycle);
 
     ngx_setproctitle("worker process");
@@ -618,6 +622,8 @@
         exit(2);
     }
 
+    ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
+
     if (ngx_threads_n) {
         if (ngx_init_threads(ngx_threads_n,
                                    ccf->thread_stack_size, cycle) == NGX_ERROR)
@@ -914,10 +920,9 @@
 
         for (i = 0; i < ngx_threads_n; i++) {
             if (ngx_threads[i].state < NGX_THREAD_EXIT) {
-                ngx_cond_signal(ngx_threads[i].cv);
-
-                if (ngx_threads[i].cv->tid == (ngx_tid_t) -1) {
+                if (ngx_cond_signal(ngx_threads[i].cv) == NGX_ERROR) {
                     ngx_threads[i].state = NGX_THREAD_DONE;
+
                 } else {
                     live = 1;
                 }
@@ -955,8 +960,6 @@
     ngx_core_tls_t   *tls;
     ngx_cycle_t      *cycle;
 
-    thr->cv->tid = ngx_thread_self();
-
     cycle = (ngx_cycle_t *) ngx_cycle;
 
     sigemptyset(&set);
diff --git a/src/os/unix/ngx_readv_chain.c b/src/os/unix/ngx_readv_chain.c
index 2db998a..7c57b7a 100644
--- a/src/os/unix/ngx_readv_chain.c
+++ b/src/os/unix/ngx_readv_chain.c
@@ -9,7 +9,7 @@
 #include <ngx_event.h>
 
 
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
 
 ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
 {
@@ -136,7 +136,7 @@
     return n;
 }
 
-#else /* ! NAVE_KQUEUE */
+#else /* ! NGX_HAVE_KQUEUE */
 
 ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
 {
@@ -216,4 +216,4 @@
     return n;
 }
 
-#endif /* NAVE_KQUEUE */
+#endif /* NGX_HAVE_KQUEUE */
diff --git a/src/os/unix/ngx_recv.c b/src/os/unix/ngx_recv.c
index d58ca9e..369be66 100644
--- a/src/os/unix/ngx_recv.c
+++ b/src/os/unix/ngx_recv.c
@@ -9,7 +9,7 @@
 #include <ngx_event.h>
 
 
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
 
 ssize_t ngx_unix_recv(ngx_connection_t *c, u_char *buf, size_t size)
 {
@@ -115,7 +115,7 @@
     return n;
 }
 
-#else /* ! NAVE_KQUEUE */
+#else /* ! NGX_HAVE_KQUEUE */
 
 ssize_t ngx_unix_recv(ngx_connection_t *c, u_char *buf, size_t size)
 {
@@ -170,4 +170,4 @@
     return n;
 }
 
-#endif /* NAVE_KQUEUE */
+#endif /* NGX_HAVE_KQUEUE */
diff --git a/src/os/unix/ngx_send.c b/src/os/unix/ngx_send.c
index ff501c3..ecd1362 100644
--- a/src/os/unix/ngx_send.c
+++ b/src/os/unix/ngx_send.c
@@ -17,7 +17,7 @@
 
     wev = c->write;
 
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
 
     if ((ngx_event_flags & NGX_USE_KQUEUE_EVENT) && wev->pending_eof) {
         ngx_log_error(NGX_LOG_INFO, c->log, wev->kq_errno,
diff --git a/src/os/unix/ngx_shared.c b/src/os/unix/ngx_shared.c
index 0edc8cb..80b5f60 100644
--- a/src/os/unix/ngx_shared.c
+++ b/src/os/unix/ngx_shared.c
@@ -8,7 +8,7 @@
 #include <ngx_core.h>
 
 
-#if (HAVE_MAP_ANON)
+#if (NGX_HAVE_MAP_ANON)
 
 void *ngx_create_shared_memory(size_t size, ngx_log_t *log)
 {
@@ -25,7 +25,7 @@
     return p;
 }
 
-#elif (HAVE_MAP_DEVZERO)
+#elif (NGX_HAVE_MAP_DEVZERO)
 
 void *ngx_create_shared_memory(size_t size, ngx_log_t *log)
 {
@@ -56,7 +56,7 @@
     return p;
 }
 
-#elif (HAVE_SYSVSHM)
+#elif (NGX_HAVE_SYSVSHM)
 
 #include <sys/ipc.h>
 #include <sys/shm.h>
diff --git a/src/os/unix/ngx_socket.c b/src/os/unix/ngx_socket.c
index da936b2..523f1f4 100644
--- a/src/os/unix/ngx_socket.c
+++ b/src/os/unix/ngx_socket.c
@@ -20,7 +20,7 @@
  */
 
 
-#if (HAVE_FIONBIO)
+#if (NGX_HAVE_FIONBIO)
 
 int ngx_nonblocking(ngx_socket_t s)
 {
diff --git a/src/os/unix/ngx_socket.h b/src/os/unix/ngx_socket.h
index 4dcf924..b381967 100644
--- a/src/os/unix/ngx_socket.h
+++ b/src/os/unix/ngx_socket.h
@@ -19,7 +19,7 @@
 #define ngx_socket_n        "socket()"
 
 
-#if (HAVE_FIONBIO)
+#if (NGX_HAVE_FIONBIO)
 
 int ngx_nonblocking(ngx_socket_t s);
 int ngx_blocking(ngx_socket_t s);
diff --git a/src/os/unix/ngx_solaris_config.h b/src/os/unix/ngx_solaris_config.h
index 8f18417..452850c 100644
--- a/src/os/unix/ngx_solaris_config.h
+++ b/src/os/unix/ngx_solaris_config.h
@@ -49,35 +49,35 @@
 #include <ngx_auto_config.h>
 
 
-#if (HAVE_POLL)
+#if (NGX_HAVE_POLL)
 #include <poll.h>
 #endif
 
 
-#if (HAVE_SENDFILE)
+#if (NGX_HAVE_SENDFILE)
 #include <sys/sendfile.h>
 #endif
 
 
-#if (HAVE_AIO)
+#if (NGX_HAVE_AIO)
 #include <aio.h>
 #endif
 
 
-#if (HAVE_DEVPOLL)
+#if (NGX_HAVE_DEVPOLL)
 #include <sys/ioctl.h>
 #include <sys/devpoll.h>
 #endif
 
 
-#ifndef HAVE_INHERITED_NONBLOCK
-#define HAVE_INHERITED_NONBLOCK  1
+#ifndef NGX_HAVE_INHERITED_NONBLOCK
+#define NGX_HAVE_INHERITED_NONBLOCK  1
 #endif
 
 
-#ifndef HAVE_SO_SNDLOWAT
+#ifndef NGX_HAVE_SO_SNDLOWAT
 /* setsockopt(SO_SNDLOWAT) returns error "Option not supported by protocol" */
-#define HAVE_SO_SNDLOWAT         0
+#define NGX_HAVE_SO_SNDLOWAT         0
 #endif
 
 
diff --git a/src/os/unix/ngx_solaris_init.c b/src/os/unix/ngx_solaris_init.c
index c671197..03072ed 100644
--- a/src/os/unix/ngx_solaris_init.c
+++ b/src/os/unix/ngx_solaris_init.c
@@ -17,7 +17,7 @@
     ngx_unix_recv,
     ngx_readv_chain,
     ngx_unix_send,
-#if (HAVE_SENDFILE)
+#if (NGX_HAVE_SENDFILE)
     ngx_solaris_sendfilev_chain,
     NGX_IO_SENDFILE
 #else
diff --git a/src/os/unix/ngx_thread.h b/src/os/unix/ngx_thread.h
index ac7cfad..e630b35 100644
--- a/src/os/unix/ngx_thread.h
+++ b/src/os/unix/ngx_thread.h
@@ -53,7 +53,6 @@
 
 typedef struct {
     pthread_cond_t    cond;
-    ngx_tid_t         tid;
     ngx_log_t        *log;
 } ngx_cond_t;
 
diff --git a/src/os/unix/ngx_time.c b/src/os/unix/ngx_time.c
index c438950..20ec464 100644
--- a/src/os/unix/ngx_time.c
+++ b/src/os/unix/ngx_time.c
@@ -10,7 +10,7 @@
 
 void ngx_localtime(ngx_tm_t *tm)
 {
-#if (HAVE_LOCALTIME_R)
+#if (NGX_HAVE_LOCALTIME_R)
     time_t     now;
 
     now = ngx_time();
diff --git a/src/os/unix/ngx_time.h b/src/os/unix/ngx_time.h
index a6acf59..f257325 100644
--- a/src/os/unix/ngx_time.h
+++ b/src/os/unix/ngx_time.h
@@ -36,7 +36,7 @@
 #define ngx_tm_wday_t  int
 
 
-#if (HAVE_GMTOFF)
+#if (NGX_HAVE_GMTOFF)
 #define ngx_tm_gmtoff  tm_gmtoff
 #define ngx_tm_zone    tm_zone
 #endif
diff --git a/src/os/unix/ngx_writev_chain.c b/src/os/unix/ngx_writev_chain.c
index e389322..2af6469 100644
--- a/src/os/unix/ngx_writev_chain.c
+++ b/src/os/unix/ngx_writev_chain.c
@@ -30,7 +30,7 @@
         return in;
     }
 
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
 
     if ((ngx_event_flags & NGX_USE_KQUEUE_EVENT) && wev->pending_eof) {
         ngx_log_error(NGX_LOG_INFO, c->log, wev->kq_errno,
diff --git a/src/os/win32/ngx_os.h b/src/os/win32/ngx_os.h
index c27f8a8..6d720fa 100644
--- a/src/os/win32/ngx_os.h
+++ b/src/os/win32/ngx_os.h
@@ -15,18 +15,6 @@
 #define NGX_IO_SENDFILE    1
 #define NGX_IO_ZEROCOPY    2
 
-#if (HAVE_SENDFILE)
-#define NGX_HAVE_SENDFILE  NGX_IO_SENDFILE
-#else
-#define NGX_HAVE_SENDFILE  0
-#endif
-
-#if (HAVE_ZEROCOPY)
-#define NGX_HAVE_ZEROCOPY  NGX_IO_ZEROCOPY
-#else
-#define NGX_HAVE_ZEROCOPY  0
-#endif
-
 
 typedef ssize_t (*ngx_recv_pt)(ngx_connection_t *c, u_char *buf, size_t size);
 typedef ssize_t (*ngx_recv_chain_pt)(ngx_connection_t *c, ngx_chain_t *in);
diff --git a/src/os/win32/ngx_time.h b/src/os/win32/ngx_time.h
index 665976d..4cb9841 100644
--- a/src/os/win32/ngx_time.h
+++ b/src/os/win32/ngx_time.h
@@ -39,7 +39,7 @@
 
 #define ngx_msleep       Sleep
 
-#define HAVE_GETTIMEZONE  1
+#define NGX_HAVE_GETTIMEZONE  1
 
 ngx_int_t ngx_gettimezone(void);
 void ngx_gettimeofday(struct timeval *tp);
diff --git a/src/os/win32/ngx_win32_config.h b/src/os/win32/ngx_win32_config.h
index e7d3086..c7703c2 100644
--- a/src/os/win32/ngx_win32_config.h
+++ b/src/os/win32/ngx_win32_config.h
@@ -115,37 +115,31 @@
 
 
 #define TIME_T_LEN        sizeof("-2147483648") - 1
+#define OFF_T_MAX_VALUE   9223372036854775807
+#define NGX_HAVE_LITTLE_ENDIAN  1
+
+#define NGX_THREADS       1
 
 
 #define NGX_WIN_NT        200000
 
 
-#define NGX_THREADS       1
-
-
-#ifndef HAVE_INHERITED_NONBLOCK
-#define HAVE_INHERITED_NONBLOCK  1
+#ifndef NGX_HAVE_INHERITED_NONBLOCK
+#define NGX_HAVE_INHERITED_NONBLOCK  1
 #endif
 
-#ifndef HAVE_WIN32_TRANSMITPACKETS
-#define HAVE_WIN32_TRANSMITPACKETS  1
-#define HAVE_WIN32_TRANSMITFILE     0
+#ifndef NGX_HAVE_WIN32_TRANSMITPACKETS
+#define NGX_HAVE_WIN32_TRANSMITPACKETS  1
+#define NGX_HAVE_WIN32_TRANSMITFILE     0
 #endif
 
-#ifndef HAVE_WIN32_TRANSMITFILE
-#define HAVE_WIN32_TRANSMITFILE  1
+#ifndef NGX_HAVE_WIN32_TRANSMITFILE
+#define NGX_HAVE_WIN32_TRANSMITFILE  1
 #endif
 
-#if (HAVE_WIN32_TRANSMITPACKETS) || (HAVE_WIN32_TRANSMITFILE)
-#define HAVE_SENDFILE  1
+#if (NGX_HAVE_WIN32_TRANSMITPACKETS) || (NGX_HAVE_WIN32_TRANSMITFILE)
+#define NGX_HAVE_SENDFILE  1
 #endif
 
 
-#define OFF_T_MAX_VALUE  9223372036854775807
-
-
-/* STUB */
-#define HAVE_LITTLE_ENDIAN  1
-
-
 #endif /* _NGX_WIN32_CONFIG_H_INCLUDED_ */