<sys/select.h> is included for AIX, when USE_SOCKETS is defined.
[openssl.git] / apps / s_time.c
index ce52b463fcbc18b255f7597055835d62632c3a17..752158460aaf49437d935482c6de5fd687129f27 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
+#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
+#if !defined(OPENSSL_SYS_MSDOS)
+#include OPENSSL_UNISTD
+#endif
 
-#if !defined(MSDOS) && (!defined(VMS) || defined(__DECC))
+#if !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VXWORKS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC))
 #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
 
-#ifndef TIMES
+#if !defined(TIMES) && !defined(OPENSSL_SYS_VXWORKS)
 #include <sys/timeb.h>
 #endif
 
-#ifdef _AIX
-#include <sys/select.h>
-#endif
-
 #if defined(sun) || defined(__ultrix)
 #define _POSIX_SOURCE
 #include <limits.h>
 /* 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
 #undef BUFSIZZ
 #define BUFSIZZ 1024*10
 
+#undef min
+#undef max
 #define min(a,b) (((a) < (b)) ? (a) : (b))
 #define max(a,b) (((a) > (b)) ? (a) : (b))
 
@@ -174,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
 
@@ -198,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
        }
@@ -368,6 +377,22 @@ static double tm_Time_F(int s)
                ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
                return((ret == 0.0)?1e-6:ret);
        }
+#elif defined(OPENSSL_SYS_VXWORKS)
+        {
+       static unsigned long tick_start, tick_end;
+
+       if( s == START )
+               {
+               tick_start = tickGet();
+               return 0;
+               }
+       else
+               {
+               tick_end = tickGet();
+               ret = (double)(tick_end - tick_start) / (double)sysClkRateGet();
+               return((ret == 0.0)?1e-6:ret);
+               }
+        }
 #else /* !times() */
        static struct timeb tstart,tend;
        long i;
@@ -443,7 +468,6 @@ int MAIN(int argc, char **argv)
 
        if (tm_cipher == NULL ) {
                fprintf( stderr, "No CIPHER specified\n" );
-/*             EXIT(1); */
        }
 
        if (!(perform & 1)) goto next;
@@ -610,6 +634,7 @@ end:
                SSL_CTX_free(tm_ctx);
                tm_ctx=NULL;
                }
+       apps_shutdown();
        EXIT(ret);
        }