2 * Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/
3 * Copyright (C) 2006-2009 Brian Aker
6 * Use and distribution licensed under the BSD license. See
7 * the COPYING file in the parent directory for full text.
12 #include "mem_config.h"
24 #include <libmemcached-1.0/memcached.h>
26 #include "utilities.h"
28 #define PROGRAM_NAME "memerror"
29 #define PROGRAM_DESCRIPTION "Translate a memcached errror code into a string."
33 void options_parse(int argc
, char *argv
[]);
35 int main(int argc
, char *argv
[])
37 options_parse(argc
, argv
);
48 unsigned long value
= strtoul(argv
[optind
], &nptr
, 10);
51 (nptr
== argv
[optind
] and value
== 0) or
52 (value
== ULONG_MAX
and errno
== ERANGE
) or
53 (value
== 0 and errno
== EINVAL
))
55 std::cerr
<< "strtoul() was unable to parse given value" << std::endl
;
59 if (value
< MEMCACHED_MAXIMUM_RETURN
)
61 std::cout
<< memcached_strerror(NULL
, (memcached_return_t
)value
) << std::endl
;
65 std::cerr
<< memcached_strerror(NULL
, MEMCACHED_MAXIMUM_RETURN
) << std::endl
;
76 void options_parse(int argc
, char *argv
[])
78 static struct option long_options
[]=
80 {(OPTIONSTRING
)"version", no_argument
, NULL
, OPT_VERSION
},
81 {(OPTIONSTRING
)"help", no_argument
, NULL
, OPT_HELP
},
85 bool opt_version
= false;
90 int option_rv
= getopt_long(argc
, argv
, "Vhvds:", long_options
, &option_index
);
101 case OPT_VERSION
: /* --version or -V */
105 case OPT_HELP
: /* --help or -h */
110 /* getopt_long already printed an error message. */
120 version_command(PROGRAM_NAME
);
126 help_command(PROGRAM_NAME
, PROGRAM_DESCRIPTION
, long_options
, NULL
);