~ubuntu-branches/ubuntu/precise/libmtp/precise-proposed

« back to all changes in this revision

Viewing changes to m4/byteorder.m4

  • Committer: Bazaar Package Importer
  • Author(s): Savvas Radevic
  • Date: 2009-04-18 19:58:14 UTC
  • mto: (16.1.2 squeeze) (0.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20090418195814-o6h16rbqdbvlrw8s
Tags: upstream-0.3.7
ImportĀ upstreamĀ versionĀ 0.3.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
215
215
/* Define aliases for the standard byte swapping macros */
216
216
/* Arguments to these macros must be properly aligned on natural word */
217
217
/* boundaries in order to work properly on all architectures */
218
 
#define htobe16(x) htons(x)
219
 
#define htobe32(x) htonl(x)
220
 
#define be16toh(x) ntohs(x)
221
 
#define be32toh(x) ntohl(x)
 
218
#ifndef htobe16
 
219
# define htobe16(x) htons(x)
 
220
#endif
 
221
#ifndef htobe32
 
222
# define htobe32(x) htonl(x)
 
223
#endif
 
224
#ifndef be16toh
 
225
# define be16toh(x) ntohs(x)
 
226
#endif
 
227
#ifndef be32toh
 
228
# define be32toh(x) ntohl(x)
 
229
#endif
222
230
 
223
231
#define HTOBE16(x) (x) = htobe16(x)
224
232
#define HTOBE32(x) (x) = htobe32(x)
230
238
 if test $ac_cv_c_bigendian = yes; then
231
239
  cat >> "$1" << EOF
232
240
/* Define our own extended byte swapping macros for big-endian machines */
233
 
#define htole16(x)      swap16(x)
234
 
#define htole32(x)      swap32(x)
235
 
#define le16toh(x)      swap16(x)
236
 
#define le32toh(x)      swap32(x)
237
 
#define le64toh(x)      swap64(x)
 
241
#ifndef htole16
 
242
# define htole16(x)      swap16(x)
 
243
#endif
 
244
#ifndef htole32
 
245
# define htole32(x)      swap32(x)
 
246
#endif
 
247
#ifndef le16toh
 
248
# define le16toh(x)      swap16(x)
 
249
#endif
 
250
#ifndef le32toh
 
251
# define le32toh(x)      swap32(x)
 
252
#endif
 
253
#ifndef le64toh
 
254
# define le64toh(x)      swap64(x)
 
255
#endif
238
256
 
239
 
#define htobe64(x)      (x)
240
 
#define be64toh(x)      (x)
 
257
#ifndef htobe64
 
258
# define htobe64(x)      (x)
 
259
#endif
 
260
#ifndef be64toh
 
261
# define be64toh(x)      (x)
 
262
#endif
241
263
 
242
264
#define HTOLE16(x)      (x) = htole16(x)
243
265
#define HTOLE32(x)      (x) = htole32(x)
252
274
 else
253
275
  cat >> "$1" << EOF
254
276
/* On little endian machines, these macros are null */
255
 
#define htole16(x)      (x)
256
 
#define htole32(x)      (x)
257
 
#define htole64(x)      (x)
258
 
#define le16toh(x)      (x)
259
 
#define le32toh(x)      (x)
260
 
#define le64toh(x)      (x)
 
277
#ifndef htole16
 
278
# define htole16(x)      (x)
 
279
#endif
 
280
#ifndef htole32
 
281
# define htole32(x)      (x)
 
282
#endif
 
283
#ifndef htole64
 
284
# define htole64(x)      (x)
 
285
#endif
 
286
#ifndef le16toh
 
287
# define le16toh(x)      (x)
 
288
#endif
 
289
#ifndef le32toh
 
290
# define le32toh(x)      (x)
 
291
#endif
 
292
#ifndef le64toh
 
293
# define le64toh(x)      (x)
 
294
#endif
261
295
 
262
296
#define HTOLE16(x)      (void) (x)
263
297
#define HTOLE32(x)      (void) (x)
267
301
#define LE64TOH(x)      (void) (x)
268
302
 
269
303
/* These don't have standard aliases */
270
 
#define htobe64(x)      swap64(x)
271
 
#define be64toh(x)      swap64(x)
 
304
#ifndef htobe64
 
305
# define htobe64(x)      swap64(x)
 
306
#endif
 
307
#ifndef be64toh
 
308
# define be64toh(x)      swap64(x)
 
309
#endif
272
310
 
273
311
#define HTOBE64(x)      (x) = htobe64(x)
274
312
#define BE64TOH(x)      (x) = be64toh(x)
279
317
 
280
318
cat >> "$1" << EOF
281
319
/* Define the C99 standard length-specific integer types */
282
 
#include "libptp-stdint.h"
 
320
#include <_stdint.h>
283
321
 
284
322
EOF
285
323
 
294
332
 
295
333
/* The i386 and compatibles can handle unaligned memory access, */
296
334
/* so use the optimized macros above to do this job */
297
 
#define be16atoh(x)     be16toh(*(uint16_t*)(x))
298
 
#define be32atoh(x)     be32toh(*(uint32_t*)(x))
299
 
#define be64atoh(x)     be64toh(*(uint64_t*)(x))
300
 
#define le16atoh(x)     le16toh(*(uint16_t*)(x))
301
 
#define le32atoh(x)     le32toh(*(uint32_t*)(x))
302
 
#define le64atoh(x)     le64toh(*(uint64_t*)(x))
 
335
#ifndef be16atoh
 
336
# define be16atoh(x)     be16toh(*(uint16_t*)(x))
 
337
#endif
 
338
#ifndef be32atoh
 
339
# define be32atoh(x)     be32toh(*(uint32_t*)(x))
 
340
#endif
 
341
#ifndef be64atoh
 
342
# define be64atoh(x)     be64toh(*(uint64_t*)(x))
 
343
#endif
 
344
#ifndef le16atoh
 
345
# define le16atoh(x)     le16toh(*(uint16_t*)(x))
 
346
#endif
 
347
#ifndef le32atoh
 
348
# define le32atoh(x)     le32toh(*(uint32_t*)(x))
 
349
#endif
 
350
#ifndef le64atoh
 
351
# define le64atoh(x)     le64toh(*(uint64_t*)(x))
 
352
#endif
303
353
 
304
 
#define htobe16a(a,x)   *(uint16_t*)(a) = htobe16(x)
305
 
#define htobe32a(a,x)   *(uint32_t*)(a) = htobe32(x)
306
 
#define htobe64a(a,x)   *(uint64_t*)(a) = htobe64(x)
307
 
#define htole16a(a,x)   *(uint16_t*)(a) = htole16(x)
308
 
#define htole32a(a,x)   *(uint32_t*)(a) = htole32(x)
309
 
#define htole64a(a,x)   *(uint64_t*)(a) = htole64(x)
 
354
#ifndef htob16a
 
355
# define htobe16a(a,x)   *(uint16_t*)(a) = htobe16(x)
 
356
#endif
 
357
#ifndef htobe32a
 
358
# define htobe32a(a,x)   *(uint32_t*)(a) = htobe32(x)
 
359
#endif
 
360
#ifndef htobe64a
 
361
# define htobe64a(a,x)   *(uint64_t*)(a) = htobe64(x)
 
362
#endif
 
363
#ifndef htole16a
 
364
# define htole16a(a,x)   *(uint16_t*)(a) = htole16(x)
 
365
#endif
 
366
#ifndef htole32a
 
367
# define htole32a(a,x)   *(uint32_t*)(a) = htole32(x)
 
368
#endif
 
369
#ifndef htole64a
 
370
# define htole64a(a,x)   *(uint64_t*)(a) = htole64(x)
 
371
#endif
310
372
 
311
373
EOF
312
374
  ;;