Merging, with changes, --file for memcat.
authorBrian Aker <brian@gaz>
Tue, 8 Jun 2010 19:05:16 +0000 (12:05 -0700)
committerBrian Aker <brian@gaz>
Tue, 8 Jun 2010 19:05:16 +0000 (12:05 -0700)
1  2 
clients/memcat.c
tests/include.am

index 3ae82e460188ef0ef76a20369db04af2aa408f83,a25bc12c9f5c6f3fa60d6ad96a0b59c524b005bc..d0a6b38faf769e8e2a3c87b11d7c0a524f850555
@@@ -91,9 -92,35 +92,43 @@@ int main(int argc, char *argv[]
        else
        {
          if (opt_verbose)
++        {
            printf("key: %s\nflags: %x\nlength: %zu\nvalue: ",
                   argv[optind], flags, string_length);
-         printf("%.*s\n", (int)string_length, string);
 -        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);
        }
      }
        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;
index be3e336399882c497585d8764cf486401710f9af,be3e336399882c497585d8764cf486401710f9af..b71f0c79ed83f9cba3064dc32136d3f9e6ae0798
@@@ -112,12 -112,12 +112,14 @@@ memcapable: clients/memcapabl
  test-memcat: clients/memcat clients/memcp
        @echo "Testing memcat"
        @@MEMC_BINARY@ -d -P `pwd`/tests/Xumemc.pid -p 12555
--      @clients/memcp --servers="localhost:12555" clients/memcp
--      @clients/memcat --servers="localhost:12555" memcp > tests/scratch
++      @clients/memcp --servers="localhost:12555" `pwd`/clients/memcp
++      @clients/memcat --servers="localhost:12555" memcp > `pwd`/tests/scratch
++      @clients/memcat --servers="localhost:12555" --file=`pwd`/tests/scratch2 memcp
  #     @diff clients/memcp tests/scratch
--      @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server"
--      @rm tests/Xumemc.pid
--      @rm tests/scratch
++      @cat `pwd`/tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server"
++      @rm `pwd`/tests/Xumemc.pid
++      @rm `pwd`/tests/scratch
++      @rm `pwd`/tests/scratch2
  
  valgrind-memcat: clients/memcat clients/memcp
        @echo "Testing memcat"