jinclude.h 3.4 KB

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