File indexing completed on 2025-01-19 03:55:51
0001 /* 0002 * jinclude.h 0003 * 0004 * SPDX-FileCopyrightText: 1991-1994, Thomas G. Lane. 0005 * This file is part of the Independent JPEG Group's software. 0006 * For conditions of distribution and use, see the accompanying README file. 0007 * 0008 * This file exists to provide a single place to fix any problems with 0009 * including the wrong system include files. (Common problems are taken 0010 * care of by the standard jconfig symbols, but on really weird systems 0011 * you may have to edit this file.) 0012 * 0013 * NOTE: this file is NOT intended to be included by applications using the 0014 * JPEG library. Most applications need only include jpeglib.h. 0015 */ 0016 0017 0018 /* Include auto-config file to find out which system include files we need. */ 0019 0020 #include "jconfig.h" /* auto configuration options */ 0021 #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */ 0022 0023 /* 0024 * We need the NULL macro and size_t typedef. 0025 * On an ANSI-conforming system it is sufficient to include <stddef.h>. 0026 * Otherwise, we get them from <stdlib.h> or <stdio.h>; we may have to 0027 * pull in <sys/types.h> as well. 0028 * Note that the core JPEG library does not require <stdio.h>; 0029 * only the default error handler and data source/destination modules do. 0030 * But we must pull it in because of the references to FILE in jpeglib.h. 0031 * You can remove those references if you want to compile without <stdio.h>. 0032 */ 0033 0034 #ifdef HAVE_STDDEF_H 0035 #include <stddef.h> 0036 #endif 0037 0038 #ifdef HAVE_STDLIB_H 0039 #include <stdlib.h> 0040 #endif 0041 0042 #ifdef NEED_SYS_TYPES_H 0043 #include <sys/types.h> 0044 #endif 0045 0046 #include <stdio.h> 0047 0048 /* 0049 * We need memory copying and zeroing functions, plus strncpy(). 0050 * ANSI and System V implementations declare these in <string.h>. 0051 * BSD doesn't have the mem() functions, but it does have bcopy()/bzero(). 0052 * Some systems may declare memset and memcpy in <memory.h>. 0053 * 0054 * NOTE: we assume the size parameters to these functions are of type size_t. 0055 * Change the casts in these macros if not! 0056 */ 0057 0058 #ifdef NEED_BSD_STRINGS 0059 0060 #include <strings.h> 0061 #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size)) 0062 #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size)) 0063 0064 #else /* not BSD, assume ANSI/SysV string lib */ 0065 0066 #include <string.h> 0067 #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size)) 0068 #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size)) 0069 0070 #endif 0071 0072 /* 0073 * In ANSI C, and indeed any rational implementation, size_t is also the 0074 * type returned by sizeof(). However, it seems there are some irrational 0075 * implementations out there, in which sizeof() returns an int even though 0076 * size_t is defined as long or unsigned long. To ensure consistent results 0077 * we always use this SIZEOF() macro in place of using sizeof() directly. 0078 */ 0079 0080 #define SIZEOF(object) ((size_t) sizeof(object)) 0081 0082 /* 0083 * The modules that use fread() and fwrite() always invoke them through 0084 * these macros. On some systems you may need to twiddle the argument casts. 0085 * CAUTION: argument order is different from underlying functions! 0086 */ 0087 0088 #define JFREAD(file,buf,sizeofbuf) \ 0089 ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file))) 0090 #define JFWRITE(file,buf,sizeofbuf) \ 0091 ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))