Change HZ in speed to rely on sysconf() if the clock tick is available
[openssl.git] / apps / s_time.c
index a529e2a1190df6888acc17ad7d1575ec96732e41..3b6c8088850e620eb0189d80942bf44107c0db96 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
-#if defined(NO_RSA) && !defined(NO_SSL2)
-#define NO_SSL2
-#endif
-
-#ifdef NO_STDIO
+#define USE_SOCKETS
+#include "apps.h"
+#ifdef OPENSSL_NO_STDIO
 #define APPS_WIN16
 #endif
-#define USE_SOCKETS
 #include <openssl/x509.h>
 #include <openssl/ssl.h>
 #include <openssl/pem.h>
-#include "apps.h"
 #include "s_apps.h"
 #include <openssl/err.h>
 #ifdef WIN32_STUFF
 #include "winmain.h"
 #include "wintext.h"
 #endif
+#include OPENSSL_UNISTD
 
-#if !defined(MSDOS) && (!defined(VMS) || defined(__DECC))
+#if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX)
 #define TIMES
 #endif
 
    The __TMS macro will show if it was.  If it wasn't defined, we should
    undefine TIMES, since that tells the rest of the program how things
    should be handled.                          -- Richard Levitte */
-#if defined(VMS) && defined(__DECC) && !defined(__TMS)
+#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
 #undef TIMES
 #endif
 
 /* The following if from times(3) man page.  It may need to be changed
 */
 #ifndef HZ
-#ifndef CLK_TCK
-#define HZ      100.0
-#else /* CLK_TCK */
-#define HZ ((double)CLK_TCK)
-#endif
+# ifdef _SC_CLK_TCK
+#  define HZ ((double)sysconf(_SC_CLK_TCK))
+# else
+#  ifndef CLK_TCK
+#   ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
+#    define HZ 100.0
+#   else /* _BSD_CLK_TCK_ */
+#    define HZ ((double)_BSD_CLK_TCK_)
+#   endif
+#  else /* CLK_TCK */
+#   define HZ ((double)CLK_TCK)
+#  endif
+# endif
 #endif
 
 #undef PROG
@@ -178,7 +183,7 @@ static int perform=0;
 #ifdef FIONBIO
 static int t_nbio=0;
 #endif
-#ifdef WIN32
+#ifdef OPENSSL_SYS_WIN32
 static int exitNow = 0;                /* Set when it's time to exit main */
 #endif
 
@@ -202,7 +207,7 @@ static void s_time_init(void)
 #ifdef FIONBIO
        t_nbio=0;
 #endif
-#ifdef WIN32
+#ifdef OPENSSL_SYS_WIN32
        exitNow = 0;            /* Set when it's time to exit main */
 #endif
        }
@@ -220,7 +225,7 @@ static void s_time_usage(void)
                 file if not specified by this option\n\
 -CApath arg   - PEM format directory of CA's\n\
 -CAfile arg   - PEM format file of CA's\n\
--cipher       - prefered cipher to use, play with 'openssl ciphers'\n\n";
+-cipher       - preferred cipher to use, play with 'openssl ciphers'\n\n";
 
        printf( "usage: s_time <args>\n\n" );
 
@@ -229,7 +234,7 @@ static void s_time_usage(void)
        printf("-nbio         - Run with non-blocking IO\n");
        printf("-ssl2         - Just use SSLv2\n");
        printf("-ssl3         - Just use SSLv3\n");
-       printf("-bugs         - Turn on SSL bug compatability\n");
+       printf("-bugs         - Turn on SSL bug compatibility\n");
        printf("-new          - Just time new connections\n");
        printf("-reuse        - Just time connection reuse\n");
        printf("-www page     - Retrieve 'page' from the site\n");
@@ -248,15 +253,6 @@ static int parseArgs(int argc, char **argv)
 
     verify_depth=0;
     verify_error=X509_V_OK;
-#ifdef FIONBIO
-    t_nbio=0;
-#endif
-
-       apps_startup();
-       s_time_init();
-
-       if (bio_err == NULL)
-               bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
 
     argc--;
     argv++;
@@ -327,11 +323,11 @@ static int parseArgs(int argc, char **argv)
                }
        else if(strcmp(*argv,"-bugs") == 0)
            st_bugs=1;
-#ifndef NO_SSL2
+#ifndef OPENSSL_NO_SSL2
        else if(strcmp(*argv,"-ssl2") == 0)
            s_time_meth=SSLv2_client_method();
 #endif
-#ifndef NO_SSL3
+#ifndef OPENSSL_NO_SSL3
        else if(strcmp(*argv,"-ssl3") == 0)
            s_time_meth=SSLv3_client_method();
 #endif
@@ -401,6 +397,8 @@ static double tm_Time_F(int s)
  * MAIN - main processing area for client
  *                     real name depends on MONOLITH
  */
+int MAIN(int, char **);
+
 int MAIN(int argc, char **argv)
        {
        double totalTime = 0.0;
@@ -411,11 +409,17 @@ int MAIN(int argc, char **argv)
        MS_STATIC char buf[1024*8];
        int ver;
 
-#if !defined(NO_SSL2) && !defined(NO_SSL3)
+       apps_startup();
+       s_time_init();
+
+       if (bio_err == NULL)
+               bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
+
+#if !defined(OPENSSL_NO_SSL2) && !defined(OPENSSL_NO_SSL3)
        s_time_meth=SSLv23_client_method();
-#elif !defined(NO_SSL3)
+#elif !defined(OPENSSL_NO_SSL3)
        s_time_meth=SSLv3_client_method();
-#elif !defined(NO_SSL2)
+#elif !defined(OPENSSL_NO_SSL2)
        s_time_meth=SSLv2_client_method();
 #endif
 
@@ -423,7 +427,7 @@ int MAIN(int argc, char **argv)
        if( parseArgs( argc, argv ) < 0 )
                goto end;
 
-       SSLeay_add_ssl_algorithms();
+       OpenSSL_add_ssl_algorithms();
        if ((tm_ctx=SSL_CTX_new(s_time_meth)) == NULL) return(1);
 
        SSL_CTX_set_quiet_shutdown(tm_ctx,1);
@@ -438,7 +442,7 @@ int MAIN(int argc, char **argv)
        if ((!SSL_CTX_load_verify_locations(tm_ctx,CAfile,CApath)) ||
                (!SSL_CTX_set_default_verify_paths(tm_ctx)))
                {
-               /* BIO_printf(bio_err,"error seting default verify locations\n"); */
+               /* BIO_printf(bio_err,"error setting default verify locations\n"); */
                ERR_print_errors(bio_err);
                /* goto end; */
                }
@@ -448,7 +452,6 @@ int MAIN(int argc, char **argv)
 
        if (tm_cipher == NULL ) {
                fprintf( stderr, "No CIPHER specified\n" );
-/*             EXIT(1); */
        }
 
        if (!(perform & 1)) goto next;
@@ -615,6 +618,7 @@ end:
                SSL_CTX_free(tm_ctx);
                tm_ctx=NULL;
                }
+       apps_shutdown();
        EXIT(ret);
        }
 
@@ -639,7 +643,7 @@ static SSL *doConnection(SSL *scon)
        BIO_set_conn_hostname(conn,host);
 
        if (scon == NULL)
-               serverCon=(SSL *)SSL_new(tm_ctx);
+               serverCon=SSL_new(tm_ctx);
        else
                {
                serverCon=scon;