xref: /aosp_15_r20/external/mtools/read_dword.h (revision d5c9a868b113e0ec0db2f27bc2ce8a253e77c4b0)
1*d5c9a868SElliott Hughes #ifndef READ_DWORD
2*d5c9a868SElliott Hughes #define READ_DWORD
3*d5c9a868SElliott Hughes 
4*d5c9a868SElliott Hughes /*  Copyright 2007,2009 Alain Knaff.
5*d5c9a868SElliott Hughes  *  This file is part of mtools.
6*d5c9a868SElliott Hughes  *
7*d5c9a868SElliott Hughes  *  Mtools is free software: you can redistribute it and/or modify
8*d5c9a868SElliott Hughes  *  it under the terms of the GNU General Public License as published by
9*d5c9a868SElliott Hughes  *  the Free Software Foundation, either version 3 of the License, or
10*d5c9a868SElliott Hughes  *  (at your option) any later version.
11*d5c9a868SElliott Hughes  *
12*d5c9a868SElliott Hughes  *  Mtools is distributed in the hope that it will be useful,
13*d5c9a868SElliott Hughes  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14*d5c9a868SElliott Hughes  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*d5c9a868SElliott Hughes  *  GNU General Public License for more details.
16*d5c9a868SElliott Hughes  *
17*d5c9a868SElliott Hughes  *  You should have received a copy of the GNU General Public License
18*d5c9a868SElliott Hughes  *  along with Mtools.  If not, see <http://www.gnu.org/licenses/>.
19*d5c9a868SElliott Hughes  */
20*d5c9a868SElliott Hughes 
read_dword(int handle)21*d5c9a868SElliott Hughes static Dword read_dword(int handle)
22*d5c9a868SElliott Hughes {
23*d5c9a868SElliott Hughes 	Byte val[4];
24*d5c9a868SElliott Hughes 
25*d5c9a868SElliott Hughes 	if(read(handle, (char *)val, 4) < 4)
26*d5c9a868SElliott Hughes 		return (Dword) -1;
27*d5c9a868SElliott Hughes 
28*d5c9a868SElliott Hughes 	return byte2dword(val);
29*d5c9a868SElliott Hughes }
30*d5c9a868SElliott Hughes 
UNUSED(static int32_t read_sdword (int handle))31*d5c9a868SElliott Hughes UNUSED(static int32_t read_sdword(int handle))
32*d5c9a868SElliott Hughes {
33*d5c9a868SElliott Hughes 	Byte val[4];
34*d5c9a868SElliott Hughes 
35*d5c9a868SElliott Hughes 	if(read(handle, (char *)val, 4) < 4)
36*d5c9a868SElliott Hughes 		return (int32_t) -1;
37*d5c9a868SElliott Hughes 
38*d5c9a868SElliott Hughes 	return byte2sdword(val);
39*d5c9a868SElliott Hughes }
40*d5c9a868SElliott Hughes 
41*d5c9a868SElliott Hughes 
42*d5c9a868SElliott Hughes struct SQwordRet { int64_t v; int err; };
UNUSED(static struct SQwordRet read_sqword (int handle))43*d5c9a868SElliott Hughes UNUSED(static struct SQwordRet read_sqword(int handle) )
44*d5c9a868SElliott Hughes {
45*d5c9a868SElliott Hughes 	Byte val[8];
46*d5c9a868SElliott Hughes 	struct SQwordRet ret;
47*d5c9a868SElliott Hughes 
48*d5c9a868SElliott Hughes 	if(read(handle, (char *)val, 8) < 8) {
49*d5c9a868SElliott Hughes 		ret.err=-1;
50*d5c9a868SElliott Hughes 	} else {
51*d5c9a868SElliott Hughes 		ret.v = (int64_t) byte2qword(val);
52*d5c9a868SElliott Hughes 		ret.err = 0;
53*d5c9a868SElliott Hughes 	}
54*d5c9a868SElliott Hughes 	return ret;
55*d5c9a868SElliott Hughes }
56*d5c9a868SElliott Hughes 
57*d5c9a868SElliott Hughes #endif
58