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