| 75 | } |
| 76 | |
| 77 | static int compress(char *infile, char *outfile, char *algoname, |
| 78 | int write_header) |
| 79 | { |
| 80 | int err = 1; |
| 81 | FILE *fin = NULL; |
| 82 | FILE *fout = NULL; |
| 83 | void *indata = NULL; |
| 84 | |
| 85 | const struct typedesc_t *algo = &types_cbfs_compression[0]; |
| 86 | while (algo->name != NULL) { |
| 87 | if (strcasecmp(algo->name, algoname) == 0) break; |
| 88 | algo++; |
| 89 | } |
| 90 | if (algo->name == NULL) { |
| 91 | fprintf(stderr, "algo '%s' is not supported.\n", algoname); |
| 92 | return 1; |
| 93 | } |
| 94 | |
| 95 | comp_func_ptr comp = compression_function(algo->type); |
| 96 | if (comp == NULL) { |
| 97 | printf("no handler associated with algorithm\n"); |
| 98 | return 1; |
| 99 | } |
| 100 | |
| 101 | fin = fopen(infile, "rb"); |
| 102 | if (!fin) { |
| 103 | fprintf(stderr, "could not open '%s'\n", infile); |
| 104 | return 1; |
| 105 | } |
| 106 | fout = fopen(outfile, "wb"); |
| 107 | if (!fout) { |
| 108 | fprintf(stderr, "could not open '%s' for writing\n", outfile); |
| 109 | goto out; |
| 110 | } |
| 111 | |
| 112 | if (fseek(fin, 0, SEEK_END) != 0) { |
| 113 | fprintf(stderr, "could not seek in input\n"); |
| 114 | goto out; |
| 115 | } |
| 116 | long insize = ftell(fin); |
| 117 | if (insize < 0) { |
| 118 | fprintf(stderr, "could not determine input size\n"); |
| 119 | goto out; |
| 120 | } |
| 121 | rewind(fin); |
| 122 | |
| 123 | indata = malloc(insize); |
| 124 | if (!indata) { |
| 125 | fprintf(stderr, "out of memory\n"); |
| 126 | goto out; |
| 127 | } |
| 128 | |
| 129 | void *outdata = malloc(insize); |
| 130 | if (!outdata) { |
| 131 | fprintf(stderr, "out of memory\n"); |
| 132 | goto out; |
| 133 | } |
| 134 | int outsize; |
no test coverage detected