From: Brian Aker Date: Tue, 8 Jun 2010 19:05:16 +0000 (-0700) Subject: Merging, with changes, --file for memcat. X-Git-Tag: 0.41~29 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=8cb354e120fb927ca7e601cd56180bd1efb422b9;p=awesomized%2Flibmemcached Merging, with changes, --file for memcat. --- 8cb354e120fb927ca7e601cd56180bd1efb422b9 diff --cc clients/memcat.c index 3ae82e46,a25bc12c..d0a6b38f --- a/clients/memcat.c +++ b/clients/memcat.c @@@ -91,9 -92,35 +92,43 @@@ int main(int argc, char *argv[] else { if (opt_verbose) ++ { printf("key: %s\nflags: %x\nlength: %zu\nvalue: ", argv[optind], flags, string_length); - printf("%.*s\n", (int)string_length, string); - if (opt_file) { - FILE *fp; - size_t written = 0; - - fp = fopen(opt_file, "w"); - if (!fp) { - perror("fopen"); - return_code= -1; - break; - } - - written = fwrite(string, 1, string_length, fp); - if (written != string_length) { - fprintf(stderr, "error writing file (written %d, should be %d)\n", written, string_length); - return_code= -1; - break; - } - - if (fclose(fp)) { - fprintf(stderr, "error closing file\n"); - return_code= -1; - break; - } + } - else { ++ ++ if (opt_file) ++ { ++ FILE *fp; ++ size_t written; ++ ++ fp= fopen(opt_file, "w"); ++ if (!fp) ++ { ++ perror("fopen"); ++ return_code= -1; ++ break; ++ } ++ ++ written= fwrite(string, 1, string_length, fp); ++ if (written != string_length) ++ { ++ fprintf(stderr, "error writing file (written %zu, should be %zu)\n", written, string_length); ++ return_code= -1; ++ break; ++ } ++ ++ if (fclose(fp)) ++ { ++ fprintf(stderr, "error closing file\n"); ++ return_code= -1; ++ break; ++ } ++ } ++ else ++ { + printf("%.*s\n", (int)string_length, string); + } free(string); } } @@@ -102,7 -129,7 +137,9 @@@ fprintf(stderr, "memcat: %s: memcache error %s", argv[optind], memcached_strerror(memc, rc)); if (memc->cached_errno) ++ { fprintf(stderr, " system error %s", strerror(memc->cached_errno)); ++ } fprintf(stderr, "\n"); return_code= -1; diff --cc tests/include.am index be3e3363,be3e3363..b71f0c79 --- a/tests/include.am +++ b/tests/include.am @@@ -112,12 -112,12 +112,14 @@@ memcapable: clients/memcapabl test-memcat: clients/memcat clients/memcp @echo "Testing memcat" @@MEMC_BINARY@ -d -P `pwd`/tests/Xumemc.pid -p 12555 -- @clients/memcp --servers="localhost:12555" clients/memcp -- @clients/memcat --servers="localhost:12555" memcp > tests/scratch ++ @clients/memcp --servers="localhost:12555" `pwd`/clients/memcp ++ @clients/memcat --servers="localhost:12555" memcp > `pwd`/tests/scratch ++ @clients/memcat --servers="localhost:12555" --file=`pwd`/tests/scratch2 memcp # @diff clients/memcp tests/scratch -- @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server" -- @rm tests/Xumemc.pid -- @rm tests/scratch ++ @cat `pwd`/tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server" ++ @rm `pwd`/tests/Xumemc.pid ++ @rm `pwd`/tests/scratch ++ @rm `pwd`/tests/scratch2 valgrind-memcat: clients/memcat clients/memcp @echo "Testing memcat"