summaryrefslogtreecommitdiffstats
path: root/programs
diff options
context:
space:
mode:
Diffstat (limited to 'programs')
-rw-r--r--programs/frametest.c38
-rw-r--r--programs/fuzzer.c41
2 files changed, 66 insertions, 13 deletions
diff --git a/programs/frametest.c b/programs/frametest.c
index 71490a6..a5a23c2 100644
--- a/programs/frametest.c
+++ b/programs/frametest.c
@@ -23,7 +23,7 @@
*/
/**************************************
- Compiler specific
+* Compiler specific
**************************************/
#define _CRT_SECURE_NO_WARNINGS // fgets
#ifdef _MSC_VER /* Visual Studio */
@@ -36,20 +36,31 @@
# pragma GCC diagnostic ignored "-Wmissing-field-initializers" /* GCC bug 53119 : doesn't accept { 0 } as initializer (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119) */
#endif
+/* S_ISREG & gettimeofday() are not supported by MSVC */
+#if defined(_MSC_VER) || defined(_WIN32)
+# define FUZ_LEGACY_TIMER 1
+#endif
+
/**************************************
- Includes
+* Includes
**************************************/
#include <stdlib.h> // free
#include <stdio.h> // fgets, sscanf
-#include <sys/timeb.h> // timeb
#include <string.h> // strcmp
#include "lz4frame_static.h"
#include "xxhash.h" // XXH64
+/* Use ftime() if gettimeofday() is not available on your target */
+#if defined(FUZ_LEGACY_TIMER)
+# include <sys/timeb.h> /* timeb, ftime */
+#else
+# include <sys/time.h> /* gettimeofday */
+#endif
+
/**************************************
- Basic Types
+* Basic Types
**************************************/
#if defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */
# include <stdint.h>
@@ -68,7 +79,7 @@ typedef unsigned long long U64;
/**************************************
- Constants
+* Constants
**************************************/
#ifndef LZ4_VERSION
# define LZ4_VERSION ""
@@ -109,8 +120,10 @@ static U32 pause = 0;
/*********************************************************
- Fuzzer functions
+* Fuzzer functions
*********************************************************/
+#if defined(FUZ_LEGACY_TIMER)
+
static U32 FUZ_GetMilliStart(void)
{
struct timeb tb;
@@ -120,6 +133,19 @@ static U32 FUZ_GetMilliStart(void)
return nCount;
}
+#else
+
+static U32 FUZ_GetMilliStart(void)
+{
+ struct timeval tv;
+ U32 nCount;
+ gettimeofday(&tv, NULL);
+ nCount = (U32) (tv.tv_usec/1000 + (tv.tv_sec & 0xfffff) * 1000);
+ return nCount;
+}
+
+#endif
+
static U32 FUZ_GetMilliSpan(U32 nTimeStart)
{
diff --git a/programs/fuzzer.c b/programs/fuzzer.c
index 6d3b077..f9467d9 100644
--- a/programs/fuzzer.c
+++ b/programs/fuzzer.c
@@ -25,7 +25,7 @@
*/
/**************************************
-* Remove Visual warning messages
+* Compiler options
**************************************/
#ifdef _MSC_VER /* Visual Studio */
# define _CRT_SECURE_NO_WARNINGS /* fgets */
@@ -34,21 +34,32 @@
# pragma warning(disable : 4310) /* disable: C4310: constant char value > 127 */
#endif
+/* S_ISREG & gettimeofday() are not supported by MSVC */
+#if defined(_MSC_VER) || defined(_WIN32)
+# define FUZ_LEGACY_TIMER 1
+#endif
+
/**************************************
-* Includes
+* Includes
**************************************/
#include <stdlib.h>
#include <stdio.h> /* fgets, sscanf */
-#include <sys/timeb.h> /* timeb */
#include <string.h> /* strcmp */
#include "lz4.h"
#include "lz4hc.h"
#include "xxhash.h"
+/* Use ftime() if gettimeofday() is not available on your target */
+#if defined(FUZ_LEGACY_TIMER)
+# include <sys/timeb.h> /* timeb, ftime */
+#else
+# include <sys/time.h> /* gettimeofday */
+#endif
+
/**************************************
-* Basic Types
+* Basic Types
**************************************/
#if defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */
# include <stdint.h>
@@ -67,7 +78,7 @@ typedef unsigned long long U64;
/**************************************
-* Constants
+* Constants
**************************************/
#ifndef LZ4_VERSION
# define LZ4_VERSION ""
@@ -88,7 +99,7 @@ typedef unsigned long long U64;
/*****************************************
-* Macros
+* Macros
*****************************************/
#define DISPLAY(...) fprintf(stderr, __VA_ARGS__)
#define DISPLAYLEVEL(l, ...) if (g_displayLevel>=l) { DISPLAY(__VA_ARGS__); }
@@ -98,8 +109,10 @@ static U32 g_time = 0;
/*********************************************************
- Fuzzer functions
+* Fuzzer functions
*********************************************************/
+#if defined(FUZ_LEGACY_TIMER)
+
static U32 FUZ_GetMilliStart(void)
{
struct timeb tb;
@@ -109,6 +122,20 @@ static U32 FUZ_GetMilliStart(void)
return nCount;
}
+#else
+
+static U32 FUZ_GetMilliStart(void)
+{
+ struct timeval tv;
+ U32 nCount;
+ gettimeofday(&tv, NULL);
+ nCount = (U32) (tv.tv_usec/1000 + (tv.tv_sec & 0xfffff) * 1000);
+ return nCount;
+}
+
+#endif
+
+
static U32 FUZ_GetMilliSpan(U32 nTimeStart)
{
U32 nCurrent = FUZ_GetMilliStart();