1 /* Copyright (C) 2001-2019 Artifex Software, Inc.
2    All Rights Reserved.
3 
4    This software is provided AS-IS with no warranty, either express or
5    implied.
6 
7    This software is distributed under license and may not be copied,
8    modified or distributed except as expressly authorized under the terms
9    of the license contained in the file LICENSE in this distribution.
10 
11    Refer to licensing information at http://www.artifex.com or contact
12    Artifex Software, Inc.,  1305 Grant Avenue - Suite 200, Novato,
13    CA 94945, U.S.A., +1(415)492-9861, for further information.
14 */
15 
16 
17 /* Generic substitute for Unix memory.h */
18 
19 #ifndef memory__INCLUDED
20 #  define memory__INCLUDED
21 
22 /* We must include std.h before any file that includes sys/types.h. */
23 #include "std.h"
24 
25 /******
26  ****** Note: the System V bcmp routine only returns zero or non-zero,
27  ****** unlike memcmp which returns -1, 0, or 1.
28  ******/
29 
30 #ifdef __TURBOC__
31 /* Define inline functions */
32 #  ifdef __WIN32__
33 #    define memcmp_inline(b1,b2,len) memcmp(b1,b2,len)
34 #  else
35 #    define memcmp_inline(b1,b2,len) __memcmp__(b1,b2,len)
36 #  endif
37 #  include <mem.h>
38 #else
39         /* Not Turbo C, no inline functions */
40 #  define memcmp_inline(b1,b2,len) memcmp(b1,b2,len)
41         /*
42          * Apparently the newer VMS compilers include prototypes
43          * for the mem... routines in <string.h>.  Unfortunately,
44          * gcc lies on Sun systems: it defines __STDC__ even if
45          * the header files in /usr/include are broken.
46          * However, Solaris systems, which define __svr4__, do have
47          * correct header files.
48          */
49         /*
50          * The exceptions vastly outnumber the BSD4_2 "rule":
51          * these tests should be the other way around....
52          */
53 #  if defined(VMS) || defined(_POSIX_SOURCE) || (defined(__STDC__) && (!defined(sun) || defined(__svr4__))) || defined(_HPUX_SOURCE) || defined(__WATCOMC__) || defined(THINK_C) || defined(bsdi) || defined(__FreeBSD) || (defined(_MSC_VER) && _MSC_VER >= 1000)
54 #    include <string.h>
55 #  else
56 #    if defined(BSD4_2) || defined(UTEK)
57 extern bcopy(), bcmp(), bzero();
58 
59 #	 define memcpy(dest,src,len) bcopy(src,dest,len)
60 #	 define memcmp(b1,b2,len) bcmp(b1,b2,len)
61          /* Define our own versions of missing routines (in gsmisc.c). */
62 #	 define MEMORY__NEED_MEMMOVE
63 #        include <sys/types.h>	/* for size_t */
64 #	 define MEMORY__NEED_MEMSET
65 #	 if defined(UTEK)
66 #          define MEMORY__NEED_MEMCHR
67 #        endif			/* UTEK */
68 #    else
69 #      include <memory.h>
70 #      if defined(__SVR3) || defined(sun)	/* Not sure this is right.... */
71 #	 define MEMORY__NEED_MEMMOVE
72 #        include <sys/types.h>	/* for size_t */
73 #      endif			/* __SVR3 or sun */
74 #    endif			/* BSD4_2 or UTEK */
75 #  endif			/* VMS, POSIX, ... */
76 #endif /* !__TURBOC__ */
77 
78 /*
79  * If we are profiling, substitute our own versions of memset, memcpy,
80  * and memmove, in case profiling libraries aren't available.
81  */
82 #ifdef PROFILE
83 #  define MEMORY__NEED_MEMCPY
84 #  define MEMORY__NEED_MEMMOVE
85 #  define MEMORY__NEED_MEMSET
86 #endif
87 
88 /*
89  * Declare substitutes for library procedures we supply.  We undef them
90  * first, just in case we are substituting for an existing library facility
91  * that happens to be implemented as a macro.
92  */
93 #ifdef MEMORY__NEED_MEMMOVE
94 #  undef memmove
95 #  define memmove(dest,src,len) gs_memmove(dest,src,len)
96 void *gs_memmove(void *, const void *, size_t);
97 #endif
98 #ifdef MEMORY__NEED_MEMCPY
99 #  undef memcpy
100 #  define memcpy(dest,src,len) gs_memcpy(dest,src,len)
101 void *gs_memcpy(void *, const void *, size_t);
102 #endif
103 #ifdef MEMORY__NEED_MEMSET
104 #  undef memset
105 #  define memset(dest,ch,len) gs_memset(dest,ch,len)
106 void *gs_memset(void *, int, size_t);
107 #endif
108 #ifdef MEMORY__NEED_MEMCHR
109 #  undef memchr
110 #  define memchr(ptr,ch,len) gs_memchr(ptr,ch,len)
111 void *gs_memchr(const void *, int, size_t);
112 #endif
113 
114 #endif /* memory__INCLUDED */
115