update dev300-m58
[ooovba.git] / dmake / dbug / malloc / memory.c
blobab63cf52ba86d6b52ff46537dd722b2010ce45d4
1 /*
2 * (c) Copyright 1990 Conor P. Cahill (uunet!virtech!cpcahil).
3 * You may copy, distribute, and use this software as long as this
4 * copyright statement is not removed.
5 */
7 #ifndef lint
8 static
9 char rcs_hdr[] = "$Id: memory.c,v 1.2 2006-07-25 10:09:19 rt Exp $";
10 #endif
12 void malloc_check_data();
14 char *
15 memccpy(ptr1, ptr2, ch, len)
16 register char * ptr1;
17 register char * ptr2;
18 int len;
19 int ch;
21 int check;
22 register int i;
23 char * rtn;
26 * I know that the assignment could be done in the following, but
27 * I wanted to perform a check before any assignment, so first I
28 * determine the length, check the pointers and then do the assignment.
30 for( i=0; (i < len) && (ptr2[i] != ch); i++)
33 if( ptr2[i] == ch )
35 check = i+1;
37 else
39 check = len;
42 malloc_check_data("memccpy", ptr1, check);
43 malloc_check_data("memccpy", ptr2, check);
46 * if we found the character...
49 if( i < len )
51 rtn = ptr1+i+1;
52 i++;
54 else
56 rtn = (char *) 0;
59 while( i-- )
61 *(ptr1++) = *(ptr2++);
64 return(rtn);
67 char *
68 memchr(ptr1,ch,len)
69 register char * ptr1;
70 register int ch;
71 int len;
73 int i;
75 for( i=0; (i < len) && (ptr1[i] != (char) ch); i++)
79 malloc_check_data("memchr", ptr1, i);
81 if( i < len )
83 return( ptr1+i );
85 else
87 return( (char *) 0);
91 char *
92 memcpy(ptr1, ptr2, len)
93 register char * ptr1;
94 register char * ptr2;
95 register int len;
97 char * rtn = ptr1;
99 malloc_check_data("memcpy", ptr1, len);
100 malloc_check_data("memcpy", ptr2, len);
103 * while the normal memcpy does not guarrantee that it will
104 * handle overlapping memory correctly, we will try...
106 if( ptr1 > ptr2 && ptr1 < (ptr2+len))
108 ptr1 += (len-1);
109 ptr2 += (len-1);
110 while( len-- > 0 )
112 *(ptr1--) = *(ptr2--);
115 else
117 while( len-- > 0 )
119 *(ptr1++) = *(ptr2++);
123 return(rtn);
127 memcmp(ptr1, ptr2, len)
128 register char * ptr1;
129 register char * ptr2;
130 register int len;
132 malloc_check_data("memcpy", ptr1, len);
133 malloc_check_data("memcpy", ptr2, len);
135 while( --len >= 0 && (*ptr1 == *ptr2) )
137 ptr1++;
138 ptr2++;
142 * If stopped by len, return zero
144 if( len < 0 )
146 return(0);
149 return( *ptr1 - *ptr2 );
152 char *
153 memset(ptr1, ch, len)
154 register char * ptr1;
155 register int ch;
156 register int len;
158 char * rtn = ptr1;
160 malloc_check_data("memcpy", ptr1, len);
162 while( len-- )
164 *(ptr1++) = ch;
167 return(rtn);
170 char *
171 bcopy(ptr2,ptr1,len)
172 char * ptr2;
173 char * ptr1;
174 int len;
176 return(memcpy(ptr1,ptr2,len));
179 char *
180 bzero(ptr1,len)
181 char * ptr1;
182 int len;
184 return(memset(ptr1,'\0',len));
188 bcmp(ptr2, ptr1, len)
189 char * ptr1;
190 char * ptr2;
191 int len;
193 return( memcmp(ptr1,ptr2,len) );