]>
Commit | Line | Data |
---|---|---|
fecd2382 | 1 | /* bignum_copy.c - copy a bignum |
01170860 | 2 | Copyright (C) 1987, 1990, 1991, 1992 Free Software Foundation, Inc. |
6efd877d | 3 | |
a39116f1 | 4 | This file is part of GAS, the GNU Assembler. |
6efd877d | 5 | |
a39116f1 RP |
6 | GAS is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2, or (at your option) | |
9 | any later version. | |
6efd877d | 10 | |
a39116f1 RP |
11 | GAS is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
6efd877d | 15 | |
a39116f1 RP |
16 | You should have received a copy of the GNU General Public License |
17 | along with GAS; see the file COPYING. If not, write to | |
3340f7e5 | 18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ |
fecd2382 | 19 | |
fecd2382 RP |
20 | #include "as.h" |
21 | ||
fecd2382 RP |
22 | /* |
23 | * bignum_copy () | |
24 | * | |
25 | * Copy a bignum from in to out. | |
26 | * If the output is shorter than the input, copy lower-order littlenums. | |
27 | * Return 0 or the number of significant littlenums dropped. | |
28 | * Assumes littlenum arrays are densely packed: no unused chars between | |
542e1629 | 29 | * the littlenums. Uses memcpy() to move littlenums, and wants to |
fecd2382 RP |
30 | * know length (in chars) of the input bignum. |
31 | */ | |
32 | ||
33 | /* void */ | |
34 | int | |
6efd877d KR |
35 | bignum_copy (in, in_length, out, out_length) |
36 | register LITTLENUM_TYPE *in; | |
37 | register int in_length; /* in sizeof(littlenum)s */ | |
38 | register LITTLENUM_TYPE *out; | |
39 | register int out_length; /* in sizeof(littlenum)s */ | |
fecd2382 | 40 | { |
6efd877d KR |
41 | int significant_littlenums_dropped; |
42 | ||
43 | if (out_length < in_length) | |
44 | { | |
45 | LITTLENUM_TYPE *p; /* -> most significant (non-zero) input | |
46 | littlenum. */ | |
3340f7e5 | 47 | |
6efd877d | 48 | memcpy ((void *) out, (void *) in, |
a938b1d6 | 49 | (unsigned int) out_length << LITTLENUM_SHIFT); |
6efd877d KR |
50 | for (p = in + in_length - 1; p >= in; --p) |
51 | { | |
52 | if (*p) | |
53 | break; | |
54 | } | |
55 | significant_littlenums_dropped = p - in - in_length + 1; | |
56 | ||
57 | if (significant_littlenums_dropped < 0) | |
58 | { | |
59 | significant_littlenums_dropped = 0; | |
60 | } | |
61 | } | |
62 | else | |
63 | { | |
64 | memcpy ((char *) out, (char *) in, | |
a938b1d6 | 65 | (unsigned int) in_length << LITTLENUM_SHIFT); |
3340f7e5 | 66 | |
6efd877d KR |
67 | if (out_length > in_length) |
68 | { | |
4b0dd31c | 69 | memset ((char *) (out + in_length), |
a938b1d6 ILT |
70 | '\0', |
71 | (unsigned int) (out_length - in_length) << LITTLENUM_SHIFT); | |
3340f7e5 | 72 | } |
6efd877d KR |
73 | |
74 | significant_littlenums_dropped = 0; | |
75 | } | |
76 | ||
77 | return (significant_littlenums_dropped); | |
78 | } /* bignum_copy() */ | |
fecd2382 | 79 | |
a39116f1 | 80 | /* end of bignum-copy.c */ |