New Spec file.
[awesomized/libmemcached] / clients / memcp.c
index 780514c1bc56b7bf7daac5878f85cd8449a9af5f..0a7809f8ff1ccc4659f80082734b130548d4fadd 100644 (file)
@@ -1,6 +1,6 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include <stdint.h>
+#include <inttypes.h>
 #include <unistd.h>
 #include <getopt.h>
 #include <sys/types.h>
@@ -10,7 +10,6 @@
 #include <errno.h>
 #include <strings.h>
 #include <string.h>
-#include <assert.h>
 
 #include <libmemcached/memcached.h>
 
@@ -23,6 +22,7 @@
 /* Prototypes */
 void options_parse(int argc, char *argv[]);
 
+static int opt_binary=0;
 static int opt_verbose= 0;
 static char *opt_servers= NULL;
 static char *opt_hash= NULL;
@@ -61,6 +61,7 @@ int main(int argc, char *argv[])
 
   memcached_server_push(memc, servers);
   memcached_server_list_free(servers);
+  memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, opt_binary);
 
   while (optind < argc) 
   {
@@ -106,7 +107,12 @@ int main(int argc, char *argv[])
       fprintf(stderr, "read: %s\n", strerror(errno)); 
       exit(1);
     }
-    assert(read_length == sbuf.st_size);
+
+    if (read_length != sbuf.st_size)
+    {
+      fprintf(stderr, "Failure reading from file\n");
+      exit(1);
+    }
 
     if (opt_method == OPT_ADD)
       rc= memcached_add(memc, ptr, strlen(ptr),
@@ -168,6 +174,7 @@ void options_parse(int argc, char *argv[])
       {"add",  no_argument, NULL, OPT_ADD},
       {"replace",  no_argument, NULL, OPT_REPLACE},
       {"hash", required_argument, NULL, OPT_HASH},
+      {"binary", no_argument, NULL, OPT_BINARY},
       {0, 0, 0, 0},
     };
 
@@ -181,6 +188,9 @@ void options_parse(int argc, char *argv[])
     {
     case 0:
       break;
+    case OPT_BINARY:
+      opt_binary = 1;
+      break;
     case OPT_VERBOSE: /* --verbose or -v */
       opt_verbose = OPT_VERBOSE;
       break;