Guest User

Untitled

a guest
Feb 16th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include "zlib.h"
  2. #include <stdio.h>
  3.  
  4. #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
  5. # include <fcntl.h>
  6. # include <io.h>
  7. # ifdef UNDER_CE
  8. # include <stdlib.h>
  9. # endif
  10. # define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
  11. #else
  12. # define SET_BINARY_MODE(file)
  13. #endif
  14.  
  15. static char *prog;
  16.  
  17. static void error(const char *msg);
  18. static void gz_compress(const char *in, gzFile out);
  19. int main(int argc, char *argv[]);
  20.  
  21. static void error(msg)
  22. const char *msg;
  23. {
  24. fprintf(stderr, "%s: %s\n", prog, msg);
  25. exit(1);
  26. }
  27.  
  28. static void gz_compress(in, out)
  29. const char *in;
  30. gzFile out;
  31. {
  32. int len = strlen(in);
  33. int err;
  34. if(gzwrite(out, in, (unsigned) len) != len) error(gzerror(out, &err));
  35. }
  36.  
  37. int main(argc, argv)
  38. int argc;
  39. char *argv[];
  40. {
  41. gzFile outfile;
  42. char outmode[] = "wb1";
  43.  
  44. prog = argv[0];
  45.  
  46. outfile = gzdopen(fileno(stdout), outmode);
  47. SET_BINARY_MODE(stdout);
  48. gz_compress("Hello ", outfile);
  49. gz_compress("World!", outfile);
  50. if(gzclose(outfile) != Z_OK) error("failed gzclose");
  51. }
Add Comment
Please, Sign In to add comment