beta-0.89.2
[luatex.git] / source / libs / zziplib / zziplib-0.13.62 / zzip / fetch.c
blobbd1958483ff7b4e244222e38cf578da26ba0869d
2 /*
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
7 * Author:
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 --------------------------------- */
22 /**
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))
26 uint32_t
27 __zzip_get32(unsigned char *s)
29 #if defined __ZZIP_GET32
30 return __ZZIP_GET32(s);
31 #else
32 return ((uint32_t) s[3] << 24) | ((uint32_t) s[2] << 16)
33 | ((uint32_t) s[1] << 8) | ((uint32_t) s[0]);
34 #endif
37 /** => __zzip_get32
38 * This function does the same for a 16 bit value.
40 uint16_t
41 __zzip_get16(unsigned char *s)
43 #if defined __ZZIP_GET16
44 return __ZZIP_GET16(s);
45 #else
46 return ((uint16_t) s[1] << 8) | ((uint16_t) s[0]);
47 #endif
50 /** => __zzip_get32
51 * This function does the same for an off64_t value.
53 uint64_t
54 __zzip_get64(unsigned char *s)
56 #ifdef __GNUC__
57 /* *INDENT-OFF* */
58 register uint64_t v
59 = s[7]; v <<= 8;
60 v |= s[6]; v <<= 8;
61 v |= s[5]; v <<= 8;
62 v |= s[4]; v <<= 8;
63 v |= s[3]; v <<= 8;
64 v |= s[2]; v <<= 8;
65 v |= s[1]; v <<= 8;
66 v |= s[0]; return v;
67 /* *INDENT-ON* */
68 #else
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]);
73 #endif
76 /** => __zzip_get32
77 * This function pushes a 32bit value at the specified address
79 void
80 __zzip_set32(unsigned char *s, uint32_t v)
82 #if defined __ZZIP_SET32
83 return __ZZIP_SET32(s, v);
84 #else
85 /* *INDENT-OFF* */
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);
90 /* *INDENT-ON* */
91 #endif
94 /** => __zzip_get32
95 * This function does the same for a 16 bit value.
97 void
98 __zzip_set16(unsigned char *s, uint16_t v)
100 #if defined __ZZIP_SET16
101 return __ZZIP_SET16(s, v);
102 #else
103 /* *INDENT-OFF* */
104 s[0] = (unsigned char) (v); v >>= 8;
105 s[1] = (unsigned char) (v);
106 /* *INDENT-ON* */
107 #endif
110 /** => __zzip_get32
111 * This function pushes a off64_t value at the specified address
113 void
114 __zzip_set64(unsigned char *s, uint64_t v)
116 /* *INDENT-OFF* */
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);
125 /* *INDENT-ON* */