summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--read.c2
-rw-r--r--sds.c22
-rw-r--r--sds.h3
-rw-r--r--win32.h42
4 files changed, 58 insertions, 11 deletions
diff --git a/read.c b/read.c
index 457ac68..df1a467 100644
--- a/read.c
+++ b/read.c
@@ -33,7 +33,9 @@
#include "fmacros.h"
#include <string.h>
#include <stdlib.h>
+#ifndef _MSC_VER
#include <unistd.h>
+#endif
#include <assert.h>
#include <errno.h>
#include <ctype.h>
diff --git a/sds.c b/sds.c
index 72d623e..5d55b77 100644
--- a/sds.c
+++ b/sds.c
@@ -103,7 +103,7 @@ void sdsfree(sds s) {
* the output will be "6" as the string was modified but the logical length
* remains 6 bytes. */
void sdsupdatelen(sds s) {
- struct sdshdr *sh = (void*) (s-sizeof *sh);;
+ struct sdshdr *sh = (void*) (s-sizeof *sh);
int reallen = strlen(s);
sh->free += (sh->len-reallen);
sh->len = reallen;
@@ -114,7 +114,7 @@ void sdsupdatelen(sds s) {
* so that next append operations will not require allocations up to the
* number of bytes previously available. */
void sdsclear(sds s) {
- struct sdshdr *sh = (void*) (s-sizeof *sh);;
+ struct sdshdr *sh = (void*) (s-sizeof *sh);
sh->free += sh->len;
sh->len = 0;
sh->buf[0] = '\0';
@@ -133,7 +133,7 @@ sds sdsMakeRoomFor(sds s, size_t addlen) {
if (free >= addlen) return s;
len = sdslen(s);
- sh = (void*) (s-sizeof *sh);;
+ sh = (void*) (s-sizeof *sh);
newlen = (len+addlen);
if (newlen < SDS_MAX_PREALLOC)
newlen *= 2;
@@ -155,7 +155,7 @@ sds sdsMakeRoomFor(sds s, size_t addlen) {
sds sdsRemoveFreeSpace(sds s) {
struct sdshdr *sh;
- sh = (void*) (s-sizeof *sh);;
+ sh = (void*) (s-sizeof *sh);
sh = realloc(sh, sizeof *sh+sh->len+1);
sh->free = 0;
return sh->buf;
@@ -169,7 +169,7 @@ sds sdsRemoveFreeSpace(sds s) {
* 4) The implicit null term.
*/
size_t sdsAllocSize(sds s) {
- struct sdshdr *sh = (void*) (s-sizeof *sh);;
+ struct sdshdr *sh = (void*) (s-sizeof *sh);
return sizeof(*sh)+sh->len+sh->free+1;
}
@@ -198,7 +198,7 @@ size_t sdsAllocSize(sds s) {
* sdsIncrLen(s, nread);
*/
void sdsIncrLen(sds s, int incr) {
- struct sdshdr *sh = (void*) (s-sizeof *sh);;
+ struct sdshdr *sh = (void*) (s-sizeof *sh);
assert(sh->free >= incr);
sh->len += incr;
@@ -240,7 +240,7 @@ sds sdscatlen(sds s, const void *t, size_t len) {
s = sdsMakeRoomFor(s,len);
if (s == NULL) return NULL;
- sh = (void*) (s-sizeof *sh);;
+ sh = (void*) (s-sizeof *sh);
memcpy(s+curlen, t, len);
sh->len = curlen+len;
sh->free = sh->free-len;
@@ -267,13 +267,13 @@ sds sdscatsds(sds s, const sds t) {
/* Destructively modify the sds string 's' to hold the specified binary
* safe string pointed by 't' of length 'len' bytes. */
sds sdscpylen(sds s, const char *t, size_t len) {
- struct sdshdr *sh = (void*) (s-sizeof *sh);;
+ struct sdshdr *sh = (void*) (s-sizeof *sh);
size_t totlen = sh->free+sh->len;
if (totlen < len) {
s = sdsMakeRoomFor(s,len-sh->len);
if (s == NULL) return NULL;
- sh = (void*) (s-sizeof *sh);;
+ sh = (void*) (s-sizeof *sh);
totlen = sh->free+sh->len;
}
memcpy(s, t, len);
@@ -541,7 +541,7 @@ sds sdscatfmt(sds s, char const *fmt, ...) {
* Output will be just "Hello World".
*/
void sdstrim(sds s, const char *cset) {
- struct sdshdr *sh = (void*) (s-sizeof *sh);;
+ struct sdshdr *sh = (void*) (s-sizeof *sh);
char *start, *end, *sp, *ep;
size_t len;
@@ -573,7 +573,7 @@ void sdstrim(sds s, const char *cset) {
* sdsrange(s,1,-1); => "ello World"
*/
void sdsrange(sds s, int start, int end) {
- struct sdshdr *sh = (void*) (s-sizeof *sh);;
+ struct sdshdr *sh = (void*) (s-sizeof *sh);
size_t newlen, len = sdslen(s);
if (len == 0) return;
diff --git a/sds.h b/sds.h
index b53f24d..19a2abd 100644
--- a/sds.h
+++ b/sds.h
@@ -35,6 +35,9 @@
#include <sys/types.h>
#include <stdarg.h>
+#ifdef _MSC_VER
+#include "win32.h"
+#endif
typedef char *sds;
diff --git a/win32.h b/win32.h
new file mode 100644
index 0000000..1a27c18
--- /dev/null
+++ b/win32.h
@@ -0,0 +1,42 @@
+#ifndef _WIN32_HELPER_INCLUDE
+#define _WIN32_HELPER_INCLUDE
+#ifdef _MSC_VER
+
+#ifndef inline
+#define inline __inline
+#endif
+
+#ifndef va_copy
+#define va_copy(d,s) ((d) = (s))
+#endif
+
+#ifndef snprintf
+#define snprintf c99_snprintf
+
+__inline int c99_vsnprintf(char* str, size_t size, const char* format, va_list ap)
+{
+ int count = -1;
+
+ if (size != 0)
+ count = _vsnprintf_s(str, size, _TRUNCATE, format, ap);
+ if (count == -1)
+ count = _vscprintf(format, ap);
+
+ return count;
+}
+
+__inline int c99_snprintf(char* str, size_t size, const char* format, ...)
+{
+ int count;
+ va_list ap;
+
+ va_start(ap, format);
+ count = c99_vsnprintf(str, size, format, ap);
+ va_end(ap);
+
+ return count;
+}
+#endif
+
+#endif
+#endif \ No newline at end of file