14a70c29b0ae506132506a93e29a022569702fde
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"
28 #include "libmemcached-1.0/memcached.h"
30 #include "utilities.h"
32 #define PROGRAM_NAME "memerror"
33 #define PROGRAM_DESCRIPTION "Translate a memcached errror code into a string."
36 void options_parse(int argc
, char *argv
[]);
38 int main(int argc
, char *argv
[]) {
39 options_parse(argc
, argv
);
45 while (optind
< argc
) {
48 unsigned long value
= strtoul(argv
[optind
], &nptr
, 10);
50 if ((errno
) or (nptr
== argv
[optind
] and value
== 0)
51 or (value
== ULONG_MAX
and errno
== ERANGE
) or (value
== 0 and errno
== EINVAL
))
53 std::cerr
<< "strtoul() was unable to parse given value" << std::endl
;
57 if (value
< MEMCACHED_MAXIMUM_RETURN
) {
58 std::cout
<< memcached_strerror(NULL
, (memcached_return_t
) value
) << std::endl
;
60 std::cerr
<< memcached_strerror(NULL
, MEMCACHED_MAXIMUM_RETURN
) << std::endl
;
70 void options_parse(int argc
, char *argv
[]) {
71 static struct option long_options
[] = {
72 {(OPTIONSTRING
) "version", no_argument
, NULL
, OPT_VERSION
},
73 {(OPTIONSTRING
) "help", no_argument
, NULL
, OPT_HELP
},
77 bool opt_version
= false;
78 bool opt_help
= false;
81 int option_rv
= getopt_long(argc
, argv
, "Vhvds:", long_options
, &option_index
);
82 if (option_rv
== -1) {
90 case OPT_VERSION
: /* --version or -V */
94 case OPT_HELP
: /* --help or -h */
99 /* getopt_long already printed an error message. */
108 version_command(PROGRAM_NAME
);
113 help_command(PROGRAM_NAME
, PROGRAM_DESCRIPTION
, long_options
, NULL
);