forked from mfillpot/mathomatic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblt.h
65 lines (56 loc) · 1.63 KB
/
blt.h
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
/*
* blt(), also know as memmove(3), include file for Mathomatic.
*
* Copyright (C) 1987-2012 George Gesslein II.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
The chief copyright holder can be contacted at gesslein@mathomatic.org, or
George Gesslein II, P.O. Box 224, Lansing, NY 14882-0224 USA.
*/
#if 1
#define blt(dest, src, cnt) memmove((dest), (src), (cnt)) /* memory copy function; must allow overlapping of src and dest */
#else
/* If no fast or working memmove(3) routine exists use this one. */
static inline char *
blt(dest, src, cnt)
char *dest;
const char *src;
int cnt;
{
char *tdest;
const char *tsrc;
int tcnt;
if (cnt <= 0) {
if (cnt == 0) {
return dest;
} else {
error_bug("blt() cnt < 0");
}
}
if (src == dest) {
return dest;
}
tdest = dest;
tsrc = src;
tcnt = cnt;
if (tdest > tsrc) {
tdest += tcnt;
tsrc += tcnt;
while (--tcnt >= 0)
*--tdest = *--tsrc;
} else {
while (--tcnt >= 0)
*tdest++ = *tsrc++;
}
return dest;
}
#endif