MCPcopy Create free account
hub / github.com/coreboot/coreboot / compress

Function compress

util/cbfstool/cbfscomptool.c:77–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75}
76
77static 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;

Callers 7

parse_elf_to_payloadFunction · 0.85
parse_fv_to_payloadFunction · 0.85
mainFunction · 0.85
do_processFunction · 0.85
cbfstool_convert_rawFunction · 0.85
LZ4F_compressBlockFunction · 0.85

Calls 12

strcasecmpFunction · 0.85
fprintfFunction · 0.85
compression_functionFunction · 0.85
printfFunction · 0.85
fopenFunction · 0.85
fseekFunction · 0.85
ftellFunction · 0.85
freadFunction · 0.85
fwriteFunction · 0.85
fcloseFunction · 0.85
mallocFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected