diff --git a/Makefile.in b/Makefile.in index eec8c069f..d5c98cefc 100644 --- a/Makefile.in +++ b/Makefile.in @@ -65,7 +65,7 @@ ifeq "$(QUIET)" "yes" endif BUILD=build/ -WINDRES=windres +WINDRES=@WINDRES@ LINT=splint LINTFLAGS=+quiet -weak -warnposix -unrecog -Din_addr_t=uint32_t -Du_int=unsigned -Du_char=uint8_t -preproc -Drlimit=rlimit64 -D__gnuc_va_list=va_list -Dglob64=glob -Dglobfree64=globfree # compat with openssl linux edition. diff --git a/acx_nlnetlabs.m4 b/acx_nlnetlabs.m4 index 3baa9d3bf..7055e0f80 100644 --- a/acx_nlnetlabs.m4 +++ b/acx_nlnetlabs.m4 @@ -2,10 +2,14 @@ # Copyright 2009, Wouter Wijngaards, NLnet Labs. # BSD licensed. # -# Version 2 -# 2009-07-03 +# Version 4 # Changelog -# - fixup LDFLAGS for empty ssl dir. +# 2009-07-14 U_CHAR detection improved for windows crosscompile. +# added ACX_FUNC_MALLOC +# fixup some #if to #ifdef +# NONBLOCKING test for mingw crosscompile. +# 2009-07-13 added ACX_WITH_SSL_OPTIONAL +# 2009-07-03 fixup LDFLAGS for empty ssl dir. # # Automates some of the checking constructs. Aims at portability for POSIX. # Documentation for functions is below. @@ -30,6 +34,8 @@ # ACX_TYPE_IN_PORT_T - in_port_t type. # ACX_ARG_RPATH - add --disable-rpath option. # ACX_WITH_SSL - add --with-ssl option, link -lcrypto. +# ACX_WITH_SSL_OPTIONAL - add --with-ssl option, link -lcrypto, + where --without-ssl is also accepted # ACX_LIB_SSL - setup to link -lssl. # ACX_SYS_LARGEFILE - improved sys_largefile, fseeko, >2G files. # ACX_CHECK_GETADDRINFO_WITH_INCLUDES - find getaddrinfo, portably. @@ -37,6 +43,7 @@ # ACX_CHECK_NONBLOCKING_BROKEN - see if nonblocking sockets really work. # ACX_MKDIR_ONE_ARG - determine mkdir(2) number of arguments. # ACX_FUNC_IOCTLSOCKET - find ioctlsocket, portably. +# ACX_FUNC_MALLOC - check malloc, define replacement . # AHX_CONFIG_FORMAT_ATTRIBUTE - config.h text for format. # AHX_CONFIG_UNUSED_ATTRIBUTE - config.h text for unused. # AHX_CONFIG_FSEEKO - define fseeko, ftello fallback. @@ -480,14 +487,20 @@ AC_PROG_LIBTOOL dnl Detect if u_char type is defined, otherwise define it. AC_DEFUN([ACX_TYPE_U_CHAR], - [AC_CHECK_TYPE(u_char, unsigned char)]) +[AC_CHECK_TYPE([u_char], , + [AC_DEFINE([u_char], [unsigned char], [Define to 'unsigned char if not defined])], [ +AC_INCLUDES_DEFAULT +#ifdef HAVE_WINSOCK2_H +# include +#endif +]) ]) dnl Detect if rlim_t type is defined, otherwise define it. AC_DEFUN([ACX_TYPE_RLIM_T], [AC_CHECK_TYPE(rlim_t, , [AC_DEFINE([rlim_t], [unsigned long], [Define to 'int' if not defined])], [ AC_INCLUDES_DEFAULT -#if HAVE_SYS_RESOURCE_H +#ifdef HAVE_SYS_RESOURCE_H # include #endif ]) ]) @@ -498,31 +511,34 @@ AC_DEFUN([ACX_TYPE_SOCKLEN_T], AC_CHECK_TYPE(socklen_t, , [AC_DEFINE([socklen_t], [int], [Define to 'int' if not defined])], [ AC_INCLUDES_DEFAULT -#if HAVE_SYS_SOCKET_H +#ifdef HAVE_SYS_SOCKET_H # include #endif +#ifdef HAVE_WS2TCPIP_H +# include +#endif ]) ]) -dnl Detect if socklen_t type is defined, otherwise define it. +dnl Detect if in_addr_t type is defined, otherwise define it. AC_DEFUN([ACX_TYPE_IN_ADDR_T], [ AC_CHECK_TYPE(in_addr_t, [], [AC_DEFINE([in_addr_t], [uint32_t], [in_addr_t])], [ AC_INCLUDES_DEFAULT -#if HAVE_SYS_TYPES_H +#ifdef HAVE_SYS_TYPES_H # include #endif -#if HAVE_NETINET_IN_H +#ifdef HAVE_NETINET_IN_H # include #endif ]) ]) -dnl Detect if socklen_t type is defined, otherwise define it. +dnl Detect if in_port_t type is defined, otherwise define it. AC_DEFUN([ACX_TYPE_IN_PORT_T], [ AC_CHECK_TYPE(in_port_t, [], [AC_DEFINE([in_port_t], [uint16_t], [in_port_t])], [ AC_INCLUDES_DEFAULT -#if HAVE_SYS_TYPES_H +#ifdef HAVE_SYS_TYPES_H # include #endif -#if HAVE_NETINET_IN_H +#ifdef HAVE_NETINET_IN_H # include #endif ]) ]) @@ -555,7 +571,89 @@ AC_DEFUN([ACX_RUNTIME_PATH_ADD], [ fi ]) -dnl Check for SSL. +dnl Common code for both ACX_WITH_SSL and ACX_WITH_SSL_OPTIONAL +dnl Takes one argument; the withval checked in those 2 functions +dnl sets up the environment for the given openssl path +AC_DEFUN([ACX_SSL_CHECKS], [ + withval=$1 + if test x_$withval != x_no; then + AC_MSG_CHECKING(for SSL) + if test x_$withval = x_ -o x_$withval = x_yes; then + withval="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /opt/local /usr/sfw /usr" + fi + for dir in $withval; do + ssldir="$dir" + if test -f "$dir/include/openssl/ssl.h"; then + found_ssl="yes" + AC_DEFINE_UNQUOTED([HAVE_SSL], [], [Define if you have the SSL libraries installed.]) + dnl assume /usr/include is already in the include-path. + if test "$ssldir" != "/usr"; then + CPPFLAGS="$CPPFLAGS -I$ssldir/include" + fi + break; + fi + done + if test x_$found_ssl != x_yes; then + AC_MSG_ERROR(Cannot find the SSL libraries in $withval) + else + AC_MSG_RESULT(found in $ssldir) + HAVE_SSL=yes + dnl assume /usr is already in the lib and dynlib paths. + if test "$ssldir" != "/usr" -a "$ssldir" != ""; then + LDFLAGS="$LDFLAGS -L$ssldir/lib" + ACX_RUNTIME_PATH_ADD([$ssldir/lib]) + fi + + AC_MSG_CHECKING([for HMAC_CTX_init in -lcrypto]) + LIBS="$LIBS -lcrypto" + AC_TRY_LINK(, [ + int HMAC_CTX_init(void); + (void)HMAC_CTX_init(); + ], [ + AC_MSG_RESULT(yes) + AC_DEFINE([HAVE_HMAC_CTX_INIT], 1, + [If you have HMAC_CTX_init]) + ], [ + AC_MSG_RESULT(no) + # check if -lwsock32 or -lgdi32 are needed. + BAKLIBS="$LIBS" + LIBS="$LIBS -lgdi32" + AC_MSG_CHECKING([if -lcrypto needs -lgdi32]) + AC_TRY_LINK([], [ + int HMAC_CTX_init(void); + (void)HMAC_CTX_init(); + ],[ + AC_DEFINE([HAVE_HMAC_CTX_INIT], 1, + [If you have HMAC_CTX_init]) + AC_MSG_RESULT(yes) + ],[ + AC_MSG_RESULT(no) + LIBS="$BAKLIBS" + LIBS="$LIBS -ldl" + AC_MSG_CHECKING([if -lcrypto needs -ldl]) + AC_TRY_LINK([], [ + int HMAC_CTX_init(void); + (void)HMAC_CTX_init(); + ],[ + AC_DEFINE([HAVE_HMAC_CTX_INIT], 1, + [If you have HMAC_CTX_init]) + AC_MSG_RESULT(yes) + ],[ + AC_MSG_RESULT(no) + AC_MSG_ERROR([OpenSSL found in $ssldir, but version 0.9.7 or higher is required]) + ]) + ]) + ]) + fi + AC_SUBST(HAVE_SSL) + AC_SUBST(RUNTIME_PATH) + fi +AC_CHECK_HEADERS([openssl/ssl.h],,, [AC_INCLUDES_DEFAULT]) +AC_CHECK_HEADERS([openssl/err.h],,, [AC_INCLUDES_DEFAULT]) +AC_CHECK_HEADERS([openssl/rand.h],,, [AC_INCLUDES_DEFAULT]) +])dnl End of ACX_SSL_CHECKS + +dnl Check for SSL, where SSL is mandatory dnl Adds --with-ssl option, searches for openssl and defines HAVE_SSL if found dnl Setup of CPPFLAGS, CFLAGS. Adds -lcrypto to LIBS. dnl Checks main header files of SSL. @@ -571,83 +669,25 @@ AC_ARG_WITH(ssl, AC_HELP_STRING([--with-ssl=pathname], if test x_$withval = x_no; then AC_MSG_ERROR([Need SSL library to do digital signature cryptography]) fi - if test x_$withval != x_no; then - AC_MSG_CHECKING(for SSL) - if test x_$withval = x_ -o x_$withval = x_yes; then - withval="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /opt/local /usr/sfw /usr" - fi - for dir in $withval; do - ssldir="$dir" - if test -f "$dir/include/openssl/ssl.h"; then - found_ssl="yes" - AC_DEFINE_UNQUOTED([HAVE_SSL], [], [Define if you have the SSL libraries installed.]) - dnl assume /usr/include is already in the include-path. - if test "$ssldir" != "/usr"; then - CPPFLAGS="$CPPFLAGS -I$ssldir/include" - fi - break; - fi - done - if test x_$found_ssl != x_yes; then - AC_MSG_ERROR(Cannot find the SSL libraries in $withval) - else - AC_MSG_RESULT(found in $ssldir) - HAVE_SSL=yes - dnl assume /usr is already in the lib and dynlib paths. - if test "$ssldir" != "/usr" -a "$ssldir" != ""; then - LDFLAGS="$LDFLAGS -L$ssldir/lib" - ACX_RUNTIME_PATH_ADD([$ssldir/lib]) - fi - - AC_MSG_CHECKING([for HMAC_CTX_init in -lcrypto]) - LIBS="$LIBS -lcrypto" - AC_TRY_LINK(, [ - int HMAC_CTX_init(void); - (void)HMAC_CTX_init(); - ], [ - AC_MSG_RESULT(yes) - AC_DEFINE([HAVE_HMAC_CTX_INIT], 1, - [If you have HMAC_CTX_init]) - ], [ - AC_MSG_RESULT(no) - # check if -lwsock32 or -lgdi32 are needed. - BAKLIBS="$LIBS" - LIBS="$LIBS -lgdi32" - AC_MSG_CHECKING([if -lcrypto needs -lgdi32]) - AC_TRY_LINK([], [ - int HMAC_CTX_init(void); - (void)HMAC_CTX_init(); - ],[ - AC_DEFINE([HAVE_HMAC_CTX_INIT], 1, - [If you have HMAC_CTX_init]) - AC_MSG_RESULT(yes) - ],[ - AC_MSG_RESULT(no) - LIBS="$BAKLIBS" - LIBS="$LIBS -ldl" - AC_MSG_CHECKING([if -lcrypto needs -ldl]) - AC_TRY_LINK([], [ - int HMAC_CTX_init(void); - (void)HMAC_CTX_init(); - ],[ - AC_DEFINE([HAVE_HMAC_CTX_INIT], 1, - [If you have HMAC_CTX_init]) - AC_MSG_RESULT(yes) - ],[ - AC_MSG_RESULT(no) - AC_MSG_ERROR([OpenSSL found in $ssldir, but version 0.9.7 or higher is required]) - ]) - ]) - ]) - fi - AC_SUBST(HAVE_SSL) - AC_SUBST(RUNTIME_PATH) - fi -AC_CHECK_HEADERS([openssl/ssl.h],,, [AC_INCLUDES_DEFAULT]) -AC_CHECK_HEADERS([openssl/err.h],,, [AC_INCLUDES_DEFAULT]) -AC_CHECK_HEADERS([openssl/rand.h],,, [AC_INCLUDES_DEFAULT]) + ACX_SSL_CHECKS($withval) ])dnl End of ACX_WITH_SSL +dnl Check for SSL, where ssl is optional (--without-ssl is allowed) +dnl Adds --with-ssl option, searches for openssl and defines HAVE_SSL if found +dnl Setup of CPPFLAGS, CFLAGS. Adds -lcrypto to LIBS. +dnl Checks main header files of SSL. +dnl +AC_DEFUN([ACX_WITH_SSL_OPTIONAL], +[ +AC_ARG_WITH(ssl, AC_HELP_STRING([--with-ssl=pathname], + [enable SSL (will check /usr/local/ssl + /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /opt/local /usr/sfw /usr)]),[ + ],[ + withval="yes" + ]) + ACX_SSL_CHECKS($withval) +])dnl End of ACX_WITH_SSL_OPTIONAL + dnl Setup to use -lssl dnl To use -lcrypto, use the ACX_WITH_SSL setup (before this one). AC_DEFUN([ACX_LIB_SSL], @@ -779,6 +819,10 @@ dnl a nonblocking socket do not work, a new call to select is necessary. AC_DEFUN([ACX_CHECK_NONBLOCKING_BROKEN], [ AC_MSG_CHECKING([if nonblocking sockets work]) +if echo $target | grep mingw32 >/dev/null; then + AC_MSG_RESULT([no (windows)]) + AC_DEFINE([NONBLOCKING_IS_BROKEN], 1, [Define if the network stack does not fully support nonblocking io (causes lower performance).]) +else AC_RUN_IFELSE(AC_LANG_PROGRAM([ #include #include @@ -904,6 +948,7 @@ AC_RUN_IFELSE(AC_LANG_PROGRAM([ ], [ AC_MSG_RESULT([crosscompile(yes)]) ]) +fi ])dnl End of ACX_CHECK_NONBLOCKING_BROKEN dnl Check if mkdir has one or two arguments. @@ -947,6 +992,16 @@ AC_DEFINE(HAVE_IOCTLSOCKET, 1, [if the function 'ioctlsocket' is available]) ],[AC_MSG_RESULT(no)]) ])dnl end of ACX_FUNC_IOCTLSOCKET +dnl detect malloc and provide malloc compat prototype. +dnl $1: unique name for compat code +AC_DEFUN([ACX_FUNC_MALLOC], +[ + AC_FUNC_MALLOC + if test "$ac_cv_func_malloc_0_nonnull" = no; then + AC_DEFINE_UNQUOTED([malloc], [rpl_malloc_$1], [Define if replacement function should be used.]) + fi +]) + dnl Define fallback for fseeko and ftello if needed. AC_DEFUN([AHX_CONFIG_FSEEKO], [ diff --git a/compat/malloc.c b/compat/malloc.c index 42999f6a4..e13ac2b64 100644 --- a/compat/malloc.c +++ b/compat/malloc.c @@ -2,8 +2,6 @@ GNU-compliant. See autoconf documentation. */ #include "config.h" -#undef malloc - #include void *malloc (); @@ -12,7 +10,7 @@ void *malloc (); If N is zero, allocate a 1-byte block. */ void * -rpl_malloc (size_t n) +malloc (size_t n) { if (n == 0) n = 1; diff --git a/config.h.in b/config.h.in index 7e340b25d..e897584a6 100644 --- a/config.h.in +++ b/config.h.in @@ -494,7 +494,7 @@ /* Define to `signed char' if does not define. */ #undef int8_t -/* Define to rpl_malloc if the replacement function should be used. */ +/* Define if replacement function should be used. */ #undef malloc /* Define to `long int' if does not define. */ @@ -515,7 +515,7 @@ /* Define to `int' if does not define. */ #undef ssize_t -/* Define to `unsigned char' if does not define. */ +/* Define to 'unsigned char if not defined */ #undef u_char /* Define to `int' if doesn't define. */ diff --git a/configure b/configure index 9e9f23aa1..b3fa86690 100755 --- a/configure +++ b/configure @@ -789,6 +789,7 @@ enable_option_checking=no ac_subst_vars='LTLIBOBJS subdirs ldnsdir +WINDRES UB_ON_WINDOWS LIBOBJS CHECKLOCK_SRC @@ -3927,7 +3928,11 @@ esac # are we on MinGW? if uname -s 2>&1 | grep MINGW32 >/dev/null; then on_mingw="yes" -else on_mingw="no"; fi +else + if echo $target | grep mingw32 >/dev/null; then on_mingw="yes" + else on_mingw="no"; fi +fi +echo "on mingw" $on_mingw # # Determine configuration file @@ -7163,13 +7168,13 @@ if test "${lt_cv_nm_interface+set}" = set; then else lt_cv_nm_interface="BSD nm" echo "int some_variable = 0;" > conftest.$ac_ext - (eval echo "\"\$as_me:7166: $ac_compile\"" >&5) + (eval echo "\"\$as_me:7171: $ac_compile\"" >&5) (eval "$ac_compile" 2>conftest.err) cat conftest.err >&5 - (eval echo "\"\$as_me:7169: $NM \\\"conftest.$ac_objext\\\"\"" >&5) + (eval echo "\"\$as_me:7174: $NM \\\"conftest.$ac_objext\\\"\"" >&5) (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) cat conftest.err >&5 - (eval echo "\"\$as_me:7172: output\"" >&5) + (eval echo "\"\$as_me:7177: output\"" >&5) cat conftest.out >&5 if $GREP 'External.*some_variable' conftest.out > /dev/null; then lt_cv_nm_interface="MS dumpbin" @@ -8374,7 +8379,7 @@ ia64-*-hpux*) ;; *-*-irix6*) # Find out which ABI we are using. - echo '#line 8377 "configure"' > conftest.$ac_ext + echo '#line 8382 "configure"' > conftest.$ac_ext if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 (eval $ac_compile) 2>&5 ac_status=$? @@ -9741,11 +9746,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:9744: $lt_compile\"" >&5) + (eval echo "\"\$as_me:9749: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:9748: \$? = $ac_status" >&5 + echo "$as_me:9753: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -10080,11 +10085,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:10083: $lt_compile\"" >&5) + (eval echo "\"\$as_me:10088: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:10087: \$? = $ac_status" >&5 + echo "$as_me:10092: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -10185,11 +10190,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:10188: $lt_compile\"" >&5) + (eval echo "\"\$as_me:10193: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:10192: \$? = $ac_status" >&5 + echo "$as_me:10197: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -10240,11 +10245,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:10243: $lt_compile\"" >&5) + (eval echo "\"\$as_me:10248: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:10247: \$? = $ac_status" >&5 + echo "$as_me:10252: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -13043,7 +13048,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 13046 "configure" +#line 13051 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -13139,7 +13144,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 13142 "configure" +#line 13147 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -14748,7 +14753,13 @@ _ACEOF cat confdefs.h >>conftest.$ac_ext cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ + $ac_includes_default +#ifdef HAVE_WINSOCK2_H +# include +#endif + + int main () { @@ -14782,7 +14793,13 @@ _ACEOF cat confdefs.h >>conftest.$ac_ext cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ + $ac_includes_default +#ifdef HAVE_WINSOCK2_H +# include +#endif + + int main () { @@ -14834,7 +14851,7 @@ if test "x$ac_cv_type_u_char" = x""yes; then : else -cat >>confdefs.h <<_ACEOF +cat >>confdefs.h <<\_ACEOF #define u_char unsigned char _ACEOF @@ -14854,7 +14871,7 @@ cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ $ac_includes_default -#if HAVE_SYS_RESOURCE_H +#ifdef HAVE_SYS_RESOURCE_H # include #endif @@ -14894,7 +14911,7 @@ cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ $ac_includes_default -#if HAVE_SYS_RESOURCE_H +#ifdef HAVE_SYS_RESOURCE_H # include #endif @@ -14971,9 +14988,12 @@ cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ $ac_includes_default -#if HAVE_SYS_SOCKET_H +#ifdef HAVE_SYS_SOCKET_H # include #endif +#ifdef HAVE_WS2TCPIP_H +# include +#endif int @@ -15011,9 +15031,12 @@ cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ $ac_includes_default -#if HAVE_SYS_SOCKET_H +#ifdef HAVE_SYS_SOCKET_H # include #endif +#ifdef HAVE_WS2TCPIP_H +# include +#endif int @@ -15087,10 +15110,10 @@ cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ $ac_includes_default -#if HAVE_SYS_TYPES_H +#ifdef HAVE_SYS_TYPES_H # include #endif -#if HAVE_NETINET_IN_H +#ifdef HAVE_NETINET_IN_H # include #endif @@ -15130,10 +15153,10 @@ cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ $ac_includes_default -#if HAVE_SYS_TYPES_H +#ifdef HAVE_SYS_TYPES_H # include #endif -#if HAVE_NETINET_IN_H +#ifdef HAVE_NETINET_IN_H # include #endif @@ -15209,10 +15232,10 @@ cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ $ac_includes_default -#if HAVE_SYS_TYPES_H +#ifdef HAVE_SYS_TYPES_H # include #endif -#if HAVE_NETINET_IN_H +#ifdef HAVE_NETINET_IN_H # include #endif @@ -15252,10 +15275,10 @@ cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ $ac_includes_default -#if HAVE_SYS_TYPES_H +#ifdef HAVE_SYS_TYPES_H # include #endif -#if HAVE_NETINET_IN_H +#ifdef HAVE_NETINET_IN_H # include #endif @@ -16864,6 +16887,8 @@ fi $as_echo "$as_me: error: Need SSL library to do digital signature cryptography" >&2;} { (exit 1); exit 1; }; } fi + + withval=$withval if test x_$withval != x_no; then { $as_echo "$as_me:$LINENO: checking for SSL" >&5 $as_echo_n "checking for SSL... " >&6; } @@ -16879,9 +16904,9 @@ cat >>confdefs.h <<_ACEOF #define HAVE_SSL /**/ _ACEOF - if test "$ssldir" != "/usr"; then - CPPFLAGS="$CPPFLAGS -I$ssldir/include" - fi + if test "$ssldir" != "/usr"; then + CPPFLAGS="$CPPFLAGS -I$ssldir/include" + fi break; fi done @@ -16893,7 +16918,7 @@ $as_echo "$as_me: error: Cannot find the SSL libraries in $withval" >&2;} { $as_echo "$as_me:$LINENO: result: found in $ssldir" >&5 $as_echo "found in $ssldir" >&6; } HAVE_SSL=yes - if test "$ssldir" != "/usr" -a "$ssldir" != ""; then + if test "$ssldir" != "/usr" -a "$ssldir" != ""; then LDFLAGS="$LDFLAGS -L$ssldir/lib" if test "x$enable_rpath" = xyes; then @@ -16902,12 +16927,12 @@ $as_echo "found in $ssldir" >&6; } fi fi - fi + fi - { $as_echo "$as_me:$LINENO: checking for HMAC_CTX_init in -lcrypto" >&5 + { $as_echo "$as_me:$LINENO: checking for HMAC_CTX_init in -lcrypto" >&5 $as_echo_n "checking for HMAC_CTX_init in -lcrypto... " >&6; } - LIBS="$LIBS -lcrypto" - cat >conftest.$ac_ext <<_ACEOF + LIBS="$LIBS -lcrypto" + cat >conftest.$ac_ext <<_ACEOF /* confdefs.h. */ _ACEOF cat confdefs.h >>conftest.$ac_ext @@ -16918,8 +16943,8 @@ int main () { - int HMAC_CTX_init(void); - (void)HMAC_CTX_init(); + int HMAC_CTX_init(void); + (void)HMAC_CTX_init(); ; return 0; @@ -16947,7 +16972,7 @@ $as_echo "$ac_try_echo") >&5 $as_test_x conftest$ac_exeext }; then - { $as_echo "$as_me:$LINENO: result: yes" >&5 + { $as_echo "$as_me:$LINENO: result: yes" >&5 $as_echo "yes" >&6; } cat >>confdefs.h <<\_ACEOF @@ -16960,14 +16985,14 @@ else sed 's/^/| /' conftest.$ac_ext >&5 - { $as_echo "$as_me:$LINENO: result: no" >&5 + { $as_echo "$as_me:$LINENO: result: no" >&5 $as_echo "no" >&6; } - # check if -lwsock32 or -lgdi32 are needed. - BAKLIBS="$LIBS" - LIBS="$LIBS -lgdi32" - { $as_echo "$as_me:$LINENO: checking if -lcrypto needs -lgdi32" >&5 + # check if -lwsock32 or -lgdi32 are needed. + BAKLIBS="$LIBS" + LIBS="$LIBS -lgdi32" + { $as_echo "$as_me:$LINENO: checking if -lcrypto needs -lgdi32" >&5 $as_echo_n "checking if -lcrypto needs -lgdi32... " >&6; } - cat >conftest.$ac_ext <<_ACEOF + cat >conftest.$ac_ext <<_ACEOF /* confdefs.h. */ _ACEOF cat confdefs.h >>conftest.$ac_ext @@ -16978,8 +17003,8 @@ int main () { - int HMAC_CTX_init(void); - (void)HMAC_CTX_init(); + int HMAC_CTX_init(void); + (void)HMAC_CTX_init(); ; return 0; @@ -17012,7 +17037,7 @@ cat >>confdefs.h <<\_ACEOF #define HAVE_HMAC_CTX_INIT 1 _ACEOF - { $as_echo "$as_me:$LINENO: result: yes" >&5 + { $as_echo "$as_me:$LINENO: result: yes" >&5 $as_echo "yes" >&6; } else @@ -17020,13 +17045,13 @@ else sed 's/^/| /' conftest.$ac_ext >&5 - { $as_echo "$as_me:$LINENO: result: no" >&5 + { $as_echo "$as_me:$LINENO: result: no" >&5 $as_echo "no" >&6; } - LIBS="$BAKLIBS" - LIBS="$LIBS -ldl" - { $as_echo "$as_me:$LINENO: checking if -lcrypto needs -ldl" >&5 + LIBS="$BAKLIBS" + LIBS="$LIBS -ldl" + { $as_echo "$as_me:$LINENO: checking if -lcrypto needs -ldl" >&5 $as_echo_n "checking if -lcrypto needs -ldl... " >&6; } - cat >conftest.$ac_ext <<_ACEOF + cat >conftest.$ac_ext <<_ACEOF /* confdefs.h. */ _ACEOF cat confdefs.h >>conftest.$ac_ext @@ -17037,8 +17062,8 @@ int main () { - int HMAC_CTX_init(void); - (void)HMAC_CTX_init(); + int HMAC_CTX_init(void); + (void)HMAC_CTX_init(); ; return 0; @@ -17071,7 +17096,7 @@ cat >>confdefs.h <<\_ACEOF #define HAVE_HMAC_CTX_INIT 1 _ACEOF - { $as_echo "$as_me:$LINENO: result: yes" >&5 + { $as_echo "$as_me:$LINENO: result: yes" >&5 $as_echo "yes" >&6; } else @@ -17079,7 +17104,7 @@ else sed 's/^/| /' conftest.$ac_ext >&5 - { $as_echo "$as_me:$LINENO: result: no" >&5 + { $as_echo "$as_me:$LINENO: result: no" >&5 $as_echo "no" >&6; } { { $as_echo "$as_me:$LINENO: error: OpenSSL found in $ssldir, but version 0.9.7 or higher is required" >&5 $as_echo "$as_me: error: OpenSSL found in $ssldir, but version 0.9.7 or higher is required" >&2;} @@ -17294,6 +17319,7 @@ done + # check if libssl needs libdl BAKLIBS="$LIBS" LIBS="-lssl $LIBS" @@ -18584,6 +18610,7 @@ if test x_$enable_static_exe = x_yes; then staticexe="-static" if test "$on_mingw" = yes; then staticexe="-all-static" + LIBS="$LIBS -lgdi32 -lz" fi fi @@ -18617,6 +18644,7 @@ _ACEOF else + for ac_header in stdlib.h do as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` @@ -18860,6 +18888,14 @@ fi + if test "$ac_cv_func_malloc_0_nonnull" = no; then + +cat >>confdefs.h <<_ACEOF +#define malloc rpl_malloc_unbound +_ACEOF + + fi + fi @@ -20359,6 +20395,98 @@ _ACEOF UB_ON_WINDOWS=yes + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}windres", so it can be a program name with args. +set dummy ${ac_tool_prefix}windres; ac_word=$2 +{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_WINDRES+set}" = set; then + $as_echo_n "(cached) " >&6 +else + if test -n "$WINDRES"; then + ac_cv_prog_WINDRES="$WINDRES" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_WINDRES="${ac_tool_prefix}windres" + $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +WINDRES=$ac_cv_prog_WINDRES +if test -n "$WINDRES"; then + { $as_echo "$as_me:$LINENO: result: $WINDRES" >&5 +$as_echo "$WINDRES" >&6; } +else + { $as_echo "$as_me:$LINENO: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_WINDRES"; then + ac_ct_WINDRES=$WINDRES + # Extract the first word of "windres", so it can be a program name with args. +set dummy windres; ac_word=$2 +{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_ac_ct_WINDRES+set}" = set; then + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_WINDRES"; then + ac_cv_prog_ac_ct_WINDRES="$ac_ct_WINDRES" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_WINDRES="windres" + $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +ac_ct_WINDRES=$ac_cv_prog_ac_ct_WINDRES +if test -n "$ac_ct_WINDRES"; then + { $as_echo "$as_me:$LINENO: result: $ac_ct_WINDRES" >&5 +$as_echo "$ac_ct_WINDRES" >&6; } +else + { $as_echo "$as_me:$LINENO: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_WINDRES" = x; then + WINDRES="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:$LINENO: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + WINDRES=$ac_ct_WINDRES + fi +else + WINDRES="$ac_cv_prog_WINDRES" +fi + fi if test $ac_cv_func_getaddrinfo = no; then case " $LIBOBJS " in @@ -20738,6 +20866,15 @@ fi { $as_echo "$as_me:$LINENO: checking if nonblocking sockets work" >&5 $as_echo_n "checking if nonblocking sockets work... " >&6; } +if echo $target | grep mingw32 >/dev/null; then + { $as_echo "$as_me:$LINENO: result: no (windows)" >&5 +$as_echo "no (windows)" >&6; } + +cat >>confdefs.h <<\_ACEOF +#define NONBLOCKING_IS_BROKEN 1 +_ACEOF + +else if test "$cross_compiling" = yes; then { $as_echo "$as_me:$LINENO: result: crosscompile(yes)" >&5 @@ -20923,6 +21060,7 @@ rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$a fi +fi { $as_echo "$as_me:$LINENO: checking whether mkdir has one arg" >&5 diff --git a/configure.ac b/configure.ac index ede51e679..8006fbb57 100644 --- a/configure.ac +++ b/configure.ac @@ -59,7 +59,11 @@ esac # are we on MinGW? if uname -s 2>&1 | grep MINGW32 >/dev/null; then on_mingw="yes" -else on_mingw="no"; fi +else + if echo $target | grep mingw32 >/dev/null; then on_mingw="yes" + else on_mingw="no"; fi +fi +echo "on mingw" $on_mingw # # Determine configuration file @@ -443,6 +447,7 @@ if test x_$enable_static_exe = x_yes; then staticexe="-static" if test "$on_mingw" = yes; then staticexe="-all-static" + LIBS="$LIBS -lgdi32 -lz" fi fi @@ -463,7 +468,7 @@ AC_ARG_ENABLE(alloc-checks, AC_HELP_STRING([--enable-alloc-checks], if test x_$enable_alloc_checks = x_yes; then AC_DEFINE(UNBOUND_ALLOC_STATS, 1, [use statistics for allocs and frees, for debug use]) else - AC_FUNC_MALLOC + ACX_FUNC_MALLOC([unbound]) fi AC_FUNC_CHOWN @@ -477,6 +482,7 @@ if test "$USE_WINSOCK" = 1; then AC_DEFINE(UB_ON_WINDOWS, 1, [Use win32 resources and API]) UB_ON_WINDOWS=yes AC_SUBST(UB_ON_WINDOWS) + AC_CHECK_TOOL(WINDRES, windres) fi if test $ac_cv_func_getaddrinfo = no; then AC_LIBOBJ([fake-rfc2553]) diff --git a/doc/Changelog b/doc/Changelog index 85e663be1..33a4d2a3b 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -2,6 +2,7 @@ - updated ldns tarball for solaris x64 compile assistance. - no need to define RAND_MAX from config.h. - iana portlist updated. + - configure changes and ldns update for mingw32 crosscompile. 13 July 2009: Wouter - Fix for crash at start on windows. diff --git a/ldns-src.tar.gz b/ldns-src.tar.gz index 25bb95189..804486099 100644 Binary files a/ldns-src.tar.gz and b/ldns-src.tar.gz differ diff --git a/testcode/delayer.c b/testcode/delayer.c index 3bc75e8ca..7ab6a974e 100644 --- a/testcode/delayer.c +++ b/testcode/delayer.c @@ -360,7 +360,7 @@ service_send(struct ringbuf* ring, struct timeval* now, ldns_buffer* pkt, (unsigned)tv.tv_sec, (unsigned)tv.tv_usec); log_addr(1, "from client", &p->addr, p->addr_len); /* send it */ - sent = sendto(p->s, ldns_buffer_begin(pkt), + sent = sendto(p->s, (void*)ldns_buffer_begin(pkt), ldns_buffer_limit(pkt), 0, (struct sockaddr*)srv_addr, srv_len); if(sent == -1) { @@ -384,7 +384,7 @@ do_proxy(struct proxy* p, int retsock, ldns_buffer* pkt) int i; ssize_t r; for(i=0; is, ldns_buffer_begin(pkt), + r = recv(p->s, (void*)ldns_buffer_begin(pkt), ldns_buffer_capacity(pkt), 0); if(r == -1) { #ifndef USE_WINSOCK @@ -403,8 +403,8 @@ do_proxy(struct proxy* p, int retsock, ldns_buffer* pkt) log_addr(1, "return reply to client", &p->addr, p->addr_len); /* send reply back to the real client */ p->numreturn++; - r = sendto(retsock, ldns_buffer_begin(pkt), (size_t)r, 0, - (struct sockaddr*)&p->addr, p->addr_len); + r = sendto(retsock, (void*)ldns_buffer_begin(pkt), (size_t)r, + 0, (struct sockaddr*)&p->addr, p->addr_len); if(r == -1) { #ifndef USE_WINSOCK log_err("sendto: %s", strerror(errno)); @@ -492,7 +492,7 @@ service_recv(int s, struct ringbuf* ring, ldns_buffer* pkt, struct proxy* p; for(i=0; iio[n].fd, info->qlist_data[info->qlist_idx], + r = sendto(info->io[n].fd, (void*)info->qlist_data[info->qlist_idx], info->qlist_len[info->qlist_idx], 0, (struct sockaddr*)&info->dest, info->destlen); /*log_hex("send", info->qlist_data[info->qlist_idx], @@ -299,7 +299,7 @@ static void perfreply(struct perfinfo* info, size_t n, struct timeval* now) { ssize_t r; - r = recv(info->io[n].fd, ldns_buffer_begin(info->buf), + r = recv(info->io[n].fd, (void*)ldns_buffer_begin(info->buf), ldns_buffer_capacity(info->buf), 0); if(r == -1) { #ifndef USE_WINSOCK diff --git a/testcode/streamtcp.c b/testcode/streamtcp.c index 838fef6e0..f79806fee 100644 --- a/testcode/streamtcp.c +++ b/testcode/streamtcp.c @@ -137,7 +137,7 @@ write_q(int fd, int udp, ldns_buffer* buf, int id, exit(1); } } - if(send(fd, ldns_buffer_begin(buf), ldns_buffer_limit(buf), 0) < + if(send(fd, (void*)ldns_buffer_begin(buf), ldns_buffer_limit(buf), 0) < (ssize_t)ldns_buffer_limit(buf)) { #ifndef USE_WINSOCK perror("send() data failed"); @@ -170,7 +170,8 @@ recv_one(int fd, int udp, ldns_buffer* buf) len = ntohs(len); ldns_buffer_clear(buf); ldns_buffer_set_limit(buf, len); - if(recv(fd, ldns_buffer_begin(buf), len, 0) < (ssize_t)len) { + if(recv(fd, (void*)ldns_buffer_begin(buf), len, 0) < + (ssize_t)len) { #ifndef USE_WINSOCK perror("read() data failed"); #else @@ -182,7 +183,7 @@ recv_one(int fd, int udp, ldns_buffer* buf) } else { ssize_t l; ldns_buffer_clear(buf); - if((l=recv(fd, ldns_buffer_begin(buf), + if((l=recv(fd, (void*)ldns_buffer_begin(buf), ldns_buffer_capacity(buf), 0)) < 0) { #ifndef USE_WINSOCK perror("read() data failed"); diff --git a/util/netevent.c b/util/netevent.c index 673aa1c0f..c10f688ce 100644 --- a/util/netevent.c +++ b/util/netevent.c @@ -246,7 +246,7 @@ comm_point_send_udp_msg(struct comm_point *c, ldns_buffer* packet, log_err("error: send empty UDP packet"); #endif log_assert(addr && addrlen > 0); - sent = sendto(c->fd, ldns_buffer_begin(packet), + sent = sendto(c->fd, (void*)ldns_buffer_begin(packet), ldns_buffer_remaining(packet), 0, addr, addrlen); if(sent == -1) { @@ -530,7 +530,7 @@ comm_point_udp_callback(int fd, short event, void* arg) rep.addrlen = (socklen_t)sizeof(rep.addr); log_assert(fd != -1); log_assert(ldns_buffer_remaining(rep.c->buffer) > 0); - recv = recvfrom(fd, ldns_buffer_begin(rep.c->buffer), + recv = recvfrom(fd, (void*)ldns_buffer_begin(rep.c->buffer), ldns_buffer_remaining(rep.c->buffer), 0, (struct sockaddr*)&rep.addr, &rep.addrlen); if(recv == -1) { @@ -711,7 +711,7 @@ comm_point_tcp_handle_read(int fd, struct comm_point* c, int short_ok) log_assert(fd != -1); if(c->tcp_byte_count < sizeof(uint16_t)) { /* read length bytes */ - r = recv(fd, ldns_buffer_at(c->buffer, c->tcp_byte_count), + r = recv(fd,(void*)ldns_buffer_at(c->buffer,c->tcp_byte_count), sizeof(uint16_t)-c->tcp_byte_count, 0); if(r == 0) return 0; @@ -760,7 +760,7 @@ comm_point_tcp_handle_read(int fd, struct comm_point* c, int short_ok) } log_assert(ldns_buffer_remaining(c->buffer) > 0); - r = recv(fd, ldns_buffer_current(c->buffer), + r = recv(fd, (void*)ldns_buffer_current(c->buffer), ldns_buffer_remaining(c->buffer), 0); if(r == 0) { return 0; @@ -902,7 +902,7 @@ comm_point_tcp_handle_write(int fd, struct comm_point* c) } } log_assert(ldns_buffer_remaining(c->buffer) > 0); - r = send(fd, ldns_buffer_current(c->buffer), + r = send(fd, (void*)ldns_buffer_current(c->buffer), ldns_buffer_remaining(c->buffer), 0); if(r == -1) { #ifndef USE_WINSOCK diff --git a/util/winsock_event.c b/util/winsock_event.c index 33cf08a10..ff5c9b093 100644 --- a/util/winsock_event.c +++ b/util/winsock_event.c @@ -76,6 +76,7 @@ settime(struct event_base* base) return 0; } +#ifdef UNBOUND_DEBUG /** * Find a fd in the list of items. * Note that not all items have a fd associated (those are -1). @@ -94,9 +95,10 @@ find_fd(struct event_base* base, int fd) } return -1; } +#endif /** Find ptr in base array */ -static int +static void zero_waitfor(WSAEVENT waitfor[], WSAEVENT x) { int i; diff --git a/winrc/README.txt b/winrc/README.txt index 0aeef8600..455b01c40 100644 --- a/winrc/README.txt +++ b/winrc/README.txt @@ -79,6 +79,23 @@ Unbound and its utilities also work from the commandline (like on unix) if you prefer. ++++ Cross compile + +You can crosscompile unbound. This results in .exe files. +Install the packages: mingw32-binutils mingw32-cpp mingw32-filesystem +mingw32-gcc mingw32-openssl mingw32-openssl-static mingw32-runtime +mingw32-termcap mingw32-w32api mingw32-zlib mingw32-zlib-static +(package names for fedora 11). + +Then run: +$ mingw32-configure +$ make + +It may be a good idea to pass --enable-static-exe --enable-debug to +the mingw32-configure line. This enables statically linked executables +so you do not need to pilfer dlls together, and debug has assertions. + + +++ CREDITS Unbound was written in portable C by Wouter Wijngaards (NLnet Labs). diff --git a/winrc/w_inst.c b/winrc/w_inst.c index b31004ad9..173ee3398 100644 --- a/winrc/w_inst.c +++ b/winrc/w_inst.c @@ -75,7 +75,7 @@ event_reg_install(FILE* out, const char* pathname) if(RegSetValueEx(hk, (LPCTSTR)"EventMessageFile", 0, /* reserved, mustbezero */ REG_EXPAND_SZ, /* value type (string w env subst) */ - pathname, /* data */ + (BYTE*)pathname, /* data */ (DWORD)strlen(pathname)+1)) /* length of data */ { RegCloseKey(hk); @@ -93,7 +93,7 @@ event_reg_install(FILE* out, const char* pathname) /* category message file */ if(RegSetValueEx(hk, (LPCTSTR)"CategoryMessageFile", 0, REG_EXPAND_SZ, - pathname, (DWORD)strlen(pathname)+1)) { + (BYTE*)pathname, (DWORD)strlen(pathname)+1)) { RegCloseKey(hk); fatal_win(out, "could not registry set CategoryMessageFile"); } diff --git a/winrc/win_svc.c b/winrc/win_svc.c index 6513b52e3..d362aaf75 100644 --- a/winrc/win_svc.c +++ b/winrc/win_svc.c @@ -181,7 +181,7 @@ lookup_reg_str(const char* key, const char* name) if(type == REG_SZ || type == REG_MULTI_SZ || type == REG_EXPAND_SZ) { buf[sizeof(buf)-1] = 0; buf[sizeof(buf)-2] = 0; /* for multi_sz */ - result = strdup(buf); + result = strdup((char*)buf); if(!result) reportev("out of memory"); } return result; @@ -221,9 +221,11 @@ lookup_reg_int(const char* key, const char* name) if(type == REG_SZ || type == REG_MULTI_SZ || type == REG_EXPAND_SZ) { buf[sizeof(buf)-1] = 0; buf[sizeof(buf)-2] = 0; /* for multi_sz */ - result = atoi(buf); + result = atoi((char*)buf); } else if(type == REG_DWORD) { - result = *(DWORD*)buf; + DWORD r; + memmove(&r, buf, sizeof(r)); + result = r; } return result; }