zutil.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* zutil.c -- target dependent utility functions for the compression library
  2. * Copyright (C) 1995-2005 Jean-loup Gailly.
  3. * For conditions of distribution and use, see copyright notice in zlib.h
  4. */
  5. /* @(#) $Id$ */
  6. #include "zutil.h"
  7. #ifndef NO_DUMMY_DECL
  8. struct internal_state {int dummy;}; /* for buggy compilers */
  9. #endif
  10. const char * const z_errmsg[10] = {
  11. "need dictionary", /* Z_NEED_DICT 2 */
  12. "stream end", /* Z_STREAM_END 1 */
  13. "", /* Z_OK 0 */
  14. "file error", /* Z_ERRNO (-1) */
  15. "stream error", /* Z_STREAM_ERROR (-2) */
  16. "data error", /* Z_DATA_ERROR (-3) */
  17. "insufficient memory", /* Z_MEM_ERROR (-4) */
  18. "buffer error", /* Z_BUF_ERROR (-5) */
  19. "incompatible version",/* Z_VERSION_ERROR (-6) */
  20. ""};
  21. #ifdef DEBUG
  22. #ifndef verbose
  23. #define verbose 0
  24. #endif
  25. int z_verbose = verbose;
  26. void z_error (m)
  27. char *m;
  28. {
  29. fprintf(stderr, "%s\n", m);
  30. hang ();
  31. }
  32. #endif
  33. /* exported to allow conversion of error code to string for compress() and
  34. * uncompress()
  35. */
  36. #ifndef MY_ZCALLOC /* Any system without a special alloc function */
  37. #ifndef STDC
  38. extern voidp malloc OF((uInt size));
  39. extern voidp calloc OF((uInt items, uInt size));
  40. extern void free OF((voidpf ptr));
  41. #endif
  42. voidpf zcalloc (opaque, items, size)
  43. voidpf opaque;
  44. unsigned items;
  45. unsigned size;
  46. {
  47. if (opaque)
  48. items += size - size; /* make compiler happy */
  49. return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
  50. (voidpf)calloc(items, size);
  51. }
  52. void zcfree (opaque, ptr, nb)
  53. voidpf opaque;
  54. voidpf ptr;
  55. unsigned nb;
  56. {
  57. free(ptr);
  58. if (opaque)
  59. return; /* make compiler happy */
  60. }
  61. #endif /* MY_ZCALLOC */