minigzip.c (237691) | minigzip.c (254069) |
---|---|
1/* minigzip.c -- simulate gzip using the zlib compression library 2 * Copyright (C) 1995-2006, 2010, 2011 Jean-loup Gailly. 3 * For conditions of distribution and use, see copyright notice in zlib.h 4 */ 5 6/* 7 * minigzip is a minimal implementation of the gzip utility. This is 8 * only an example of using zlib and isn't meant to replace the --- 26 unchanged lines hidden (view full) --- 35# ifdef UNDER_CE 36# include <stdlib.h> 37# endif 38# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) 39#else 40# define SET_BINARY_MODE(file) 41#endif 42 | 1/* minigzip.c -- simulate gzip using the zlib compression library 2 * Copyright (C) 1995-2006, 2010, 2011 Jean-loup Gailly. 3 * For conditions of distribution and use, see copyright notice in zlib.h 4 */ 5 6/* 7 * minigzip is a minimal implementation of the gzip utility. This is 8 * only an example of using zlib and isn't meant to replace the --- 26 unchanged lines hidden (view full) --- 35# ifdef UNDER_CE 36# include <stdlib.h> 37# endif 38# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) 39#else 40# define SET_BINARY_MODE(file) 41#endif 42 |
43#ifdef _MSC_VER 44# define snprintf _snprintf 45#endif 46 |
|
43#ifdef VMS 44# define unlink delete 45# define GZ_SUFFIX "-gz" 46#endif 47#ifdef RISCOS 48# define unlink remove 49# define GZ_SUFFIX "-gz" 50# define fileno(file) file->__file --- 407 unchanged lines hidden (view full) --- 458 FILE *in; 459 gzFile out; 460 461 if (strlen(file) + strlen(GZ_SUFFIX) >= sizeof(outfile)) { 462 fprintf(stderr, "%s: filename too long\n", prog); 463 exit(1); 464 } 465 | 47#ifdef VMS 48# define unlink delete 49# define GZ_SUFFIX "-gz" 50#endif 51#ifdef RISCOS 52# define unlink remove 53# define GZ_SUFFIX "-gz" 54# define fileno(file) file->__file --- 407 unchanged lines hidden (view full) --- 462 FILE *in; 463 gzFile out; 464 465 if (strlen(file) + strlen(GZ_SUFFIX) >= sizeof(outfile)) { 466 fprintf(stderr, "%s: filename too long\n", prog); 467 exit(1); 468 } 469 |
470#if !defined(NO_snprintf) && !defined(NO_vsnprintf) 471 snprintf(outfile, sizeof(outfile), "%s%s", file, GZ_SUFFIX); 472#else |
|
466 strcpy(outfile, file); 467 strcat(outfile, GZ_SUFFIX); | 473 strcpy(outfile, file); 474 strcat(outfile, GZ_SUFFIX); |
475#endif |
|
468 469 in = fopen(file, "rb"); 470 if (in == NULL) { 471 perror(file); 472 exit(1); 473 } 474 out = gzopen(outfile, mode); 475 if (out == NULL) { --- 18 unchanged lines hidden (view full) --- 494 gzFile in; 495 size_t len = strlen(file); 496 497 if (len + strlen(GZ_SUFFIX) >= sizeof(buf)) { 498 fprintf(stderr, "%s: filename too long\n", prog); 499 exit(1); 500 } 501 | 476 477 in = fopen(file, "rb"); 478 if (in == NULL) { 479 perror(file); 480 exit(1); 481 } 482 out = gzopen(outfile, mode); 483 if (out == NULL) { --- 18 unchanged lines hidden (view full) --- 502 gzFile in; 503 size_t len = strlen(file); 504 505 if (len + strlen(GZ_SUFFIX) >= sizeof(buf)) { 506 fprintf(stderr, "%s: filename too long\n", prog); 507 exit(1); 508 } 509 |
510#if !defined(NO_snprintf) && !defined(NO_vsnprintf) 511 snprintf(buf, sizeof(buf), "%s", file); 512#else |
|
502 strcpy(buf, file); | 513 strcpy(buf, file); |
514#endif |
|
503 504 if (len > SUFFIX_LEN && strcmp(file+len-SUFFIX_LEN, GZ_SUFFIX) == 0) { 505 infile = file; 506 outfile = buf; 507 outfile[len-3] = '\0'; 508 } else { 509 outfile = file; 510 infile = buf; | 515 516 if (len > SUFFIX_LEN && strcmp(file+len-SUFFIX_LEN, GZ_SUFFIX) == 0) { 517 infile = file; 518 outfile = buf; 519 outfile[len-3] = '\0'; 520 } else { 521 outfile = file; 522 infile = buf; |
523#if !defined(NO_snprintf) && !defined(NO_vsnprintf) 524 snprintf(buf + len, sizeof(buf) - len, "%s", GZ_SUFFIX); 525#else |
|
511 strcat(infile, GZ_SUFFIX); | 526 strcat(infile, GZ_SUFFIX); |
527#endif |
|
512 } 513 in = gzopen(infile, "rb"); 514 if (in == NULL) { 515 fprintf(stderr, "%s: can't gzopen %s\n", prog, infile); 516 exit(1); 517 } 518 out = fopen(outfile, "wb"); 519 if (out == NULL) { --- 21 unchanged lines hidden (view full) --- 541 int argc; 542 char *argv[]; 543{ 544 int copyout = 0; 545 int uncompr = 0; 546 gzFile file; 547 char *bname, outmode[20]; 548 | 528 } 529 in = gzopen(infile, "rb"); 530 if (in == NULL) { 531 fprintf(stderr, "%s: can't gzopen %s\n", prog, infile); 532 exit(1); 533 } 534 out = fopen(outfile, "wb"); 535 if (out == NULL) { --- 21 unchanged lines hidden (view full) --- 557 int argc; 558 char *argv[]; 559{ 560 int copyout = 0; 561 int uncompr = 0; 562 gzFile file; 563 char *bname, outmode[20]; 564 |
565#if !defined(NO_snprintf) && !defined(NO_vsnprintf) 566 snprintf(outmode, sizeof(outmode), "%s", "wb6 "); 567#else |
|
549 strcpy(outmode, "wb6 "); | 568 strcpy(outmode, "wb6 "); |
569#endif |
|
550 551 prog = argv[0]; 552 bname = strrchr(argv[0], '/'); 553 if (bname) 554 bname++; 555 else 556 bname = argv[0]; 557 argc--, argv++; --- 74 unchanged lines hidden --- | 570 571 prog = argv[0]; 572 bname = strrchr(argv[0], '/'); 573 if (bname) 574 bname++; 575 else 576 bname = argv[0]; 577 argc--, argv++; --- 74 unchanged lines hidden --- |