zutil.c 1.7 KB

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