3 * These routines are helpers - note that this file gets linked into all the
4 * zip-access variants that refer to <zzip/format.h>. On the x86 platform the
5 * actual definitions will be empty - fetching is done on native machine-level
8 * Guido Draheim <guidod@gmx.de>
10 * Copyright (c) 2004,2005,2006 Guido Draheim
11 * All rights reserved,
12 * use under the restrictions of the
13 * Lesser GNU General Public License
14 * or alternatively the restrictions
15 * of the Mozilla Public License 1.1
18 #include <zzip/fetch.h>
20 /* ------------------------- fetch helpers --------------------------------- */
23 * Make 32 bit value in host byteorder from little-endian mapped octet-data
24 * (works also on machines which SIGBUS on misaligned data access (eg. 68000))
27 __zzip_get32(unsigned char *s
)
29 #if defined __ZZIP_GET32
30 return __ZZIP_GET32(s
);
32 return ((uint32_t) s
[3] << 24) | ((uint32_t) s
[2] << 16)
33 | ((uint32_t) s
[1] << 8) | ((uint32_t) s
[0]);
38 * This function does the same for a 16 bit value.
41 __zzip_get16(unsigned char *s
)
43 #if defined __ZZIP_GET16
44 return __ZZIP_GET16(s
);
46 return ((uint16_t) s
[1] << 8) | ((uint16_t) s
[0]);
51 * This function does the same for an off64_t value.
54 __zzip_get64(unsigned char *s
)
69 return ((uint64_t) s
[7] << 56) | ((uint64_t) s
[6] << 48)
70 | ((uint64_t) s
[5] << 40) | ((uint64_t) s
[4] << 32)
71 | ((uint64_t) s
[3] << 24) | ((uint64_t) s
[2] << 16)
72 | ((uint64_t) s
[1] << 8) | ((uint64_t) s
[0]);
77 * This function pushes a 32bit value at the specified address
80 __zzip_set32(unsigned char *s
, uint32_t v
)
82 #if defined __ZZIP_SET32
83 return __ZZIP_SET32(s
, v
);
86 s
[0] = (unsigned char) (v
); v
>>= 8;
87 s
[1] = (unsigned char) (v
); v
>>= 8;
88 s
[2] = (unsigned char) (v
); v
>>= 8;
89 s
[3] = (unsigned char) (v
);
95 * This function does the same for a 16 bit value.
98 __zzip_set16(unsigned char *s
, uint16_t v
)
100 #if defined __ZZIP_SET16
101 return __ZZIP_SET16(s
, v
);
104 s
[0] = (unsigned char) (v
); v
>>= 8;
105 s
[1] = (unsigned char) (v
);
111 * This function pushes a off64_t value at the specified address
114 __zzip_set64(unsigned char *s
, uint64_t v
)
117 s
[0] = (unsigned char) (v
); v
>>= 8;
118 s
[1] = (unsigned char) (v
); v
>>= 8;
119 s
[2] = (unsigned char) (v
); v
>>= 8;
120 s
[3] = (unsigned char) (v
); v
>>= 8;
121 s
[4] = (unsigned char) (v
); v
>>= 8;
122 s
[5] = (unsigned char) (v
); v
>>= 8;
123 s
[6] = (unsigned char) (v
); v
>>= 8;
124 s
[7] = (unsigned char) (v
);