Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / gnu / usr.bin / ld / xbits.c
1 /*
2  * Copyright (c) 1993 Paul Kranenburg
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by Paul Kranenburg.
16  * 4. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * $FreeBSD: src/gnu/usr.bin/ld/xbits.c,v 1.7 1999/08/27 23:36:03 peter Exp $
31  * $DragonFly: src/gnu/usr.bin/ld/Attic/xbits.c,v 1.2 2003/06/17 04:25:46 dillon Exp $
32  */
33
34 /*
35  * "Generic" byte-swap routines.
36  */
37
38 #include <sys/param.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <sys/types.h>
42 #include <sys/stat.h>
43 #include <sys/file.h>
44 #include <fcntl.h>
45 #include <ar.h>
46 #include <ranlib.h>
47 #include <a.out.h>
48 #include <stab.h>
49 #include <string.h>
50
51 #include "ld.h"
52 #include "dynamic.h"
53
54 void
55 swap_longs(lp, n)
56 int     n;
57 long    *lp;
58 {
59         for (; n > 0; n--, lp++)
60                 *lp = md_swap_long(*lp);
61 }
62
63 void
64 swap_symbols(s, n)
65 struct nlist *s;
66 int n;
67 {
68         for (; n; n--, s++) {
69                 s->n_un.n_strx = md_swap_long(s->n_un.n_strx);
70                 s->n_desc = md_swap_short(s->n_desc);
71                 s->n_value = md_swap_long(s->n_value);
72         }
73 }
74
75 void
76 swap_zsymbols(s, n)
77 struct nzlist *s;
78 int n;
79 {
80         for (; n; n--, s++) {
81                 s->nz_strx = md_swap_long(s->nz_strx);
82                 s->nz_desc = md_swap_short(s->nz_desc);
83                 s->nz_value = md_swap_long(s->nz_value);
84                 s->nz_size = md_swap_long(s->nz_size);
85         }
86 }
87
88
89 void
90 swap_ranlib_hdr(rlp, n)
91 struct ranlib *rlp;
92 int n;
93 {
94         for (; n; n--, rlp++) {
95                 rlp->ran_un.ran_strx = md_swap_long(rlp->ran_un.ran_strx);
96                 rlp->ran_off = md_swap_long(rlp->ran_off);
97         }
98 }
99
100 void
101 swap__dynamic(dp)
102 struct _dynamic *dp;
103 {
104         dp->d_version = md_swap_long(dp->d_version);
105         dp->d_debug = (struct so_debug *)md_swap_long((long)dp->d_debug);
106         dp->d_un.d_sdt = (struct section_dispatch_table *)
107                                 md_swap_long((long)dp->d_un.d_sdt);
108         dp->d_entry = (struct ld_entry *)md_swap_long((long)dp->d_entry);
109 }
110
111 void
112 swap_section_dispatch_table(sdp)
113 struct section_dispatch_table *sdp;
114 {
115         swap_longs((long *)sdp, sizeof(*sdp)/sizeof(long));
116 }
117
118 void
119 swap_so_debug(ddp)
120 struct so_debug *ddp;
121 {
122         swap_longs((long *)ddp, sizeof(*ddp)/sizeof(long));
123 }
124
125 void
126 swapin_sod(sodp, n)
127 struct sod *sodp;
128 int n;
129 {
130         unsigned long   bits;
131
132         for (; n; n--, sodp++) {
133                 sodp->sod_name = md_swap_long(sodp->sod_name);
134                 sodp->sod_major = md_swap_short(sodp->sod_major);
135                 sodp->sod_minor = md_swap_short(sodp->sod_minor);
136                 sodp->sod_next = md_swap_long(sodp->sod_next);
137                 bits = ((unsigned long *)sodp)[1];
138                 sodp->sod_library = ((bits >> 24) & 1);
139         }
140 }
141
142 void
143 swapout_sod(sodp, n)
144 struct sod *sodp;
145 int n;
146 {
147         unsigned long   bits;
148
149         for (; n; n--, sodp++) {
150                 sodp->sod_name = md_swap_long(sodp->sod_name);
151                 sodp->sod_major = md_swap_short(sodp->sod_major);
152                 sodp->sod_minor = md_swap_short(sodp->sod_minor);
153                 sodp->sod_next = md_swap_long(sodp->sod_next);
154                 bits = (unsigned long)(sodp->sod_library) << 24;
155                 ((unsigned long *)sodp)[1] = bits;
156         }
157 }
158
159 void
160 swap_rrs_hash(fsp, n)
161 struct rrs_hash *fsp;
162 int n;
163 {
164         for (; n; n--, fsp++) {
165                 fsp->rh_symbolnum = md_swap_long(fsp->rh_symbolnum);
166                 fsp->rh_next = md_swap_long(fsp->rh_next);
167         }
168 }
169