Constify the API and enable -Wwrite-strings

The API is more similar to printf now.
This commit is contained in:
Pierre Riteau 2010-05-25 13:56:18 +02:00
parent bd4ec57059
commit 4693a51707
7 changed files with 13 additions and 13 deletions

View File

@ -8,7 +8,7 @@ ifeq ($(uname_S),SunOS)
CFLAGS?= -std=c99 -pedantic $(OPTIMIZATION) -Wall -W -D__EXTENSIONS__ -D_XPG6 CFLAGS?= -std=c99 -pedantic $(OPTIMIZATION) -Wall -W -D__EXTENSIONS__ -D_XPG6
CCLINK?= -ldl -lnsl -lsocket -lm -lpthread CCLINK?= -ldl -lnsl -lsocket -lm -lpthread
else else
CFLAGS?= -std=c99 -pedantic $(OPTIMIZATION) -Wall -W $(ARCH) $(PROF) CFLAGS?= -std=c99 -pedantic $(OPTIMIZATION) -Wall -W -Wwrite-strings $(ARCH) $(PROF)
CCLINK?= -lm -pthread CCLINK?= -lm -pthread
endif endif
CCOPT= $(CFLAGS) $(CCLINK) $(ARCH) $(PROF) CCOPT= $(CFLAGS) $(CCLINK) $(ARCH) $(PROF)

4
anet.c
View File

@ -125,7 +125,7 @@ int anetResolve(char *err, char *host, char *ipbuf)
#define ANET_CONNECT_NONE 0 #define ANET_CONNECT_NONE 0
#define ANET_CONNECT_NONBLOCK 1 #define ANET_CONNECT_NONBLOCK 1
static int anetTcpGenericConnect(char *err, char *addr, int port, int flags) static int anetTcpGenericConnect(char *err, const char *addr, int port, int flags)
{ {
int s, on = 1; int s, on = 1;
struct sockaddr_in sa; struct sockaddr_in sa;
@ -167,7 +167,7 @@ static int anetTcpGenericConnect(char *err, char *addr, int port, int flags)
return s; return s;
} }
int anetTcpConnect(char *err, char *addr, int port) int anetTcpConnect(char *err, const char *addr, int port)
{ {
return anetTcpGenericConnect(err,addr,port,ANET_CONNECT_NONE); return anetTcpGenericConnect(err,addr,port,ANET_CONNECT_NONE);
} }

2
anet.h
View File

@ -35,7 +35,7 @@
#define ANET_ERR -1 #define ANET_ERR -1
#define ANET_ERR_LEN 256 #define ANET_ERR_LEN 256
int anetTcpConnect(char *err, char *addr, int port); int anetTcpConnect(char *err, const char *addr, int port);
int anetTcpNonBlockConnect(char *err, char *addr, int port); int anetTcpNonBlockConnect(char *err, char *addr, int port);
int anetRead(int fd, char *buf, int count); int anetRead(int fd, char *buf, int count);
int anetResolve(char *err, char *host, char *ipbuf); int anetResolve(char *err, char *host, char *ipbuf);

View File

@ -50,7 +50,7 @@ static void redisOOM(void) {
* to the socket file descriptor. On error a redisReply object is returned * to the socket file descriptor. On error a redisReply object is returned
* with reply->type set to REDIS_REPLY_ERROR and reply->string containing * with reply->type set to REDIS_REPLY_ERROR and reply->string containing
* the error message. This replyObject must be freed with redisFreeReply(). */ * the error message. This replyObject must be freed with redisFreeReply(). */
redisReply *redisConnect(int *fd, char *ip, int port) { redisReply *redisConnect(int *fd, const char *ip, int port) {
char err[ANET_ERR_LEN]; char err[ANET_ERR_LEN];
*fd = anetTcpConnect(err,ip,port); *fd = anetTcpConnect(err,ip,port);
@ -233,10 +233,10 @@ static void addArgument(sds a, char ***argv, int *argc) {
* Finally when type is REDIS_REPLY_INTEGER the long long integer is * Finally when type is REDIS_REPLY_INTEGER the long long integer is
* stored at reply->integer. * stored at reply->integer.
*/ */
redisReply *redisCommand(int fd, char *format, ...) { redisReply *redisCommand(int fd, const char *format, ...) {
va_list ap; va_list ap;
size_t size; size_t size;
char *arg, *c = format; const char *arg, *c = format;
sds cmd = sdsempty(); /* whole command buffer */ sds cmd = sdsempty(); /* whole command buffer */
sds current = sdsempty(); /* current argument */ sds current = sdsempty(); /* current argument */
char **argv = NULL; char **argv = NULL;

View File

@ -47,8 +47,8 @@ typedef struct redisReply {
struct redisReply **element; /* elements vector for REDIS_REPLY_ARRAY */ struct redisReply **element; /* elements vector for REDIS_REPLY_ARRAY */
} redisReply; } redisReply;
redisReply *redisConnect(int *fd, char *ip, int port); redisReply *redisConnect(int *fd, const char *ip, int port);
void freeReplyObject(redisReply *r); void freeReplyObject(redisReply *r);
redisReply *redisCommand(int fd, char *format, ...); redisReply *redisCommand(int fd, const char *format, ...);
#endif #endif

4
sds.c
View File

@ -116,7 +116,7 @@ static sds sdsMakeRoomFor(sds s, size_t addlen) {
return newsh->buf; return newsh->buf;
} }
sds sdscatlen(sds s, void *t, size_t len) { sds sdscatlen(sds s, const void *t, size_t len) {
struct sdshdr *sh; struct sdshdr *sh;
size_t curlen = sdslen(s); size_t curlen = sdslen(s);
@ -130,7 +130,7 @@ sds sdscatlen(sds s, void *t, size_t len) {
return s; return s;
} }
sds sdscat(sds s, char *t) { sds sdscat(sds s, const char *t) {
return sdscatlen(s, t, strlen(t)); return sdscatlen(s, t, strlen(t));
} }

4
sds.h
View File

@ -48,8 +48,8 @@ size_t sdslen(const sds s);
sds sdsdup(const sds s); sds sdsdup(const sds s);
void sdsfree(sds s); void sdsfree(sds s);
size_t sdsavail(sds s); size_t sdsavail(sds s);
sds sdscatlen(sds s, void *t, size_t len); sds sdscatlen(sds s, const void *t, size_t len);
sds sdscat(sds s, char *t); sds sdscat(sds s, const char *t);
sds sdscpylen(sds s, char *t, size_t len); sds sdscpylen(sds s, char *t, size_t len);
sds sdscpy(sds s, char *t); sds sdscpy(sds s, char *t);