208e013dd6a0d3b915865fcbea8af7abc25b1f04
2 +--------------------------------------------------------------------+
3 | libmemcached - C/C++ Client Library for memcached |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted under the terms of the BSD license. |
7 | You should have received a copy of the license in a bundled file |
8 | named LICENSE; in case you did not receive a copy you can review |
9 | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
10 +--------------------------------------------------------------------+
11 | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
12 | Copyright (c) 2020 Michael Wallner <mike@php.net> |
13 +--------------------------------------------------------------------+
16 #include "mem_config.h"
18 #define PROGRAM_NAME "memerror"
19 #define PROGRAM_DESCRIPTION "Translate a memcached error code into a string."
20 #define PROGRAM_VERSION "1.1"
22 #include "common/options.hpp"
24 int main(int argc
, char *argv
[]) {
25 client_options opt
{PROGRAM_NAME
, PROGRAM_VERSION
, PROGRAM_DESCRIPTION
, "code [code ...]"};
27 for (const auto &def
: opt
.defaults
) {
28 switch (def
.opt
.val
) {
30 case 'V': // --version
31 case 'v': // --verbose
40 char **argp
= nullptr;
41 if (!opt
.parse(argc
, argv
, &argp
)) {
48 std::cerr
<< "No error codes provided.\n";
52 for (auto arg
= argp
; *arg
; ++arg
) {
53 auto code
= std::stoul(*arg
);
54 auto rc
= static_cast<memcached_return_t
>(code
);
56 if (opt
.isset("verbose")) {
57 std::cout
<< "code: " << code
<< "\n";
58 std::cout
<< "name: " << memcached_strerror(nullptr, rc
) << "\n";
60 std::cout
<< memcached_strerror(nullptr, rc
) << "\n";