annotate Python/memmove.c @ 13267:4ce255495da3 legacy-trunk

Jack Jansen, Mac patch: If we have stat.h include it if we don't have sys/stat.h
author Guido van Rossum <guido@python.org>
date Sat, 01 Jul 2000 01:08:11 +0000
parents 87ee82e5c56d
children f79434ee41fa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1449
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /***********************************************************
13255
916fb024ce94 Change copyright notice.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
2 Copyright (c) 2000, BeOpen.com.
916fb024ce94 Change copyright notice.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
3 Copyright (c) 1995-2000, Corporation for National Research Initiatives.
916fb024ce94 Change copyright notice.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
4 Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
916fb024ce94 Change copyright notice.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
5 All rights reserved.
1449
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
13255
916fb024ce94 Change copyright notice.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
7 See the file "Misc/COPYRIGHT" for information on usage and
916fb024ce94 Change copyright notice.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
8 redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
1449
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 ******************************************************************/
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
10
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 /* A perhaps slow but I hope correct implementation of memmove */
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
12
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 extern char *memcpy();
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 char *
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 memmove(dst, src, n)
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 char *dst;
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 char *src;
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 int n;
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 {
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 char *realdst = dst;
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 if (n <= 0)
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 return dst;
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 if (src >= dst+n || dst >= src+n)
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 return memcpy(dst, src, n);
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 if (src > dst) {
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 while (--n >= 0)
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 *dst++ = *src++;
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 }
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 else if (src < dst) {
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 src += n;
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 dst += n;
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 while (--n >= 0)
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 *--dst = *--src;
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 }
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 return realdst;
ae93ec4dd556 New files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 }