X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Fbin%2Fmemdump.cc;h=630c11117cbf9ae2809536965c198c226e521268;hb=18f81009ed414fd399a6ba9c7894fcd89b14ce75;hp=8c5690d5d3f27af36b8294c7ba26e1ff445d4d0d;hpb=2e9eb0803f1fc81bfe6c3e2dda0ed2cbe1aa6a76;p=awesomized%2Flibmemcached diff --git a/src/bin/memdump.cc b/src/bin/memdump.cc index 8c5690d5..630c1111 100644 --- a/src/bin/memdump.cc +++ b/src/bin/memdump.cc @@ -9,7 +9,7 @@ | the terms online at: https://opensource.org/licenses/BSD-3-Clause | +--------------------------------------------------------------------+ | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ | - | Copyright (c) 2020 Michael Wallner | + | Copyright (c) 2020-2021 Michael Wallner https://awesome.co/ | +--------------------------------------------------------------------+ */ @@ -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);