OSDN Git Service

Warning fixes:
[pf3gnuchains/gcc-fork.git] / libchill / memmove.c
1 /* Implement string-related runtime actions for CHILL.
2    Copyright (C) 1992,1993 Free Software Foundation, Inc.
3    Author: Bill Cox
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
20
21 /* As a special exception, if you link this library with other files,
22    some of which are compiled with GCC, to produce an executable,
23    this library does not by itself cause the resulting executable
24    to be covered by the GNU General Public License.
25    This exception does not however invalidate any other reasons why
26    the executable file might be covered by the GNU General Public License.  */
27
28 #define MIN(a, b)  ((a) < (b) ? (a) : (b))
29
30
31 /*
32  * function memmove
33  *
34  * parameters:
35  *     S1 - pointer to destination string
36  *     S2 - pointer to source string
37  *     LEN - length of string
38  *
39  * returns:
40  *     pointer to destination string
41  *
42  * exceptions:
43  *     none
44  *
45  * abstract:
46  *     copies a string safely, where the source and dest areas may overlap.
47  *
48  */
49
50 void *
51 memmove (s1, s2, n)
52      void *s1;
53      const void *s2;
54      int n;
55 {
56   char *sc1 = s1;
57   const char *sc2 = s2;
58
59   if (sc2 < sc1 && (sc1 < sc2 + n))
60     for (sc1 += n, sc2 += n; 0 < n; --n)
61       *--sc1 = *--sc2;
62   else
63 #if 0
64     for (; 0 < n; --n)
65       *sc1++ = *sc2++;
66 #else
67     memcpy (sc1, sc2, n);
68 #endif
69   return s1;
70 }