comparison tools/packed.c @ 1031:f7863608d84c

Cleanup, remove debug code.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 01 Mar 2015 16:26:47 +0200
parents c88b879c735c
children f8d75a51de2c
comparison
equal deleted inserted replaced
1030:a76056297006 1031:f7863608d84c
265 265
266 266
267 int dmPackAddFile(DMPackFile * pack, const char *filename, 267 int dmPackAddFile(DMPackFile * pack, const char *filename,
268 const Uint32 flags, const BOOL compress, int level, DMPackEntry ** ppEntry) 268 const Uint32 flags, const BOOL compress, int level, DMPackEntry ** ppEntry)
269 { 269 {
270 z_stream zstr;
271 Uint64 startOffs, outSize; 270 Uint64 startOffs, outSize;
272 FILE *inFile = NULL, *tmpFile;
273 Uint8 *inBuffer = NULL, *outBuffer = NULL; 271 Uint8 *inBuffer = NULL, *outBuffer = NULL;
274 DMPackEntry entry, *node; 272 DMPackEntry entry, *node;
273 FILE *inFile = NULL;
275 int ret = DMERR_OK; 274 int ret = DMERR_OK;
276 BOOL zinit = FALSE; 275 BOOL zinit = FALSE;
276 z_stream zstr;
277 277
278 *ppEntry = NULL; 278 *ppEntry = NULL;
279 279
280 if (pack == NULL) 280 if (pack == NULL)
281 return DMERR_NULLPTR; 281 return DMERR_NULLPTR;
319 ret = DMERR_COMPRESSION; 319 ret = DMERR_COMPRESSION;
320 goto out; 320 goto out;
321 } 321 }
322 zinit = TRUE; 322 zinit = TRUE;
323 323
324 tmpFile = fopen("dump.bin", "wb");
325
326 // Initialize compression streams 324 // Initialize compression streams
327 zret = Z_OK; 325 zret = Z_OK;
328 while (!feof(inFile) && zret == Z_OK) 326 while (!feof(inFile) && zret == Z_OK)
329 { 327 {
330 zstr.avail_in = fread(inBuffer, sizeof(Uint8), SET_TMPBUF_SIZE, inFile); 328 zstr.avail_in = fread(inBuffer, sizeof(Uint8), SET_TMPBUF_SIZE, inFile);
336 zret = deflate(&zstr, Z_FULL_FLUSH); 334 zret = deflate(&zstr, Z_FULL_FLUSH);
337 335
338 if (zret == Z_OK && zstr.total_out > 0) 336 if (zret == Z_OK && zstr.total_out > 0)
339 { 337 {
340 outSize += zstr.total_out; 338 outSize += zstr.total_out;
341 fwrite(outBuffer, sizeof(Uint8), zstr.total_out, tmpFile);
342 if (fwrite(outBuffer, sizeof(Uint8), zstr.total_out, pack->file) != zstr.total_out) 339 if (fwrite(outBuffer, sizeof(Uint8), zstr.total_out, pack->file) != zstr.total_out)
343 { 340 {
344 ret = DMERR_FWRITE; 341 ret = DMERR_FWRITE;
345 goto out; 342 goto out;
346 } 343 }
347 } 344 }
348 } 345 }
349 fclose(tmpFile);
350 } 346 }
351 347
352 // Create directory entry 348 // Create directory entry
353 strncpy(entry.filename, filename, sizeof(entry.filename)); 349 strncpy(entry.filename, filename, sizeof(entry.filename));
354 entry.filename[sizeof(entry.filename) - 1] = 0; 350 entry.filename[sizeof(entry.filename) - 1] = 0;