summaryrefslogtreecommitdiff
blob: 7fb6f7abaa770b4eac597fb0934bb23cbb958586 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* Copyright (C) 2001-2020 Artifex Software, Inc.
   All Rights Reserved.

   This software is provided AS-IS with no warranty, either express or
   implied.

   This software is distributed under license and may not be copied,
   modified or distributed except as expressly authorized under the terms
   of the license contained in the file LICENSE in this distribution.

   Refer to licensing information at http://www.artifex.com or contact
   Artifex Software, Inc.,  1305 Grant Avenue - Suite 200, Novato,
   CA 94945, U.S.A., +1(415)492-9861, for further information.
*/


/* Generic substitute for Unix memory.h */

#ifndef memory__INCLUDED
#  define memory__INCLUDED

/* We must include std.h before any file that includes sys/types.h. */
#include "std.h"

/******
 ****** Note: the System V bcmp routine only returns zero or non-zero,
 ****** unlike memcmp which returns -1, 0, or 1.
 ******/

#define memcmp_inline(b1,b2,len) memcmp(b1,b2,len)

/*
 * Apparently the newer VMS compilers include prototypes
 * for the mem... routines in <string.h>.  Unfortunately,
 * gcc lies on Sun systems: it defines __STDC__ even if
 * the header files in /usr/include are broken.
 * However, Solaris systems, which define __svr4__, do have
 * correct header files.
 */
/*
 * The exceptions vastly outnumber the BSD4_2 "rule":
 * these tests should be the other way around....
 */

#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)
#  include <string.h>
#else
#  if defined(BSD4_2) || defined(UTEK)
extern bcopy(), bcmp(), bzero();

#      define memcpy(dest,src,len) bcopy(src,dest,len)
#      define memcmp(b1,b2,len) bcmp(b1,b2,len)
       /* Define our own versions of missing routines (in gsmisc.c). */
#      define MEMORY__NEED_MEMMOVE
#      include <sys/types.h>  /* for size_t */
#      define MEMORY__NEED_MEMSET
#      if defined(UTEK)
#        define MEMORY__NEED_MEMCHR
#      endif                  /* UTEK */
#  else
#    include <memory.h>
#    if defined(__SVR3) || defined(sun)       /* Not sure this is right.... */
#      define MEMORY__NEED_MEMMOVE
#      include <sys/types.h>  /* for size_t */
#    endif                    /* __SVR3 or sun */
#  endif                      /* BSD4_2 or UTEK */
#endif                        /* VMS, POSIX, ... */

/*
 * If we are profiling, substitute our own versions of memset, memcpy,
 * and memmove, in case profiling libraries aren't available.
 */
#ifdef PROFILE
#  define MEMORY__NEED_MEMCPY
#  define MEMORY__NEED_MEMMOVE
#  define MEMORY__NEED_MEMSET
#endif

/*
 * Declare substitutes for library procedures we supply.  We undef them
 * first, just in case we are substituting for an existing library facility
 * that happens to be implemented as a macro.
 */
#ifdef MEMORY__NEED_MEMMOVE
#  undef memmove
#  define memmove(dest,src,len) gs_memmove(dest,src,len)
void *gs_memmove(void *, const void *, size_t);
#endif
#ifdef MEMORY__NEED_MEMCPY
#  undef memcpy
#  define memcpy(dest,src,len) gs_memcpy(dest,src,len)
void *gs_memcpy(void *, const void *, size_t);
#endif
#ifdef MEMORY__NEED_MEMSET
#  undef memset
#  define memset(dest,ch,len) gs_memset(dest,ch,len)
void *gs_memset(void *, int, size_t);
#endif
#ifdef MEMORY__NEED_MEMCHR
#  undef memchr
#  define memchr(ptr,ch,len) gs_memchr(ptr,ch,len)
void *gs_memchr(const void *, int, size_t);
#endif

#endif /* memory__INCLUDED */