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);
50 if ((nptr
== argv
[optind
] and value
== 0) or
51 (value
== ULONG_MAX
and errno
== ERANGE
) or
52 (value
== 0 and errno
== EINVAL
))
54 std::cerr
<< "strtoul() was unable to parse given value" << std::endl
;
58 if (value
< MEMCACHED_MAXIMUM_RETURN
)
60 std::cout
<< memcached_strerror(NULL
, (memcached_return_t
)value
) << std::endl
;
64 std::cerr
<< memcached_strerror(NULL
, MEMCACHED_MAXIMUM_RETURN
) << std::endl
;
75 void options_parse(int argc
, char *argv
[])
77 static struct option long_options
[]=
79 {(OPTIONSTRING
)"version", no_argument
, NULL
, OPT_VERSION
},
80 {(OPTIONSTRING
)"help", no_argument
, NULL
, OPT_HELP
},
84 bool opt_version
= false;
89 int option_rv
= getopt_long(argc
, argv
, "Vhvds:", long_options
, &option_index
);
100 case OPT_VERSION
: /* --version or -V */
104 case OPT_HELP
: /* --help or -h */
109 /* getopt_long already printed an error message. */
119 version_command(PROGRAM_NAME
);
125 help_command(PROGRAM_NAME
, PROGRAM_DESCRIPTION
, long_options
, NULL
);