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"
23 #include "common/checks.hpp"
25 int main(int argc
, char *argv
[]) {
26 client_options opt
{PROGRAM_NAME
, PROGRAM_VERSION
, PROGRAM_DESCRIPTION
, "code [code ...]"};
28 for (const auto &def
: opt
.defaults
) {
29 switch (def
.opt
.val
) {
31 case 'V': // --version
32 case 'v': // --verbose
42 char **argp
= nullptr;
43 if (!opt
.parse(argc
, argv
, &argp
)) {
47 if (!opt
.apply(nullptr)) {
51 if (!check_argp(opt
, argp
, "No error code(s) provided.")) {
55 auto exit_code
= EXIT_SUCCESS
;
56 for (auto arg
= argp
; *arg
; ++arg
) {
57 auto code
= std::stoul(*arg
);
58 auto rc
= static_cast<memcached_return_t
>(code
);
60 if (opt
.isset("verbose")) {
61 std::cout
<< "code: " << code
<< "\n";
62 std::cout
<< "name: ";
64 if (rc
>= MEMCACHED_MAXIMUM_RETURN
) {
65 exit_code
= EXIT_FAILURE
;
66 std::cerr
<< memcached_strerror(nullptr, rc
) << std::endl
;
68 std::cout
<< memcached_strerror(nullptr, rc
) << std::endl
;