/*
+--------------------------------------------------------------------+
- | libmemcached - C/C++ Client Library for memcached |
+ | libmemcached-awesome - C/C++ Client Library for memcached |
+--------------------------------------------------------------------+
| Redistribution and use in source and binary forms, with or without |
| modification, are permitted under the terms of the BSD license. |
| 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 <mike@php.net> |
+ | Copyright (c) 2020-2021 Michael Wallner https://awesome.co/ |
+--------------------------------------------------------------------+
*/
#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<std::ostream *>(ctx);
}
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);
}
}
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);