X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Fbin%2Fmemdump.cc;h=7bed49232b8e983101fad4cf031678d5db8c524a;hb=cb19624cb66bad8af6b87acf013f60588ca6c854;hp=8c5690d5d3f27af36b8294c7ba26e1ff445d4d0d;hpb=2e9eb0803f1fc81bfe6c3e2dda0ed2cbe1aa6a76;p=awesomized%2Flibmemcached diff --git a/src/bin/memdump.cc b/src/bin/memdump.cc index 8c5690d5..7bed4923 100644 --- a/src/bin/memdump.cc +++ b/src/bin/memdump.cc @@ -21,6 +21,7 @@ #define PROGRAM_VERSION "1.1" #include "common/options.hpp" +#include "common/checks.hpp" static memcached_return_t print(const memcached_st *, const char *k, size_t l, void *ctx) { auto out = static_cast(ctx); @@ -54,10 +55,7 @@ int main(int argc, char *argv[]) { } memcached_st memc; - if (!memcached_create(&memc)) { - if (!opt.isset("quiet")) { - std::cerr << "Failed to initialize memcached client.\n"; - } + if (!check_memcached(opt, memc)) { exit(EXIT_FAILURE); } @@ -66,23 +64,8 @@ int main(int argc, char *argv[]) { } memcached_dump_fn cb[1] = {&print}; - std::ostream *outstream = &std::cout; std::ofstream outfile{}; - - if (auto filename = opt.argof("file")) { - if (opt.isset("debug")) { - std::cerr << "Opening " << filename << " for output.\n"; - } - outfile.open(filename, std::ios::binary | std::ios::out); - if (!outfile.is_open()) { - if (!opt.isset("quiet")) { - std::cerr << "Failed to open " << filename << " for writing.\n"; - } - memcached_free(&memc); - exit(EXIT_FAILURE); - } - outstream = &outfile; - } + std::ostream *outstream = check_ostream(opt, opt.argof("file"), outfile); auto rc = memcached_dump(&memc, cb, outstream, 1);