1 | /* Copyright (C) 1998 Free Software Foundation, Inc.
|
---|
2 |
|
---|
3 | This program is free software; you can redistribute it and/or modify it
|
---|
4 | under the terms of the GNU General Public License as published by the
|
---|
5 | Free Software Foundation; either version 2, or (at your option) any
|
---|
6 | later version.
|
---|
7 |
|
---|
8 | This program is distributed in the hope that it will be useful,
|
---|
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
11 | GNU General Public License for more details.
|
---|
12 |
|
---|
13 | You should have received a copy of the GNU General Public License
|
---|
14 | along with this program; if not, write to the Free Software
|
---|
15 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
---|
16 | USA. */
|
---|
17 |
|
---|
18 | /* Last ditch effort to support memmove: if user doesn't have
|
---|
19 | memmove or bcopy, we offer this sluggish implementation. */
|
---|
20 |
|
---|
21 | #include "config.h"
|
---|
22 | #ifndef HAVE_MEMMOVE
|
---|
23 |
|
---|
24 | #include <sys/types.h>
|
---|
25 | #ifdef HAVE_MEMORY_H
|
---|
26 | # include <memory.h>
|
---|
27 | #endif
|
---|
28 |
|
---|
29 | #ifndef VOID
|
---|
30 | # define VOID void
|
---|
31 | #endif
|
---|
32 |
|
---|
33 | VOID *
|
---|
34 | memmove(dest, src, len)
|
---|
35 | VOID *dest;
|
---|
36 | const VOID *src;
|
---|
37 | size_t len;
|
---|
38 | {
|
---|
39 | #ifdef HAVE_BCOPY
|
---|
40 | bcopy(src, dest, len);
|
---|
41 |
|
---|
42 | #else /*!HAVE_BCOPY*/
|
---|
43 | char *dp = dest;
|
---|
44 | const char *sp = src;
|
---|
45 |
|
---|
46 | # ifdef HAVE_MEMCPY
|
---|
47 | /* A special-case for non-overlapping regions, on the assumption
|
---|
48 | that there is some hope that the sytem's memcpy() implementaion
|
---|
49 | is better than our dumb fall-back one. */
|
---|
50 | if ((dp < sp && dp+len < sp) || (sp < dp && sp+len < dp))
|
---|
51 | return memcpy(dest, src, len);
|
---|
52 | # endif
|
---|
53 |
|
---|
54 | /* I tried real hard to avoid getting to this point.
|
---|
55 | You *really* ought to upgrade your system's libraries;
|
---|
56 | the performance of this implementation sucks. */
|
---|
57 | if (dp < sp)
|
---|
58 | {
|
---|
59 | while (len-- > 0)
|
---|
60 | *dp++ = *sp++;
|
---|
61 | }
|
---|
62 | else
|
---|
63 | {
|
---|
64 | if (dp == sp)
|
---|
65 | return dest;
|
---|
66 | dp += len;
|
---|
67 | sp += len;
|
---|
68 | while (len-- > 0)
|
---|
69 | *--dp = *--sp;
|
---|
70 | }
|
---|
71 | #endif /*!HAVE_BCOPY*/
|
---|
72 |
|
---|
73 | return dest;
|
---|
74 | }
|
---|
75 |
|
---|
76 | #endif /*!HAVE_MEMMOVE*/
|
---|