2 * Copyright (C) 2006-2009 Brian Aker
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
23 #include <libmemcached/memcached.h>
25 #include "utilities.h"
27 #define PROGRAM_NAME "memerror"
28 #define PROGRAM_DESCRIPTION "Translate a memcached errror code into a string."
32 void options_parse(int argc
, char *argv
[]);
34 int main(int argc
, char *argv
[])
36 options_parse(argc
, argv
);
47 unsigned long value
= strtoul(argv
[optind
], &nptr
, 10);
49 if ((nptr
== argv
[optind
] and value
== 0) or
50 (value
== ULONG_MAX
and errno
== ERANGE
) or
51 (value
== 0 and errno
== EINVAL
))
53 std::cerr
<< "strtoul() was unable to parse given value" << std::endl
;
57 if (value
< MEMCACHED_MAXIMUM_RETURN
)
59 std::cout
<< memcached_strerror(NULL
, (memcached_return_t
)value
) << std::endl
;
63 std::cerr
<< memcached_strerror(NULL
, MEMCACHED_MAXIMUM_RETURN
) << std::endl
;
74 void options_parse(int argc
, char *argv
[])
76 static struct option long_options
[]=
78 {(OPTIONSTRING
)"version", no_argument
, NULL
, OPT_VERSION
},
79 {(OPTIONSTRING
)"help", no_argument
, NULL
, OPT_HELP
},
83 bool opt_version
= false;
88 int option_rv
= getopt_long(argc
, argv
, "Vhvds:", long_options
, &option_index
);
99 case OPT_VERSION
: /* --version or -V */
103 case OPT_HELP
: /* --help or -h */
108 /* getopt_long already printed an error message. */
118 version_command(PROGRAM_NAME
);
124 help_command(PROGRAM_NAME
, PROGRAM_DESCRIPTION
, long_options
, NULL
);