From: Date: Sat, 22 Sep 2007 05:26:29 +0000 (+0200) Subject: Fixed all warnings in code. X-Git-Tag: 0.2~10 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=875200dc0c5668bba4f8a68b487f9d2f2a1eedb0;hp=ca065f55235fd9979ede818963780f417d70c64e;p=awesomized%2Flibmemcached Fixed all warnings in code. --- diff --git a/lib/Makefile.am b/lib/Makefile.am index b9072cf2..93ab95ed 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,4 +1,4 @@ -INCLUDES = -I$(top_builddir)/include +INCLUDES = -I$(top_builddir)/include -Wall LIBS = lib_LTLIBRARIES = libmemcached.la diff --git a/lib/memcached.c b/lib/memcached.c index 6a7715de..8122e1e8 100644 --- a/lib/memcached.c +++ b/lib/memcached.c @@ -26,7 +26,6 @@ memcached_st *memcached_init(memcached_st *ptr) void memcached_deinit(memcached_st *ptr) { unsigned int x; - memcached_host_st *host_ptr; if (ptr->hosts) { diff --git a/lib/memcached_auto.c b/lib/memcached_auto.c index 975be824..7122dc90 100644 --- a/lib/memcached_auto.c +++ b/lib/memcached_auto.c @@ -20,15 +20,11 @@ static memcached_return memcached_auto(memcached_st *ptr, send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "%s %.*s %u\r\n", verb, - key_length, key, + (int)key_length, key, offset); if ((write(ptr->hosts[server_key].fd, buffer, send_length) == -1)) - { - fprintf(stderr, "failed set on %.*s TCP\n", key_length+1, key); - return MEMCACHED_WRITE_FAILURE; - } memset(buffer, 0, MEMCACHED_DEFAULT_COMMAND_SIZE); send_length= read(ptr->hosts[server_key].fd, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE); diff --git a/lib/memcached_connect.c b/lib/memcached_connect.c index d015c68a..a0c8737c 100644 --- a/lib/memcached_connect.c +++ b/lib/memcached_connect.c @@ -26,7 +26,6 @@ memcached_return memcached_connect(memcached_st *ptr) unsigned int x; struct sockaddr_in localAddr, servAddr; struct hostent *h; - memcached_host_st *host_ptr; if (ptr->connected) return MEMCACHED_SUCCESS; @@ -44,10 +43,7 @@ memcached_return memcached_connect(memcached_st *ptr) for (x= 0; x < ptr->number_of_hosts; x++) { if ((h= gethostbyname(ptr->hosts[x].hostname)) == NULL) - { - fprintf(stderr, "unknown host '%s'\n", ptr->hosts[x].hostname); return MEMCACHED_HOST_LOCKUP_FAILURE; - } servAddr.sin_family= h->h_addrtype; memcpy((char *) &servAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length); @@ -55,10 +51,7 @@ memcached_return memcached_connect(memcached_st *ptr) /* Create the socket */ if ((ptr->hosts[0].fd= socket(AF_INET, SOCK_STREAM, 0)) < 0) - { - fprintf(stderr, "cannot open socket"); return MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE; - } /* bind any port number */ @@ -67,19 +60,11 @@ memcached_return memcached_connect(memcached_st *ptr) localAddr.sin_port = htons(0); if (bind(ptr->hosts[0].fd, (struct sockaddr *) &localAddr, sizeof(localAddr)) < 0) - { - fprintf(stderr, "cannot bind port TCP %u\n", ptr->hosts[x].port); return(MEMCACHED_CONNECTION_BIND_FAILURE); - } /* connect to server */ if (connect(ptr->hosts[0].fd, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0) - { - fprintf(stderr, "cannot connect to host '%s' (%u) (error: %s)\n", ptr->hosts[x].hostname, - ptr->hosts[x].port, - strerror(errno)); return MEMCACHED_HOST_LOCKUP_FAILURE; - } } ptr->connected= 1; diff --git a/lib/memcached_delete.c b/lib/memcached_delete.c index e601e6fa..d24c0f82 100644 --- a/lib/memcached_delete.c +++ b/lib/memcached_delete.c @@ -17,16 +17,14 @@ memcached_return memcached_delete(memcached_st *ptr, char *key, size_t key_lengt if (expiration) send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, - "delete %.*s %u\r\n", key_length, key, expiration); + "delete %.*s %llu\r\n", (int)key_length, key, + (unsigned long long)expiration); else send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, - "delete %.*s\r\n", key_length, key); - if ((write(ptr->hosts[server_key].fd, buffer, send_length) == -1)) - { - fprintf(stderr, "failed set on %.*s TCP\n", key_length+1, key); + "delete %.*s\r\n", (int)key_length, key); + if ((write(ptr->hosts[server_key].fd, buffer, send_length) == -1)) return MEMCACHED_WRITE_FAILURE; - } return memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, server_key); } diff --git a/lib/memcached_flush.c b/lib/memcached_flush.c index a3e1be0b..8c51cdf1 100644 --- a/lib/memcached_flush.c +++ b/lib/memcached_flush.c @@ -16,16 +16,12 @@ memcached_return memcached_flush(memcached_st *ptr, time_t expiration) { if (expiration) send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, - "flush_all %u\r\n", expiration); + "flush_all %llu\r\n", (unsigned long long)expiration); else send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "flush_all\r\n"); if ((write(ptr->hosts[x].fd, buffer, send_length) == -1)) - { - fprintf(stderr, "failed flush_all TCP\n"); - return MEMCACHED_WRITE_FAILURE; - } rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, x); diff --git a/lib/memcached_get.c b/lib/memcached_get.c index 36d96505..a1885450 100644 --- a/lib/memcached_get.c +++ b/lib/memcached_get.c @@ -19,13 +19,12 @@ char *memcached_get(memcached_st *ptr, char *key, size_t key_length, server_key= memcached_generate_hash(key, key_length) % ptr->number_of_hosts; send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "get %.*s\r\n", - key_length, key); + (int)key_length, key); if (*error != MEMCACHED_SUCCESS) return NULL; if ((write(ptr->hosts[server_key].fd, buffer, send_length) == -1)) { - fprintf(stderr, "failed fetch on %.*s TCP\n", key_length+1, key); *error= MEMCACHED_WRITE_FAILURE; return NULL; } diff --git a/lib/memcached_stats.c b/lib/memcached_stats.c index 8928ee09..d7f948fa 100644 --- a/lib/memcached_stats.c +++ b/lib/memcached_stats.c @@ -207,9 +207,7 @@ memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_retur memcached_return memcached_stat_hostname(memcached_stat_st *stat, char *args, char *hostname, unsigned int port) { - size_t send_length; memcached_return rc; - char buffer[HUGE_STRING_LEN]; memcached_st memc; memcached_init(&memc); diff --git a/lib/memcached_storage.c b/lib/memcached_storage.c index 5c34a573..484341c8 100644 --- a/lib/memcached_storage.c +++ b/lib/memcached_storage.c @@ -32,32 +32,19 @@ static memcached_return memcached_send(memcached_st *ptr, server_key= memcached_generate_hash(key, key_length) % ptr->number_of_hosts; write_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, - "%s %.*s %u %u %u\r\n", verb, - key_length, key, flags, expiration, value_length); + "%s %.*s %x %llu %zu\r\n", verb, + (int)key_length, key, flags, + (unsigned long long)expiration, value_length); if ((sent_length= write(ptr->hosts[server_key].fd, buffer, write_length)) == -1) - { - fprintf(stderr, "failed %s on %.*s: %s\n", verb, key_length+1, key, strerror(errno)); - return MEMCACHED_WRITE_FAILURE; - } assert(write_length == sent_length); - WATCHPOINT; - printf("About to push %.*s\n", value_length, value); - WATCHPOINT; if ((sent_length= write(ptr->hosts[server_key].fd, value, value_length)) == -1) - { - fprintf(stderr, "failed %s on %.*s: %s\n", verb, key_length+1, key, strerror(errno)); - return MEMCACHED_WRITE_FAILURE; - } assert(value_length == sent_length); - if ((sent_length= write(ptr->hosts[server_key].fd, "\r\n", 2)) == -1) - { - fprintf(stderr, "failed %s on %.*s: %s\n", verb, key_length+1, key, strerror(errno)); + if ((sent_length= write(ptr->hosts[server_key].fd, "\r\n", 2)) == -1) return MEMCACHED_WRITE_FAILURE; - } assert(2 == sent_length); sent_length= read(ptr->hosts[server_key].fd, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE); diff --git a/lib/memcached_strerror.c b/lib/memcached_strerror.c index f6d9105e..335ec26c 100644 --- a/lib/memcached_strerror.c +++ b/lib/memcached_strerror.c @@ -41,6 +41,8 @@ char *memcached_strerror(memcached_st *ptr, memcached_return rc) case MEMCACHED_PARTIAL_READ: return "PARTIAL READ"; case MEMCACHED_SOME_ERRORS: - return "SOME ERRORS WERE REPORTED "; + return "SOME ERRORS WERE REPORTED"; }; + + return "COMPLETELY UNKNOWN ERROR, SOMEONE FORGOT TO UPDATE ERROR MESSAGES"; } diff --git a/lib/memcached_verbosity.c b/lib/memcached_verbosity.c index bb4f68c0..506dbb07 100644 --- a/lib/memcached_verbosity.c +++ b/lib/memcached_verbosity.c @@ -20,11 +20,7 @@ memcached_return memcached_verbosity(memcached_st *ptr, unsigned int verbosity) memcached_return rc; if ((write(ptr->hosts[x].fd, buffer, send_length) == -1)) - { - fprintf(stderr, "failed verbosity\n"); - return MEMCACHED_WRITE_FAILURE; - } rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, x); diff --git a/src/Makefile.am b/src/Makefile.am index 3f003d7c..57386fae 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -INCLUDES = -I$(top_builddir)/include +INCLUDES = -I$(top_builddir)/include -Wall LDADDS = ../lib/libmemcached.la bin_PROGRAMS = memcat memcp memstat memrm diff --git a/src/memcat.c b/src/memcat.c index 4253aa00..1e7f5bf7 100644 --- a/src/memcat.c +++ b/src/memcat.c @@ -10,8 +10,8 @@ /* Prototypes */ void options_parse(int argc, char *argv[]); -static int opt_verbose; -static int opt_displayflag; +static int opt_verbose= 0; +static int opt_displayflag= 0; static char *opt_servers; int main(int argc, char *argv[]) @@ -19,7 +19,7 @@ int main(int argc, char *argv[]) memcached_st *memc; char *string; size_t string_length; - uint16_t flags; + uint16_t flags; memcached_return rc; memc= memcached_init(NULL); @@ -37,39 +37,41 @@ int main(int argc, char *argv[]) { if (opt_displayflag) { - if (opt_verbose) - printf("key: %s\nflags: ", argv[optind]); - printf("%u\n", flags); + if (opt_verbose) + printf("key: %s\nflags: ", argv[optind]); + printf("%x\n", flags); } else { - if (opt_verbose) - printf("key: %s\nflags: %u\nlength: %uz\nvalue: ", - argv[optind], flags, string_length); - printf("%.*s\n", string_length, string); + if (opt_verbose) + printf("key: %s\nflags: %x\nlength: %zu\nvalue: ", + argv[optind], flags, string_length); + printf("%.*s\n", (int)string_length, string); free(string); } } else { fprintf(stderr, "memcat: %s: memcache error %s\n", - argv[optind], memcached_strerror(memc, rc)); + argv[optind], memcached_strerror(memc, rc)); } optind++; } memcached_deinit(memc); + free(opt_servers); + return 0; }; void options_parse(int argc, char *argv[]) { - int option_index = 0; + int option_index= 0; int option_rv; - static struct option long_options[] = + static struct option long_options[]= { {"version", no_argument, NULL, OPT_VERSION}, {"help", no_argument, NULL, OPT_HELP}, @@ -82,9 +84,10 @@ void options_parse(int argc, char *argv[]) while (1) { - option_rv = getopt_long(argc, argv, "Vhvds:", long_options, &option_index); + option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index); if (option_rv == -1) break; - switch (option_rv) { + switch (option_rv) + { case 0: break; case OPT_VERSION: /* --version or -V */ @@ -96,7 +99,7 @@ void options_parse(int argc, char *argv[]) exit(0); break; case OPT_SERVERS: /* --servers or -s */ - opt_servers= optarg; + opt_servers= strdup(optarg); break; case '?': /* getopt_long already printed an error message. */ diff --git a/src/memcp.c b/src/memcp.c index bba346b9..ec9a2faf 100644 --- a/src/memcp.c +++ b/src/memcp.c @@ -9,25 +9,26 @@ #include #include "client_options.h" +#include "utilities.h" /* Prototypes */ void options_parse(int argc, char *argv[]); static int opt_verbose= 0; static char *opt_servers= NULL; -static int opt_method= 0; -uint16_t opt_flags= 0; -time_t opt_expires= 0; +static int opt_method= OPT_SET; +static uint16_t opt_flags= 0; +static time_t opt_expires= 0; int main(int argc, char *argv[]) { memcached_st *memc; - char *string; - size_t string_length; memcached_return rc; + options_parse(argc, argv); memc= memcached_init(NULL); + if (opt_servers) parse_opt_servers(memc, opt_servers); else @@ -42,7 +43,7 @@ int main(int argc, char *argv[]) char *file_buffer_ptr; fd= open(argv[optind], O_RDONLY); - if (fd < 0) + if (fd < 0) { fprintf(stderr, "memcp: %s: %s\n", argv[optind], strerror(errno)); optind++; @@ -61,9 +62,9 @@ int main(int argc, char *argv[]) { static char *opstr[] = { "set", "add", "replace" }; printf("op: %s\nsource file: %s\nlength: %zu\n" - "key: %s\nflags: %u\n expires: %llu\n", - opstr[opt_method], argv[optind], sbuf.st_size, - ptr, opt_flags, opt_expires); + "key: %s\nflags: %x\n expires: %llu\n", + opstr[opt_method], argv[optind], (size_t)sbuf.st_size, + ptr, opt_flags, (unsigned long long)opt_expires); } if ((file_buffer_ptr= (char *)malloc(sizeof(char) * sbuf.st_size)) == NULL) @@ -104,17 +105,17 @@ int main(int argc, char *argv[]) memcached_deinit(memc); - cleanup(); + free(opt_servers); return 0; -}; +} void options_parse(int argc, char *argv[]) { int option_index= 0; int option_rv; - static struct option long_options[] = + static struct option long_options[]= { {"version", no_argument, NULL, OPT_VERSION}, {"help", no_argument, NULL, OPT_HELP}, @@ -135,7 +136,8 @@ void options_parse(int argc, char *argv[]) if (option_rv == -1) break; - switch (option_rv) { + switch (option_rv) + { case 0: break; case OPT_VERSION: /* --version or -V */ @@ -145,13 +147,13 @@ void options_parse(int argc, char *argv[]) printf("useful help messages go here\n"); exit(0); case OPT_SERVERS: /* --servers or -s */ - opt_servers= strdup_cleanup(optarg); + opt_servers= strdup(optarg); break; case OPT_FLAG: /* --flag */ - opt_flags= (uint16_t)strtol(optarg, (char **)NULL, 10); + opt_flags= (uint16_t)strtol(optarg, (char **)NULL, 16); break; case OPT_EXPIRE: /* --expire */ - opt_expires= (time_t)strtol(optarg, (char **)NULL, 10); + opt_expires= (time_t)strtoll(optarg, (char **)NULL, 10); break; case OPT_SET: opt_method= OPT_SET; diff --git a/src/memrm.c b/src/memrm.c index 4a3da021..3e468a3d 100644 --- a/src/memrm.c +++ b/src/memrm.c @@ -3,36 +3,73 @@ #include #include #include "client_options.h" +#include "utilities.h" -static int opt_verbose; -static char *opt_servers; +static int opt_verbose= 0; +static time_t opt_expire= 0; +static char *opt_servers= NULL; + +/* Prototypes */ +void options_parse(int argc, char *argv[]); int main(int argc, char *argv[]) { memcached_st *memc; - char *string; - size_t string_length; - time_t expires = 0; memcached_return rc; - static struct option long_options[] = + options_parse(argc, argv); + + memc= memcached_init(NULL); + + parse_opt_servers(memc, opt_servers); + + if (opt_servers) + parse_opt_servers(memc, opt_servers); + + while (optind <= argc) + { + if (opt_verbose) + printf("key: %s\nexpires: %llu\n", argv[optind], (unsigned long long)opt_expire); + rc = memcached_delete(memc, argv[optind], strlen(argv[optind]), opt_expire); + + if (rc != MEMCACHED_SUCCESS) { - {"version", no_argument, NULL, OPT_VERSION}, - {"help", no_argument, NULL, OPT_HELP}, - {"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, - {"debug", no_argument, &opt_verbose, OPT_DEBUG}, - {"servers", required_argument, NULL, OPT_SERVERS}, - {"expire", required_argument, NULL, OPT_EXPIRE}, - {0, 0, 0, 0}, - }; - int option_index = 0; + fprintf(stderr, "memrm: %s: memcache error %s\n", + argv[optind], memcached_strerror(memc, rc)); + } + + optind++; + } + + memcached_deinit(memc); + + free(opt_servers); + + return 0; +} + + +void options_parse(int argc, char *argv[]) +{ + static struct option long_options[]= + { + {"version", no_argument, NULL, OPT_VERSION}, + {"help", no_argument, NULL, OPT_HELP}, + {"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, + {"debug", no_argument, &opt_verbose, OPT_DEBUG}, + {"servers", required_argument, NULL, OPT_SERVERS}, + {"expire", required_argument, NULL, OPT_EXPIRE}, + {0, 0, 0, 0}, + }; + int option_index= 0; int option_rv; while (1) { - option_rv = getopt_long(argc, argv, "Vhvds:", long_options, &option_index); + option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index); if (option_rv == -1) break; - switch (option_rv) { + switch (option_rv) + { case 0: break; case OPT_VERSION: /* --version or -V */ @@ -44,10 +81,10 @@ int main(int argc, char *argv[]) exit(0); break; case OPT_SERVERS: /* --servers or -s */ - opt_servers = optarg; + opt_servers= strdup(optarg); break; case OPT_EXPIRE: /* --expire */ - expires = (time_t)strtol(optarg, (char **)NULL, 10); + opt_expire= (time_t)strtoll(optarg, (char **)NULL, 10); break; case '?': /* getopt_long already printed an error message. */ @@ -56,26 +93,4 @@ int main(int argc, char *argv[]) abort(); } } - - memc= memcached_init(NULL); - parse_opt_servers(memc, opt_servers); - - while (optind <= argc) - { - if (opt_verbose) - printf("key: %s\nexpires: %llu\n", argv[optind], expires); - rc = memcached_delete(memc, argv[optind], strlen(argv[optind]), expires); - - if (rc != MEMCACHED_SUCCESS) - { - fprintf(stderr, "memrm: %s: memcache error %s\n", - argv[optind], memcached_strerror(memc, rc)); - } - - optind++; - } - - memcached_deinit(memc); - - return 0; -}; +} diff --git a/src/memstat.c b/src/memstat.c index dcfb3af9..e7810200 100644 --- a/src/memstat.c +++ b/src/memstat.c @@ -34,7 +34,7 @@ int main(int argc, char *argv[]) void options_parse(int argc, char *argv[]) { - static struct option long_options[] = + static struct option long_options[]= { {"version", no_argument, NULL, OPT_VERSION}, {"help", no_argument, NULL, OPT_HELP}, @@ -45,14 +45,15 @@ void options_parse(int argc, char *argv[]) {0, 0, 0, 0}, }; - int option_index = 0; + int option_index= 0; int option_rv; while (1) { - option_rv = getopt_long(argc, argv, "Vhvds:", long_options, &option_index); + option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index); if (option_rv == -1) break; - switch (option_rv) { + switch (option_rv) + { case 0: break; case OPT_VERSION: /* --version or -V */ @@ -64,7 +65,7 @@ void options_parse(int argc, char *argv[]) exit(0); break; case OPT_SERVERS: /* --servers or -s */ - opt_servers = optarg; + opt_servers= optarg; break; case '?': /* getopt_long already printed an error message. */ diff --git a/src/utilities.c b/src/utilities.c index ce6cd925..c866dd54 100644 --- a/src/utilities.c +++ b/src/utilities.c @@ -1,8 +1,5 @@ #include -static char **cleanup_list= NULL; -static char cleanup_list_length= 0; - void parse_opt_servers(memcached_st *memc, char *server_strings) { @@ -53,25 +50,3 @@ void parse_opt_servers(memcached_st *memc, } } } - -void cleanup(void) -{ - unsigned int x; - for (x= 0; x < cleanup_list_length; x++) - free(cleanup_list[x]); - - free(cleanup_list); -} - -char *strdup_cleanup(const char *str) -{ - char *ptr; - - ptr= strdup(str); - - cleanup_list= (char **)realloc(cleanup_list, sizeof(char *) * (cleanup_list_length+1)); - cleanup_list[cleanup_list_length]= ptr; - cleanup_list_length++; - - return ptr; -}