1 /* @(#)isonum.c	1.9 10/12/19 Copyright 2006-2010 J. Schilling */
2 #include <schily/mconfig.h>
3 #ifndef lint
4 static	UConst char sccsid[] =
5 	"@(#)isonum.c	1.9 10/12/19 Copyright 2006-2010 J. Schilling";
6 #endif
7 /*
8  *	Copyright (c) 2006-2010 J. Schilling
9  */
10 /*
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License version 2
13  * as published by the Free Software Foundation.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License along with
21  * this program; see the file COPYING.  If not, write to the Free Software
22  * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23  */
24 
25 #include "mkisofs.h"
26 
27 
28 EXPORT	void	set_721		__PR((void *vp, UInt32_t i));
29 EXPORT	void	set_722		__PR((void *vp, UInt32_t i));
30 EXPORT	void	set_723		__PR((void *vp, UInt32_t i));
31 EXPORT	void	set_731		__PR((void *vp, UInt32_t i));
32 EXPORT	void	set_732		__PR((void *vp, UInt32_t i));
33 EXPORT	void	set_733		__PR((void *vp, UInt32_t i));
34 EXPORT	UInt32_t get_711	__PR((void *vp));
35 EXPORT	UInt32_t get_721	__PR((void *vp));
36 EXPORT	UInt32_t get_723	__PR((void *vp));
37 EXPORT	UInt32_t get_731	__PR((void *vp));
38 EXPORT	UInt32_t get_732	__PR((void *vp));
39 EXPORT	UInt32_t get_733	__PR((void *vp));
40 
41 /*
42  * ISO-9660 7.2.1
43  * Set 16 bit unsigned int, store Least significant byte first
44  */
45 EXPORT void
set_721(vp,i)46 set_721(vp, i)
47 	void		*vp;
48 	UInt32_t	i;
49 {
50 	Uchar	*p = vp;
51 
52 	p[0] = i & 0xff;
53 	p[1] = (i >> 8) & 0xff;
54 }
55 
56 /*
57  * ISO-9660 7.2.2
58  * Set 16 bit unsigned int, store Most significant byte first
59  */
60 EXPORT void
set_722(vp,i)61 set_722(vp, i)
62 	void		*vp;
63 	UInt32_t	i;
64 {
65 	Uchar	*p = vp;
66 
67 	p[0] = (i >> 8) & 0xff;
68 	p[1] = i & 0xff;
69 }
70 
71 /*
72  * ISO-9660 7.2.3
73  * Set 16 bit unsigned int, store Both Byte orders
74  */
75 EXPORT void
set_723(vp,i)76 set_723(vp, i)
77 	void		*vp;
78 	UInt32_t	i;
79 {
80 	Uchar	*p = vp;
81 
82 	p[3] = p[0] = i & 0xff;
83 	p[2] = p[1] = (i >> 8) & 0xff;
84 }
85 
86 /*
87  * ISO-9660 7.3.1
88  * Set 32 bit unsigned int, store Least significant byte first
89  */
90 EXPORT void
set_731(vp,i)91 set_731(vp, i)
92 	void		*vp;
93 	UInt32_t	i;
94 {
95 	Uchar	*p = vp;
96 
97 	p[0] = i & 0xff;
98 	p[1] = (i >> 8) & 0xff;
99 	p[2] = (i >> 16) & 0xff;
100 	p[3] = (i >> 24) & 0xff;
101 }
102 
103 /*
104  * ISO-9660 7.3.2
105  * Set 32 bit unsigned int, store Most significant byte first
106  */
107 EXPORT void
set_732(vp,i)108 set_732(vp, i)
109 	void		*vp;
110 	UInt32_t	i;
111 {
112 	Uchar	*p = vp;
113 
114 	p[3] = i & 0xff;
115 	p[2] = (i >> 8) & 0xff;
116 	p[1] = (i >> 16) & 0xff;
117 	p[0] = (i >> 24) & 0xff;
118 }
119 
120 /*
121  * ISO-9660 7.3.3
122  * Set 32 bit unsigned int, store Both Byte orders
123  */
124 EXPORT void
set_733(vp,i)125 set_733(vp, i)
126 	void		*vp;
127 	UInt32_t	i;
128 {
129 	Uchar	*p = vp;
130 
131 	p[7] = p[0] = i & 0xff;
132 	p[6] = p[1] = (i >> 8) & 0xff;
133 	p[5] = p[2] = (i >> 16) & 0xff;
134 	p[4] = p[3] = (i >> 24) & 0xff;
135 }
136 
137 /*
138  * ISO-9660 7.1.1
139  * Get 8 bit unsigned int
140  */
141 EXPORT UInt32_t
get_711(vp)142 get_711(vp)
143 	void	*vp;
144 {
145 	Uchar	*p = vp;
146 
147 	return (*p & 0xff);
148 }
149 
150 /*
151  * ISO-9660 7.2.1
152  * Get 16 bit unsigned int, stored with Least significant byte first
153  */
154 EXPORT UInt32_t
get_721(vp)155 get_721(vp)
156 	void	*vp;
157 {
158 	Uchar	*p = vp;
159 
160 	return ((p[0] & 0xff) | ((p[1] & 0xff) << 8));
161 }
162 
163 
164 /*
165  * ISO-9660 7.2.3
166  * Get 16 bit unsigned int, stored with Both Byte orders
167  */
168 EXPORT UInt32_t
get_723(vp)169 get_723(vp)
170 	void	*vp;
171 {
172 	Uchar	*p = vp;
173 #if 0
174 	if (p[0] != p[3] || p[1] != p[2]) {
175 		comerrno(EX_BAD, _("Invalid format 7.2.3 number\n"));
176 	}
177 #endif
178 	return (get_721(p));
179 }
180 
181 
182 /*
183  * ISO-9660 7.3.1
184  * Get 32 bit unsigned int, stored with Least significant byte first
185  */
186 EXPORT UInt32_t
get_731(vp)187 get_731(vp)
188 	void	*vp;
189 {
190 	Uchar	*p = vp;
191 
192 	return ((p[0] & 0xff)
193 		| ((p[1] & 0xff) << 8)
194 		| ((p[2] & 0xff) << 16)
195 		| ((p[3] & 0xff) << 24));
196 }
197 
198 /*
199  * ISO-9660 7.3.2
200  * Get 32 bit unsigned int, stored with Most significant byte first
201  */
202 EXPORT UInt32_t
get_732(vp)203 get_732(vp)
204 	void	*vp;
205 {
206 	Uchar	*p = vp;
207 
208 	return ((p[3] & 0xff)
209 		| ((p[2] & 0xff) << 8)
210 		| ((p[1] & 0xff) << 16)
211 		| ((p[0] & 0xff) << 24));
212 }
213 
214 /*
215  * ISO-9660 7.3.3
216  * Get 32 bit unsigned int, stored with Both Byte orders
217  */
218 EXPORT UInt32_t
get_733(vp)219 get_733(vp)
220 	void	*vp;
221 {
222 	Uchar	*p = vp;
223 
224 	return ((p[0] & 0xff)
225 		| ((p[1] & 0xff) << 8)
226 		| ((p[2] & 0xff) << 16)
227 		| ((p[3] & 0xff) << 24));
228 }
229