Rev 193 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 193 | Rev 259 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /* |
1 | /* |
2 | This file is part of a common library |
2 | This file is part of a common library |
3 | Copyright (C) 2002-6 Toby Thain, toby@telegraphics.com.au |
3 | Copyright (C) 2002-6 Toby Thain, toby@telegraphics.com.au |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify |
5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by |
6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or |
7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, |
10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. |
13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License |
15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software |
16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | */ |
18 | */ |
19 | 19 | ||
20 | /* BigEndian and LittleEndian file I/O for long words, short words, and bytes */ |
20 | /* BigEndian and LittleEndian file I/O for long words, short words, and bytes */ |
21 | 21 | ||
22 | #include "file_io.h" |
22 | #include "file_io.h" |
23 | 23 | ||
24 | OSErr read4B(FILEREF f,long *v){ |
24 | OSErr read4B(FILEREF f,long *v){ |
25 | unsigned char p[4]; |
25 | unsigned char p[4]; |
26 | FILECOUNT count = 4; |
26 | FILECOUNT count = 4; |
27 | OSErr e = FSRead(f,&count,p); |
27 | OSErr e = FSRead(f,&count,p); |
28 | if( !e ) |
28 | if( !e ) |
29 | *v = ((long)p[0]<<24) | ((long)p[1]<<16) | ((long)p[2]<<8) | (long)p[3]; |
29 | *v = ((long)p[0]<<24) | ((long)p[1]<<16) | ((long)p[2]<<8) | (long)p[3]; |
30 | return e; |
30 | return e; |
31 | } |
31 | } |
32 | 32 | ||
33 | OSErr read2B(FILEREF f,short *v){ |
33 | OSErr read2B(FILEREF f,short *v){ |
34 | unsigned char p[2]; |
34 | unsigned char p[2]; |
35 | FILECOUNT count = 2; |
35 | FILECOUNT count = 2; |
36 | OSErr e = FSRead(f,&count,p); |
36 | OSErr e = FSRead(f,&count,p); |
37 | if( !e ) |
37 | if( !e ) |
38 | *v = (p[0]<<8) | p[1]; |
38 | *v = (p[0]<<8) | p[1]; |
39 | return e; |
39 | return e; |
40 | } |
40 | } |
41 | 41 | ||
42 | OSErr read4L(FILEREF f,long *v){ |
42 | OSErr read4L(FILEREF f,long *v){ |
43 | unsigned char p[4]; |
43 | unsigned char p[4]; |
44 | FILECOUNT count = 4; |
44 | FILECOUNT count = 4; |
45 | OSErr e = FSRead(f,&count,p); |
45 | OSErr e = FSRead(f,&count,p); |
46 | if( !e ) |
46 | if( !e ) |
47 | *v = ((long)p[3]<<24) | ((long)p[2]<<16) | ((long)p[1]<<8) | (long)p[0]; |
47 | *v = ((long)p[3]<<24) | ((long)p[2]<<16) | ((long)p[1]<<8) | (long)p[0]; |
48 | return e; |
48 | return e; |
49 | } |
49 | } |
50 | 50 | ||
51 | OSErr read2L(FILEREF f,short *v){ |
51 | OSErr read2L(FILEREF f,short *v){ |
52 | unsigned char p[2]; |
52 | unsigned char p[2]; |
53 | FILECOUNT count = 2; |
53 | FILECOUNT count = 2; |
54 | OSErr e = FSRead(f,&count,p); |
54 | OSErr e = FSRead(f,&count,p); |
55 | if( !e ) |
55 | if( !e ) |
56 | *v = (p[1]<<8) | p[0]; |
56 | *v = (p[1]<<8) | p[0]; |
57 | return e; |
57 | return e; |
58 | } |
58 | } |
59 | 59 | ||
60 | OSErr read1(FILEREF f,unsigned char *v){ |
60 | OSErr read1(FILEREF f,unsigned char *v){ |
61 | FILECOUNT count = 1; |
61 | FILECOUNT count = 1; |
62 | return FSRead(f,&count,v); |
62 | return FSRead(f,&count,v); |
63 | } |
63 | } |
64 | 64 | ||
65 | OSErr write4B(FILEREF f,long v){ |
65 | OSErr write4B(FILEREF f,long v){ |
66 | unsigned char p[4]; |
66 | unsigned char p[4]; |
67 | FILECOUNT count = 4; |
67 | FILECOUNT count = 4; |
68 | p[3] = v; |
68 | p[3] = v; |
69 | p[2] = v>>8; |
69 | p[2] = v>>8; |
70 | p[1] = v>>16; |
70 | p[1] = v>>16; |
71 | p[0] = v>>24; |
71 | p[0] = v>>24; |
72 | return FSWrite(f,&count,p); |
72 | return FSWrite(f,&count,p); |
73 | } |
73 | } |
74 | 74 | ||
75 | OSErr write2B(FILEREF f,short v){ |
75 | OSErr write2B(FILEREF f,short v){ |
76 | unsigned char p[2]; |
76 | unsigned char p[2]; |
77 | FILECOUNT count = 2; |
77 | FILECOUNT count = 2; |
78 | p[1] = v; |
78 | p[1] = v; |
79 | p[0] = v>>8; |
79 | p[0] = v>>8; |
80 | return FSWrite(f,&count,p); |
80 | return FSWrite(f,&count,p); |
81 | } |
81 | } |
82 | 82 | ||
83 | OSErr write4L(FILEREF f,long v){ |
83 | OSErr write4L(FILEREF f,long v){ |
84 | unsigned char p[4]; |
84 | unsigned char p[4]; |
85 | FILECOUNT count = 4; |
85 | FILECOUNT count = 4; |
86 | p[0] = v; |
86 | p[0] = v; |
87 | p[1] = v>>8; |
87 | p[1] = v>>8; |
88 | p[2] = v>>16; |
88 | p[2] = v>>16; |
89 | p[3] = v>>24; |
89 | p[3] = v>>24; |
90 | return FSWrite(f,&count,p); |
90 | return FSWrite(f,&count,p); |
91 | } |
91 | } |
92 | 92 | ||
93 | OSErr write2L(FILEREF f,short v){ |
93 | OSErr write2L(FILEREF f,short v){ |
94 | unsigned char p[2]; |
94 | unsigned char p[2]; |
95 | FILECOUNT count = 2; |
95 | FILECOUNT count = 2; |
96 | p[0] = v; |
96 | p[0] = v; |
97 | p[1] = v>>8; |
97 | p[1] = v>>8; |
98 | return FSWrite(f,&count,p); |
98 | return FSWrite(f,&count,p); |
99 | } |
99 | } |
100 | 100 | ||
101 | OSErr write1(FILEREF f,unsigned char v){ |
101 | OSErr write1(FILEREF f,unsigned char v){ |
102 | FILECOUNT count = 1; |
102 | FILECOUNT count = 1; |
103 | return FSWrite(f,&count,&v); |
103 | return FSWrite(f,&count,&v); |
104 | } |
104 | } |
105 | 105 |