From 4693a51707fa5c29853d7df110b424df08114f38 Mon Sep 17 00:00:00 2001 From: Pierre Riteau Date: Tue, 25 May 2010 13:56:18 +0200 Subject: Constify the API and enable -Wwrite-strings The API is more similar to printf now. --- Makefile | 2 +- anet.c | 4 ++-- anet.h | 2 +- hiredis.c | 6 +++--- hiredis.h | 4 ++-- sds.c | 4 ++-- sds.h | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 815227c..e852c03 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ ifeq ($(uname_S),SunOS) CFLAGS?= -std=c99 -pedantic $(OPTIMIZATION) -Wall -W -D__EXTENSIONS__ -D_XPG6 CCLINK?= -ldl -lnsl -lsocket -lm -lpthread else - CFLAGS?= -std=c99 -pedantic $(OPTIMIZATION) -Wall -W $(ARCH) $(PROF) + CFLAGS?= -std=c99 -pedantic $(OPTIMIZATION) -Wall -W -Wwrite-strings $(ARCH) $(PROF) CCLINK?= -lm -pthread endif CCOPT= $(CFLAGS) $(CCLINK) $(ARCH) $(PROF) diff --git a/anet.c b/anet.c index 4fe811a..45b8620 100644 --- a/anet.c +++ b/anet.c @@ -125,7 +125,7 @@ int anetResolve(char *err, char *host, char *ipbuf) #define ANET_CONNECT_NONE 0 #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; struct sockaddr_in sa; @@ -167,7 +167,7 @@ static int anetTcpGenericConnect(char *err, char *addr, int port, int flags) 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); } diff --git a/anet.h b/anet.h index ce0f477..20fd3e2 100644 --- a/anet.h +++ b/anet.h @@ -35,7 +35,7 @@ #define ANET_ERR -1 #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 anetRead(int fd, char *buf, int count); int anetResolve(char *err, char *host, char *ipbuf); diff --git a/hiredis.c b/hiredis.c index fab1a7f..4e614ce 100644 --- a/hiredis.c +++ b/hiredis.c @@ -50,7 +50,7 @@ static void redisOOM(void) { * to the socket file descriptor. On error a redisReply object is returned * with reply->type set to REDIS_REPLY_ERROR and reply->string containing * 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]; *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 * stored at reply->integer. */ -redisReply *redisCommand(int fd, char *format, ...) { +redisReply *redisCommand(int fd, const char *format, ...) { va_list ap; size_t size; - char *arg, *c = format; + const char *arg, *c = format; sds cmd = sdsempty(); /* whole command buffer */ sds current = sdsempty(); /* current argument */ char **argv = NULL; diff --git a/hiredis.h b/hiredis.h index f63390e..f28dcdb 100644 --- a/hiredis.h +++ b/hiredis.h @@ -47,8 +47,8 @@ typedef struct redisReply { struct redisReply **element; /* elements vector for REDIS_REPLY_ARRAY */ } redisReply; -redisReply *redisConnect(int *fd, char *ip, int port); +redisReply *redisConnect(int *fd, const char *ip, int port); void freeReplyObject(redisReply *r); -redisReply *redisCommand(int fd, char *format, ...); +redisReply *redisCommand(int fd, const char *format, ...); #endif diff --git a/sds.c b/sds.c index f78a0a8..4424505 100644 --- a/sds.c +++ b/sds.c @@ -116,7 +116,7 @@ static sds sdsMakeRoomFor(sds s, size_t addlen) { 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; size_t curlen = sdslen(s); @@ -130,7 +130,7 @@ sds sdscatlen(sds s, void *t, size_t len) { return s; } -sds sdscat(sds s, char *t) { +sds sdscat(sds s, const char *t) { return sdscatlen(s, t, strlen(t)); } diff --git a/sds.h b/sds.h index 8b632ff..76d69a8 100644 --- a/sds.h +++ b/sds.h @@ -48,8 +48,8 @@ size_t sdslen(const sds s); sds sdsdup(const sds s); void sdsfree(sds s); size_t sdsavail(sds s); -sds sdscatlen(sds s, void *t, size_t len); -sds sdscat(sds s, char *t); +sds sdscatlen(sds s, const void *t, size_t len); +sds sdscat(sds s, const char *t); sds sdscpylen(sds s, char *t, size_t len); sds sdscpy(sds s, char *t); -- cgit v1.2.3