Change HZ in speed to rely on sysconf() if the clock tick is available
authorRichard Levitte <levitte@openssl.org>
Fri, 28 Sep 2001 10:34:48 +0000 (10:34 +0000)
committerRichard Levitte <levitte@openssl.org>
Fri, 28 Sep 2001 10:34:48 +0000 (10:34 +0000)
that way.  Synchronise s_time with these changes.

apps/s_time.c
apps/speed.c

index 0e2f456..3b6c808 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
 #include <stdlib.h>
 #include <string.h>
 
+#define USE_SOCKETS
+#include "apps.h"
 #ifdef OPENSSL_NO_STDIO
 #define APPS_WIN16
 #endif
 #ifdef OPENSSL_NO_STDIO
 #define APPS_WIN16
 #endif
-#define USE_SOCKETS
 #include <openssl/x509.h>
 #include <openssl/ssl.h>
 #include <openssl/pem.h>
 #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 "s_apps.h"
 #include <openssl/err.h>
 #ifdef WIN32_STUFF
 #include "winmain.h"
 #include "wintext.h"
 #endif
+#include OPENSSL_UNISTD
 
 #if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX)
 #define TIMES
 
 #if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX)
 #define TIMES
 /* The following if from times(3) man page.  It may need to be changed
 */
 #ifndef HZ
 /* 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
 #endif
 
 #undef PROG
index 2024c38..45df8aa 100644 (file)
@@ -83,6 +83,7 @@
 #include <openssl/err.h>
 #include <openssl/evp.h>
 #include <openssl/objects.h>
 #include <openssl/err.h>
 #include <openssl/evp.h>
 #include <openssl/objects.h>
+#include OPENSSL_UNISTD
 
 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(OPENSSL_SYS_MACOSX)
 # define USE_TOD
 
 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(OPENSSL_SYS_MACOSX)
 # define USE_TOD
 
 /* The following if from times(3) man page.  It may need to be changed */
 #ifndef HZ
 
 /* The following if from times(3) man page.  It may need to be changed */
 #ifndef HZ
-# 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 */
-#  ifdef OPENSSL_SYS_LINUX     /* Because it seems like some Linuxen
-                                  have weird values here... */
-#   define HZ   100.0
-#  else
+# 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
 #   define HZ ((double)CLK_TCK)
 #  endif
 # endif
@@ -1446,7 +1446,10 @@ int MAIN(int argc, char **argv)
 #endif
 #ifdef HZ
 #define as_string(s) (#s)
 #endif
 #ifdef HZ
 #define as_string(s) (#s)
-       printf("HZ=%g", (double)HZ);
+       printf("HZ=%g", HZ);
+# ifdef _SC_CLK_TCK
+       printf(" [sysconf value]");
+# endif
 #endif
        printf("\n");
        printf("timing function used: %s%s%s%s%s%s%s\n",
 #endif
        printf("\n");
        printf("timing function used: %s%s%s%s%s%s%s\n",