Navigation Menu

Skip to content

Commit

Permalink
Fixed: Now usable on Windows too
Browse files Browse the repository at this point in the history
Tested with Windows 7, Visual Studio 2013 Express
  • Loading branch information
monsdar committed Apr 6, 2014
1 parent 988dc1e commit 4319502
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions examples/C/zhelpers.h
Expand Up @@ -17,9 +17,13 @@
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>

#if (defined (WIN32))
# include <time.h>
#else
# include <sys/time.h>
#endif

#include <assert.h>
#include <signal.h>

Expand All @@ -29,7 +33,7 @@
#endif

// Provide random number from 0..(num-1)
#if (defined (__WINDOWS__))
#if (defined (WIN32))
# define randof(num) (int) ((float) (num) * rand () / (RAND_MAX + 1.0))
#else
# define randof(num) (int) ((float) (num) * random () / (RAND_MAX + 1.0))
Expand Down Expand Up @@ -78,7 +82,7 @@ s_dump (void *socket)
int size = zmq_msg_recv (&message, socket, 0);

// Dump the message as text or binary
char *data = zmq_msg_data (&message);
char *data = (char*)zmq_msg_data (&message);
int is_text = 1;
int char_nbr;
for (char_nbr = 0; char_nbr < size; char_nbr++)
Expand Down Expand Up @@ -120,7 +124,7 @@ s_set_id (void *socket)
static void
s_sleep (int msecs)
{
#if (defined (__WINDOWS__))
#if (defined (WIN32))
Sleep (msecs);
#else
struct timespec t;
Expand All @@ -134,7 +138,7 @@ s_sleep (int msecs)
static int64_t
s_clock (void)
{
#if (defined (__WINDOWS__))
#if (defined (WIN32))
SYSTEMTIME st;
GetSystemTime (&st);
return (int64_t) st.wSecond * 1000 + st.wMilliseconds;
Expand All @@ -153,7 +157,7 @@ s_console (const char *format, ...)
{
time_t curtime = time (NULL);
struct tm *loctime = localtime (&curtime);
char *formatted = malloc (20);
char *formatted = (char*)malloc (20);
strftime (formatted, 20, "%y-%m-%d %H:%M:%S ", loctime);
printf ("%s", formatted);
free (formatted);
Expand Down

0 comments on commit 4319502

Please sign in to comment.