Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
hiredis
Commits
ec229678
Commit
ec229678
authored
Mar 13, 2015
by
tzickel
Browse files
Added support for compiling the parser code with Microsoft Visual C compiler.
For hiredis-py and others support on windows.
parent
37c06fac
Changes
4
Show whitespace changes
Inline
Side-by-side
read.c
View file @
ec229678
...
@@ -33,7 +33,9 @@
...
@@ -33,7 +33,9 @@
#include "fmacros.h"
#include "fmacros.h"
#include <string.h>
#include <string.h>
#include <stdlib.h>
#include <stdlib.h>
#ifndef _MSC_VER
#include <unistd.h>
#include <unistd.h>
#endif
#include <assert.h>
#include <assert.h>
#include <errno.h>
#include <errno.h>
#include <ctype.h>
#include <ctype.h>
...
...
sds.c
View file @
ec229678
...
@@ -103,7 +103,7 @@ void sdsfree(sds s) {
...
@@ -103,7 +103,7 @@ void sdsfree(sds s) {
* the output will be "6" as the string was modified but the logical length
* the output will be "6" as the string was modified but the logical length
* remains 6 bytes. */
* remains 6 bytes. */
void
sdsupdatelen
(
sds
s
)
{
void
sdsupdatelen
(
sds
s
)
{
struct
sdshdr
*
sh
=
(
void
*
)
(
s
-
sizeof
*
sh
);
;
struct
sdshdr
*
sh
=
(
void
*
)
(
s
-
sizeof
*
sh
);
int
reallen
=
strlen
(
s
);
int
reallen
=
strlen
(
s
);
sh
->
free
+=
(
sh
->
len
-
reallen
);
sh
->
free
+=
(
sh
->
len
-
reallen
);
sh
->
len
=
reallen
;
sh
->
len
=
reallen
;
...
@@ -114,7 +114,7 @@ void sdsupdatelen(sds s) {
...
@@ -114,7 +114,7 @@ void sdsupdatelen(sds s) {
* so that next append operations will not require allocations up to the
* so that next append operations will not require allocations up to the
* number of bytes previously available. */
* number of bytes previously available. */
void
sdsclear
(
sds
s
)
{
void
sdsclear
(
sds
s
)
{
struct
sdshdr
*
sh
=
(
void
*
)
(
s
-
sizeof
*
sh
);
;
struct
sdshdr
*
sh
=
(
void
*
)
(
s
-
sizeof
*
sh
);
sh
->
free
+=
sh
->
len
;
sh
->
free
+=
sh
->
len
;
sh
->
len
=
0
;
sh
->
len
=
0
;
sh
->
buf
[
0
]
=
'\0'
;
sh
->
buf
[
0
]
=
'\0'
;
...
@@ -133,7 +133,7 @@ sds sdsMakeRoomFor(sds s, size_t addlen) {
...
@@ -133,7 +133,7 @@ sds sdsMakeRoomFor(sds s, size_t addlen) {
if
(
free
>=
addlen
)
return
s
;
if
(
free
>=
addlen
)
return
s
;
len
=
sdslen
(
s
);
len
=
sdslen
(
s
);
sh
=
(
void
*
)
(
s
-
sizeof
*
sh
);
;
sh
=
(
void
*
)
(
s
-
sizeof
*
sh
);
newlen
=
(
len
+
addlen
);
newlen
=
(
len
+
addlen
);
if
(
newlen
<
SDS_MAX_PREALLOC
)
if
(
newlen
<
SDS_MAX_PREALLOC
)
newlen
*=
2
;
newlen
*=
2
;
...
@@ -155,7 +155,7 @@ sds sdsMakeRoomFor(sds s, size_t addlen) {
...
@@ -155,7 +155,7 @@ sds sdsMakeRoomFor(sds s, size_t addlen) {
sds
sdsRemoveFreeSpace
(
sds
s
)
{
sds
sdsRemoveFreeSpace
(
sds
s
)
{
struct
sdshdr
*
sh
;
struct
sdshdr
*
sh
;
sh
=
(
void
*
)
(
s
-
sizeof
*
sh
);
;
sh
=
(
void
*
)
(
s
-
sizeof
*
sh
);
sh
=
realloc
(
sh
,
sizeof
*
sh
+
sh
->
len
+
1
);
sh
=
realloc
(
sh
,
sizeof
*
sh
+
sh
->
len
+
1
);
sh
->
free
=
0
;
sh
->
free
=
0
;
return
sh
->
buf
;
return
sh
->
buf
;
...
@@ -169,7 +169,7 @@ sds sdsRemoveFreeSpace(sds s) {
...
@@ -169,7 +169,7 @@ sds sdsRemoveFreeSpace(sds s) {
* 4) The implicit null term.
* 4) The implicit null term.
*/
*/
size_t
sdsAllocSize
(
sds
s
)
{
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
;
return
sizeof
(
*
sh
)
+
sh
->
len
+
sh
->
free
+
1
;
}
}
...
@@ -198,7 +198,7 @@ size_t sdsAllocSize(sds s) {
...
@@ -198,7 +198,7 @@ size_t sdsAllocSize(sds s) {
* sdsIncrLen(s, nread);
* sdsIncrLen(s, nread);
*/
*/
void
sdsIncrLen
(
sds
s
,
int
incr
)
{
void
sdsIncrLen
(
sds
s
,
int
incr
)
{
struct
sdshdr
*
sh
=
(
void
*
)
(
s
-
sizeof
*
sh
);
;
struct
sdshdr
*
sh
=
(
void
*
)
(
s
-
sizeof
*
sh
);
assert
(
sh
->
free
>=
incr
);
assert
(
sh
->
free
>=
incr
);
sh
->
len
+=
incr
;
sh
->
len
+=
incr
;
...
@@ -240,7 +240,7 @@ sds sdscatlen(sds s, const void *t, size_t len) {
...
@@ -240,7 +240,7 @@ sds sdscatlen(sds s, const void *t, size_t len) {
s
=
sdsMakeRoomFor
(
s
,
len
);
s
=
sdsMakeRoomFor
(
s
,
len
);
if
(
s
==
NULL
)
return
NULL
;
if
(
s
==
NULL
)
return
NULL
;
sh
=
(
void
*
)
(
s
-
sizeof
*
sh
);
;
sh
=
(
void
*
)
(
s
-
sizeof
*
sh
);
memcpy
(
s
+
curlen
,
t
,
len
);
memcpy
(
s
+
curlen
,
t
,
len
);
sh
->
len
=
curlen
+
len
;
sh
->
len
=
curlen
+
len
;
sh
->
free
=
sh
->
free
-
len
;
sh
->
free
=
sh
->
free
-
len
;
...
@@ -267,13 +267,13 @@ sds sdscatsds(sds s, const sds t) {
...
@@ -267,13 +267,13 @@ sds sdscatsds(sds s, const sds t) {
/* Destructively modify the sds string 's' to hold the specified binary
/* Destructively modify the sds string 's' to hold the specified binary
* safe string pointed by 't' of length 'len' bytes. */
* safe string pointed by 't' of length 'len' bytes. */
sds
sdscpylen
(
sds
s
,
const
char
*
t
,
size_t
len
)
{
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
;
size_t
totlen
=
sh
->
free
+
sh
->
len
;
if
(
totlen
<
len
)
{
if
(
totlen
<
len
)
{
s
=
sdsMakeRoomFor
(
s
,
len
-
sh
->
len
);
s
=
sdsMakeRoomFor
(
s
,
len
-
sh
->
len
);
if
(
s
==
NULL
)
return
NULL
;
if
(
s
==
NULL
)
return
NULL
;
sh
=
(
void
*
)
(
s
-
sizeof
*
sh
);
;
sh
=
(
void
*
)
(
s
-
sizeof
*
sh
);
totlen
=
sh
->
free
+
sh
->
len
;
totlen
=
sh
->
free
+
sh
->
len
;
}
}
memcpy
(
s
,
t
,
len
);
memcpy
(
s
,
t
,
len
);
...
@@ -541,7 +541,7 @@ sds sdscatfmt(sds s, char const *fmt, ...) {
...
@@ -541,7 +541,7 @@ sds sdscatfmt(sds s, char const *fmt, ...) {
* Output will be just "Hello World".
* Output will be just "Hello World".
*/
*/
void
sdstrim
(
sds
s
,
const
char
*
cset
)
{
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
;
char
*
start
,
*
end
,
*
sp
,
*
ep
;
size_t
len
;
size_t
len
;
...
@@ -573,7 +573,7 @@ void sdstrim(sds s, const char *cset) {
...
@@ -573,7 +573,7 @@ void sdstrim(sds s, const char *cset) {
* sdsrange(s,1,-1); => "ello World"
* sdsrange(s,1,-1); => "ello World"
*/
*/
void
sdsrange
(
sds
s
,
int
start
,
int
end
)
{
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
);
size_t
newlen
,
len
=
sdslen
(
s
);
if
(
len
==
0
)
return
;
if
(
len
==
0
)
return
;
...
...
sds.h
View file @
ec229678
...
@@ -35,6 +35,9 @@
...
@@ -35,6 +35,9 @@
#include <sys/types.h>
#include <sys/types.h>
#include <stdarg.h>
#include <stdarg.h>
#ifdef _MSC_VER
#include "win32.h"
#endif
typedef
char
*
sds
;
typedef
char
*
sds
;
...
...
win32.h
0 → 100644
View file @
ec229678
#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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment