Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * jinclude.h |
| 3 | * |
Thomas G. Lane | 4a6b730 | 1992-03-17 00:00:00 +0000 | [diff] [blame^] | 4 | * Copyright (C) 1991, 1992, Thomas G. Lane. |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 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 is the central file that's #include'd by all the JPEG .c files. |
| 9 | * Its purpose is to provide a single place to fix any problems with |
| 10 | * including the wrong system include files. |
| 11 | * You can edit these declarations if you use a system with nonstandard |
| 12 | * system include files. |
| 13 | */ |
| 14 | |
| 15 | |
| 16 | /* |
Thomas G. Lane | bd543f0 | 1991-12-13 00:00:00 +0000 | [diff] [blame] | 17 | * Normally the __STDC__ macro can be taken as indicating that the system |
| 18 | * include files conform to the ANSI C standard. However, if you are running |
| 19 | * GCC on a machine with non-ANSI system include files, that is not the case. |
| 20 | * In that case change the following, or add -DNONANSI_INCLUDES to your CFLAGS. |
| 21 | */ |
| 22 | |
| 23 | #ifdef __STDC__ |
| 24 | #ifndef NONANSI_INCLUDES |
| 25 | #define INCLUDES_ARE_ANSI /* this is what's tested before including */ |
| 26 | #endif |
| 27 | #endif |
| 28 | |
| 29 | /* |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 30 | * <stdio.h> is included to get the FILE typedef and NULL macro. |
| 31 | * Note that the core portable-JPEG files do not actually do any I/O |
| 32 | * using the stdio library; only the user interface, error handler, |
| 33 | * and file reading/writing modules invoke any stdio functions. |
Thomas G. Lane | 4a6b730 | 1992-03-17 00:00:00 +0000 | [diff] [blame^] | 34 | * (Well, we did cheat a bit in jmemmgr.c, but only if MEM_STATS is defined.) |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 35 | */ |
| 36 | |
| 37 | #include <stdio.h> |
| 38 | |
| 39 | /* |
| 40 | * We need the size_t typedef, which defines the parameter type of malloc(). |
| 41 | * In an ANSI-conforming implementation this is provided by <stdio.h>, |
| 42 | * but on non-ANSI systems it's more likely to be in <sys/types.h>. |
Thomas G. Lane | bd543f0 | 1991-12-13 00:00:00 +0000 | [diff] [blame] | 43 | * On some not-quite-ANSI systems you may find it in <stddef.h>. |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 44 | */ |
| 45 | |
Thomas G. Lane | bd543f0 | 1991-12-13 00:00:00 +0000 | [diff] [blame] | 46 | #ifndef INCLUDES_ARE_ANSI /* shouldn't need this if ANSI C */ |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 47 | #include <sys/types.h> |
| 48 | #endif |
Thomas G. Lane | bd543f0 | 1991-12-13 00:00:00 +0000 | [diff] [blame] | 49 | #ifdef __SASC /* Amiga SAS C provides it in stddef.h. */ |
| 50 | #include <stddef.h> |
| 51 | #endif |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 52 | |
| 53 | /* |
| 54 | * In ANSI C, and indeed any rational implementation, size_t is also the |
| 55 | * type returned by sizeof(). However, it seems there are some irrational |
| 56 | * implementations out there, in which sizeof() returns an int even though |
| 57 | * size_t is defined as long or unsigned long. To ensure consistent results |
| 58 | * we always use this SIZEOF() macro in place of using sizeof() directly. |
| 59 | */ |
| 60 | |
Thomas G. Lane | bd543f0 | 1991-12-13 00:00:00 +0000 | [diff] [blame] | 61 | #undef SIZEOF /* in case you included X11/xmd.h */ |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 62 | #define SIZEOF(object) ((size_t) sizeof(object)) |
| 63 | |
| 64 | /* |
Thomas G. Lane | bd543f0 | 1991-12-13 00:00:00 +0000 | [diff] [blame] | 65 | * fread() and fwrite() are always invoked through these macros. |
| 66 | * On some systems you may need to twiddle the argument casts. |
| 67 | * CAUTION: argument order is different from underlying functions! |
| 68 | */ |
| 69 | |
Thomas G. Lane | 4a6b730 | 1992-03-17 00:00:00 +0000 | [diff] [blame^] | 70 | #define JFREAD(file,buf,sizeofbuf) \ |
Thomas G. Lane | bd543f0 | 1991-12-13 00:00:00 +0000 | [diff] [blame] | 71 | ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file))) |
Thomas G. Lane | 4a6b730 | 1992-03-17 00:00:00 +0000 | [diff] [blame^] | 72 | #define JFWRITE(file,buf,sizeofbuf) \ |
Thomas G. Lane | bd543f0 | 1991-12-13 00:00:00 +0000 | [diff] [blame] | 73 | ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file))) |
| 74 | |
| 75 | /* |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 76 | * We need the memcpy() and strcmp() functions, plus memory zeroing. |
| 77 | * ANSI and System V implementations declare these in <string.h>. |
| 78 | * BSD doesn't have the mem() functions, but it does have bcopy()/bzero(). |
| 79 | * NOTE: we assume the size parameters to these functions are of type size_t. |
| 80 | * Insert casts in these macros if not! |
| 81 | */ |
| 82 | |
Thomas G. Lane | bd543f0 | 1991-12-13 00:00:00 +0000 | [diff] [blame] | 83 | #ifdef INCLUDES_ARE_ANSI |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 84 | #include <string.h> |
| 85 | #define MEMZERO(voidptr,size) memset((voidptr), 0, (size)) |
Thomas G. Lane | bd543f0 | 1991-12-13 00:00:00 +0000 | [diff] [blame] | 86 | #else /* not ANSI */ |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 87 | #ifdef BSD |
| 88 | #include <strings.h> |
| 89 | #define MEMZERO(voidptr,size) bzero((voidptr), (size)) |
| 90 | #define memcpy(dest,src,size) bcopy((src), (dest), (size)) |
| 91 | #else /* not BSD, assume Sys V or compatible */ |
| 92 | #include <string.h> |
| 93 | #define MEMZERO(voidptr,size) memset((voidptr), 0, (size)) |
| 94 | #endif /* BSD */ |
Thomas G. Lane | bd543f0 | 1991-12-13 00:00:00 +0000 | [diff] [blame] | 95 | #endif /* ANSI */ |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 96 | |
| 97 | |
| 98 | /* Now include the portable JPEG definition files. */ |
| 99 | |
| 100 | #include "jconfig.h" |
| 101 | |
| 102 | #include "jpegdata.h" |