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;p=awesomized%2Flibmemcached Fixed all warnings in code. --- 875200dc0c5668bba4f8a68b487f9d2f2a1eedb0 diff --cc lib/Makefile.am index b9072cf2,b9072cf2..93ab95ed --- a/lib/Makefile.am +++ b/lib/Makefile.am @@@ -1,4 -1,4 +1,4 @@@ --INCLUDES = -I$(top_builddir)/include ++INCLUDES = -I$(top_builddir)/include -Wall LIBS = lib_LTLIBRARIES = libmemcached.la diff --cc lib/memcached.c index 6a7715de,6a7715de..8122e1e8 --- a/lib/memcached.c +++ b/lib/memcached.c @@@ -26,7 -26,7 +26,6 @@@ memcached_st *memcached_init(memcached_ void memcached_deinit(memcached_st *ptr) { unsigned int x; -- memcached_host_st *host_ptr; if (ptr->hosts) { diff --cc lib/memcached_auto.c index 975be824,268f95b8..7122dc90 --- a/lib/memcached_auto.c +++ b/lib/memcached_auto.c @@@ -20,15 -20,15 +20,11 @@@ static memcached_return memcached_auto( send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "%s %.*s %u\r\n", verb, -- key_length, key, ++ (int)key_length, key, offset); - if ((send(ptr->hosts[server_key].fd, buffer, send_length, 0) == -1)) - { - fprintf(stderr, "failed set on %.*s TCP\n", key_length+1, key); - + 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 --cc lib/memcached_connect.c index d015c68a,592ede44..a0c8737c --- a/lib/memcached_connect.c +++ b/lib/memcached_connect.c @@@ -26,7 -27,7 +26,6 @@@ memcached_return memcached_connect(memc unsigned int x; struct sockaddr_in localAddr, servAddr; struct hostent *h; -- memcached_host_st *host_ptr; if (ptr->connected) return MEMCACHED_SUCCESS; @@@ -44,10 -45,10 +43,7 @@@ 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 -56,10 +51,7 @@@ /* 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 -68,19 +60,11 @@@ 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 --cc lib/memcached_delete.c index e601e6fa,e601e6fa..d24c0f82 --- a/lib/memcached_delete.c +++ b/lib/memcached_delete.c @@@ -17,16 -17,16 +17,14 @@@ memcached_return memcached_delete(memca 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 --cc lib/memcached_flush.c index a3e1be0b,f7527a7c..8c51cdf1 --- a/lib/memcached_flush.c +++ b/lib/memcached_flush.c @@@ -16,16 -16,16 +16,12 @@@ memcached_return memcached_flush(memcac { 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 ((send(ptr->hosts[x].fd, buffer, send_length, 0) == -1)) - { - fprintf(stderr, "failed flush_all TCP\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 --cc lib/memcached_get.c index 36d96505,c688af34..a1885450 --- a/lib/memcached_get.c +++ b/lib/memcached_get.c @@@ -19,13 -19,13 +19,12 @@@ char *memcached_get(memcached_st *ptr, 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 ((send(ptr->hosts[server_key].fd, buffer, send_length, 0) == -1)) + 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 --cc lib/memcached_stats.c index 8928ee09,2511532c..d7f948fa --- a/lib/memcached_stats.c +++ b/lib/memcached_stats.c @@@ -207,9 -207,9 +207,7 @@@ memcached_stat_st *memcached_stat(memca 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 --cc lib/memcached_storage.c index 5c34a573,3df4913a..484341c8 --- a/lib/memcached_storage.c +++ b/lib/memcached_storage.c @@@ -31,40 -28,31 +31,27 @@@ static memcached_return memcached_send( server_key= memcached_generate_hash(key, key_length) % ptr->number_of_hosts; - send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, - "%s %.*s %u %u %u\r\n", verb, - key_length, key, flags, expiration, value_length); - if ((send(ptr->hosts[server_key].fd, buffer, send_length, 0) == -1)) - { - fprintf(stderr, "failed set on %.*s TCP\n", key_length+1, key); - + 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; - send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, - "%.*s\r\n", - value_length, value); - if ((send(ptr->hosts[server_key].fd, buffer, send_length, 0) == -1)) - { - fprintf(stderr, "failed set on %.*s TCP\n", key_length+1, key); + 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; -- } - - send_length= read(ptr->hosts[server_key].fd, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE); + assert(2 == sent_length); + + sent_length= read(ptr->hosts[server_key].fd, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE); - if (send_length && buffer[0] == 'S') /* STORED */ + if (sent_length && buffer[0] == 'S') /* STORED */ return MEMCACHED_SUCCESS; - else if (send_length && buffer[0] == 'N') /* NOT_STORED */ + else if (write_length && buffer[0] == 'N') /* NOT_STORED */ return MEMCACHED_NOTSTORED; else return MEMCACHED_READ_FAILURE; diff --cc lib/memcached_strerror.c index f6d9105e,f6d9105e..335ec26c --- a/lib/memcached_strerror.c +++ b/lib/memcached_strerror.c @@@ -41,6 -41,6 +41,8 @@@ char *memcached_strerror(memcached_st * 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 --cc lib/memcached_verbosity.c index bb4f68c0,4e586cfb..506dbb07 --- a/lib/memcached_verbosity.c +++ b/lib/memcached_verbosity.c @@@ -19,12 -19,12 +19,8 @@@ memcached_return memcached_verbosity(me { memcached_return rc; - if ((send(ptr->hosts[x].fd, buffer, send_length, 0) == -1)) - { - fprintf(stderr, "failed verbosity\n"); - + 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 --cc src/Makefile.am index 3f003d7c,3f003d7c..57386fae --- a/src/Makefile.am +++ b/src/Makefile.am @@@ -1,4 -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 --cc src/memcat.c index 4253aa00,ed540abb..1e7f5bf7 --- a/src/memcat.c +++ b/src/memcat.c @@@ -10,8 -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[]) @@@ -37,29 -36,29 +37,31 @@@ { if (opt_displayflag) { -- if (opt_verbose) -- printf("key: %s\nflags: ", argv[optind]); - printf("%u\n", flags); - printf("%x\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: ", - printf("key: %s\nflags: %x\nlength: %zu\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; }; @@@ -96,7 -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 --cc src/memcp.c index bba346b9,3a76049a..ec9a2faf --- a/src/memcp.c +++ b/src/memcp.c @@@ -9,40 -10,37 +9,41 @@@ #include #include "client_options.h" ++#include "utilities.h" /* Prototypes */ void options_parse(int argc, char *argv[]); -static int opt_verbose; -static char *opt_servers; -static int opt_replace; -uint16_t opt_flags= 0; -time_t opt_expires= 0; +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); - parse_opt_servers(memc, opt_servers); + - while (optind <= argc) + if (opt_servers) + parse_opt_servers(memc, opt_servers); + else + parse_opt_servers(memc, argv[--argc]); + + while (optind < argc) { - char *mptr; struct stat sbuf; int fd; char *ptr; + ssize_t read_length; + 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++; @@@ -57,57 -63,45 +58,57 @@@ else ptr= argv[optind]; - if (opt_verbose) + if (opt_verbose) { - static char *opstr[]= { "set", "add", "replace" }; + 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, - "key: %s\nflags: %x\n expires: %ld\n", - opstr[opt_replace], 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 (opt_replace == 0) - rc= memcached_set(memc, ptr, strlen(ptr), - mptr, sbuf.st_size, - opt_expires, opt_flags); - else if (opt_replace == 1) + if ((file_buffer_ptr= (char *)malloc(sizeof(char) * sbuf.st_size)) == NULL) + { + fprintf(stderr, "malloc: %s\n", strerror(errno)); + exit(1); + } + + if ((read_length= read(fd, file_buffer_ptr, sbuf.st_size)) == -1) + { + fprintf(stderr, "read: %s\n", strerror(errno)); + exit(1); + } + assert(read_length == sbuf.st_size); + + if (opt_method == OPT_ADD) rc= memcached_add(memc, ptr, strlen(ptr), - mptr, sbuf.st_size, + file_buffer_ptr, sbuf.st_size, opt_expires, opt_flags); - else if (opt_replace == 2) + else if (opt_method == OPT_REPLACE) rc= memcached_replace(memc, ptr, strlen(ptr), - mptr, sbuf.st_size, + file_buffer_ptr, sbuf.st_size, opt_expires, opt_flags); else - abort(); + rc= memcached_set(memc, ptr, strlen(ptr), + file_buffer_ptr, sbuf.st_size, + opt_expires, opt_flags); if (rc != MEMCACHED_SUCCESS) - { fprintf(stderr, "memcp: %s: memcache error %s\n", ptr, memcached_strerror(memc, rc)); - } - munmap(mptr, sbuf.st_size); + WATCHPOINT; + free(file_buffer_ptr); close(fd); optind++; } memcached_deinit(memc); - cleanup(); ++ free(opt_servers); + return 0; - }; + } void options_parse(int argc, char *argv[]) { @@@ -145,22 -140,13 +147,22 @@@ printf("useful help messages go here\n"); exit(0); case OPT_SERVERS: /* --servers or -s */ - opt_servers= strdup_cleanup(optarg); - opt_servers= 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; + break; + case OPT_REPLACE: + opt_method= OPT_REPLACE; + break; + case OPT_ADD: + opt_method= OPT_ADD; break; case '?': /* getopt_long already printed an error message. */ diff --cc src/memrm.c index 4a3da021,f49444e8..3e468a3d --- a/src/memrm.c +++ b/src/memrm.c @@@ -3,29 -3,29 +3,65 @@@ #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; - time_t expires= 0; memcached_return rc; - static struct option long_options[] = - 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}, - {"verbose", no_argument, &opt_verbose, 1}, - {"debug", no_argument, &opt_verbose, 2}, -- {"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) @@@ -44,10 -45,10 +81,10 @@@ exit(0); break; case OPT_SERVERS: /* --servers or -s */ - opt_servers = optarg; - opt_servers= optarg; ++ opt_servers= strdup(optarg); break; case OPT_EXPIRE: /* --expire */ - expires = (time_t)strtol(optarg, (char **)NULL, 10); - 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 -57,25 +93,4 @@@ 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 (opt_verbose) - printf("key: %s\nexpires: %ld\n", argv[optind], expires); -- - if (rc != MEMCACHED_SUCCESS) - { - 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 --cc src/utilities.c index ce6cd925,5dd66f62..c866dd54 --- a/src/utilities.c +++ b/src/utilities.c @@@ -1,10 -1,7 +1,7 @@@ #include - static char **cleanup_list= NULL; - static char cleanup_list_length= 0; - void parse_opt_servers(memcached_st *memc, - char *opt_servers) + char *server_strings) { char *string; unsigned int port; @@@ -53,25 -44,4 +50,3 @@@ } } } - - 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; - }