Updating test case such that we output version information and correctly set
[m6w6/libmemcached] / clients / memcat.c
index a25bc12c9f5c6f3fa60d6ad96a0b59c524b005bc..5c7a512f2763e9b2214c610f8be841e83d5b731c 100644 (file)
@@ -9,7 +9,8 @@
  *
  */
 
-#include "libmemcached/common.h"
+#include "config.h"
+
 #include <stdio.h>
 #include <inttypes.h>
 #include <string.h>
@@ -47,6 +48,7 @@ int main(int argc, char *argv[])
   int return_code= 0;
 
   options_parse(argc, argv);
+  initialize_sockets();
 
   if (!opt_servers)
   {
@@ -92,33 +94,41 @@ int main(int argc, char *argv[])
       else
       {
         if (opt_verbose)
+        {
           printf("key: %s\nflags: %x\nlength: %zu\nvalue: ",
                  argv[optind], flags, string_length);
-        if (opt_file) {
-            FILE *fp;
-            size_t written = 0;
-
-            fp = fopen(opt_file, "w");
-            if (!fp) {
-                perror("fopen");
-                return_code= -1;
-                break;
-            }
-
-            written = fwrite(string, 1, string_length, fp);
-            if (written != string_length) {
-                fprintf(stderr, "error writing file (written %d, should be %d)\n", written, string_length);
-                return_code= -1;
-                break;
-            }
-
-            if (fclose(fp)) {
-                fprintf(stderr, "error closing file\n");
-                return_code= -1;
-                break;
-            }
         }
-        else {
+
+        if (opt_file)
+        {
+          FILE *fp;
+          size_t written;
+
+          fp= fopen(opt_file, "w");
+          if (!fp)
+          {
+            perror("fopen");
+            return_code= -1;
+            break;
+          }
+
+          written= fwrite(string, 1, string_length, fp);
+          if (written != string_length) 
+          {
+            fprintf(stderr, "error writing file (written %zu, should be %zu)\n", written, string_length);
+            return_code= -1;
+            break;
+          }
+
+          if (fclose(fp))
+          {
+            fprintf(stderr, "error closing file\n");
+            return_code= -1;
+            break;
+          }
+        }
+        else
+        {
             printf("%.*s\n", (int)string_length, string);
         }
         free(string);
@@ -129,7 +139,9 @@ int main(int argc, char *argv[])
       fprintf(stderr, "memcat: %s: memcache error %s",
               argv[optind], memcached_strerror(memc, rc));
       if (memc->cached_errno)
+      {
        fprintf(stderr, " system error %s", strerror(memc->cached_errno));
+      }
       fprintf(stderr, "\n");
 
       return_code= -1;