jinclude.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * jinclude.h
  3. *
  4. * Copyright (C) 1991-1994, Thomas G. Lane.
  5. * This file is part of the Independent JPEG Group's software.
  6. * For conditions of distribution and use, see the accompanying README file.
  7. *
  8. * This file exists to provide a single place to fix any problems with
  9. * including the wrong system include files. (Common problems are taken
  10. * care of by the standard jconfig symbols, but on really weird systems
  11. * you may have to edit this file.)
  12. *
  13. * NOTE: this file is NOT intended to be included by applications using the
  14. * JPEG library. Most applications need only include jpeglib.h.
  15. */
  16. /* Include auto-config file to find out which system include files we need. */
  17. #include "jconfig.h" /* auto configuration options */
  18. #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
  19. /*
  20. * We need the NULL macro and size_t typedef.
  21. * On an ANSI-conforming system it is sufficient to include <stddef.h>.
  22. * Otherwise, we get them from <stdlib.h> or <stdio.h>; we may have to
  23. * pull in <sys/types.h> as well.
  24. * Note that the core JPEG library does not require <stdio.h>;
  25. * only the default error handler and data source/destination modules do.
  26. * But we must pull it in because of the references to FILE in jpeglib.h.
  27. * You can remove those references if you want to compile without <stdio.h>.
  28. */
  29. #ifdef HAVE_STDDEF_H
  30. #include <stddef.h>
  31. #endif
  32. #ifdef HAVE_STDLIB_H
  33. #include <stdlib.h>
  34. #endif
  35. #ifdef NEED_SYS_TYPES_H
  36. #include <sys/types.h>
  37. #endif
  38. #include <stdio.h>
  39. /*
  40. * We need memory copying and zeroing functions, plus strncpy().
  41. * ANSI and System V implementations declare these in <string.h>.
  42. * BSD doesn't have the mem() functions, but it does have bcopy()/bzero().
  43. * Some systems may declare memset and memcpy in <memory.h>.
  44. *
  45. * NOTE: we assume the size parameters to these functions are of type size_t.
  46. * Change the casts in these macros if not!
  47. */
  48. #ifdef NEED_BSD_STRINGS
  49. #include <strings.h>
  50. #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
  51. #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
  52. #else /* not BSD, assume ANSI/SysV string lib */
  53. #include <string.h>
  54. #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
  55. #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
  56. #endif
  57. /*
  58. * In ANSI C, and indeed any rational implementation, size_t is also the
  59. * type returned by sizeof(). However, it seems there are some irrational
  60. * implementations out there, in which sizeof() returns an int even though
  61. * size_t is defined as long or unsigned long. To ensure consistent results
  62. * we always use this SIZEOF() macro in place of using sizeof() directly.
  63. */
  64. #define SIZEOF(object) ((size_t) sizeof(object))
  65. /*
  66. * The modules that use fread() and fwrite() always invoke them through
  67. * these macros. On some systems you may need to twiddle the argument casts.
  68. * CAUTION: argument order is different from underlying functions!
  69. */
  70. #define JFREAD(file,buf,sizeofbuf) \
  71. ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  72. #define JFWRITE(file,buf,sizeofbuf) \
  73. ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))