zutil.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #ifdef __UBOOT__
  38. #include <malloc.h>
  39. #else
  40. #ifndef STDC
  41. extern voidp malloc OF((uInt size));
  42. extern voidp calloc OF((uInt items, uInt size));
  43. extern void free OF((voidpf ptr));
  44. #endif
  45. #endif
  46. voidpf zcalloc(voidpf opaque, unsigned items, unsigned size)
  47. {
  48. if (opaque)
  49. items += size - size; /* make compiler happy */
  50. return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
  51. (voidpf)calloc(items, size);
  52. }
  53. void zcfree(voidpf opaque, voidpf ptr, unsigned nb)
  54. {
  55. free(ptr);
  56. if (opaque)
  57. return; /* make compiler happy */
  58. }
  59. #endif /* MY_ZCALLOC */