Skip to content

Fix: Compile error on the Window paltform #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion core/samples/pubnub_objects_api_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
#include "core/pubnub_objects_api.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif
// This sample demo is split into 4 sections:
// 1. UUID metadata section
// 2. Channels metadata section
Expand Down
7 changes: 6 additions & 1 deletion core/samples/pubnub_sync_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@

#include <stdio.h>
#include <time.h>
#include <unistd.h>

#ifdef _WIN32
#include <windows.h>
#define sleep(x) Sleep(1000 * (x))
#else
#include <unistd.h>
#endif

static void generate_user_id(pubnub_t* pbp)
{
Expand Down
6 changes: 3 additions & 3 deletions lib/md5/md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static void const* body(MD5_CTX *ctx, void const* data, unsigned long size)
return ptr;
}

void MD5_Init(MD5_CTX *ctx)
void MD5_Init_(MD5_CTX *ctx)
{
ctx->a = 0x67452301;
ctx->b = 0xefcdab89;
Expand All @@ -205,7 +205,7 @@ void MD5_Init(MD5_CTX *ctx)
ctx->hi = 0;
}

void MD5_Update(MD5_CTX *ctx, void const *data, unsigned long size)
void MD5_Update_(MD5_CTX *ctx, void const *data, unsigned long size)
{
MD5_u32plus saved_lo;
unsigned long used, free;
Expand Down Expand Up @@ -239,7 +239,7 @@ void MD5_Update(MD5_CTX *ctx, void const *data, unsigned long size)
memcpy(ctx->buffer, data, size);
}

void MD5_Final(unsigned char *result, MD5_CTX *ctx)
void MD5_Final_(unsigned char *result, MD5_CTX *ctx)
{
unsigned long used, free;

Expand Down
6 changes: 3 additions & 3 deletions lib/md5/md5.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ typedef struct {
MD5_u32plus block[16];
} MD5_CTX;

extern void MD5_Init(MD5_CTX *ctx);
extern void MD5_Update(MD5_CTX *ctx, void const *data, unsigned long size);
extern void MD5_Final(unsigned char *result, MD5_CTX *ctx);
extern void MD5_Init_(MD5_CTX *ctx);
extern void MD5_Update_(MD5_CTX *ctx, void const *data, unsigned long size);
extern void MD5_Final_(unsigned char *result, MD5_CTX *ctx);

#endif
20 changes: 10 additions & 10 deletions lib/md5/pbmd5.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,47 +32,47 @@
/** Initializes the MD5 context for a new calculation.
@param x Pointer to a MD5 context
*/
#define pbmd5_init(x) MD5_Init(x)
#define pbmd5_init(x) MD5_Init_(x)

/** Update the MD5 context with the "next part of the message".
@param x Pointer to a MD5 context
@param m Pointer to the start of the "next part of the message"
@param l Length (in bytes) of the "next part of the message"
*/
#define pbmd5_update(x, m, l) MD5_Update((x), (m), (l))
#define pbmd5_update(x, m, l) MD5_Update_((x), (m), (l))

/** Update the MD5 context with the "next part of the message".
Assumes it is an ASCIIZ string.
@warning This macro uses @p str twice!
@param x Pointer to a MD5 context
@param str String being the "next part of the message"
*/
#define pbmd5_update_str(x, str) MD5_Update((x), (str), strlen(str))
#define pbmd5_update_str(x, str) MD5_Update_((x), (str), strlen(str))

/** Does the final calculations of the MD5 on context @p x and
stores the digest to @p d.
@param x Pointer to a MD5 context
@param d Pointer to an array of (at least) 16 bytes
*/
#define pbmd5_final(x, d) MD5_Final((d), (x))
#define pbmd5_final(x, d) MD5_Final_((d), (x))

/** This helper macro will calculate the MD5 on the message
in @p m, having the length @p l and store it in @p d.
*/
#define pbmd5_digest(m, l, d) do { MD5_CTX M_ctx_; \
MD5_Init(&M_ctx_); \
MD5_Update(&M_ctx_, (m), (l)); \
MD5_Final((d), &M_ctx); \
MD5_Init_(&M_ctx_); \
MD5_Update_(&M_ctx_, (m), (l)); \
MD5_Final_((d), &M_ctx); \
} while (0)

/** This helper macro will calculate the MD5 on the message in @p str,
assuming it's an ASCIIZ string andd store it in @p d.
@warning This macro uses @p str twice!
*/
#define pbmd5_digest_str(str, d) do { MD5_CTX M_ctx_; \
MD5_Init(&M_ctx_); \
MD5_Update(&M_ctx_, (str), strlen(str)); \
MD5_Final((d), &M_ctx); \
MD5_Init_(&M_ctx_); \
MD5_Update_(&M_ctx_, (str), strlen(str)); \
MD5_Final_((d), &M_ctx); \
} while (0)

#endif /* !defined INC_PBMD5 */