Coda Distributed File System
rwcdb_pack.h
Go to the documentation of this file.
1/* BLURB lgpl
2
3 Coda File System
4 Release 8
5
6 Copyright (c) 2003-2021 Carnegie Mellon University
7 Additional copyrights listed below
8
9This code is distributed "AS IS" without warranty of any kind under
10the terms of the GNU Library General Public Licence Version 2, as
11shown in the file LICENSE. The technical and financial contributors to
12Coda are listed in the file CREDITS.
13
14 Additional copyrights
15*/
16
17#ifndef _RWCDB_PACK_H_
18#define _RWCDB_PACK_H_
19
20#include <config.h>
21#include <sys/types.h>
22#include <stdint.h>
23
24/* really bad hack, but this should work for 'most' systems :) */
25#ifndef __BYTE_ORDER
26#define __BIG_ENDIAN 4321
27#define __LITTLE_ENDIAN 1234
28#define __BYTE_ORDER __LITTLE_ENDIAN
29#endif
30
31/* Indirect thanks to Alan Barrett for figuring out which 'standard' headers
32 * are used to define the 'standard' byte swapping functions. */
33#if __BYTE_ORDER == __LITTLE_ENDIAN
34#define SWAP_IN(x) (x)
35#define SWAP_OUT(x) (x)
36#elif HAVE_BYTESWAP_H
37#include <byteswap.h>
38#define SWAP_IN(x) bswap_32(x)
39#define SWAP_OUT(x) bswap_32(x)
40#elif HAVE_SYS_BSWAP_H
41#include <sys/bswap.h>
42#define SWAP_IN(x) bswap32(x)
43#define SWAP_OUT(x) bswap32(x)
44#elif HAVE_SYS_ENDIAN_H
45#include <sys/endian.h>
46#define SWAP_IN(x) le32toh(x)
47#define SWAP_OUT(x) htole32(x)
48#else
49#error "Need to know how to convert between native and little endian byteorder"
50#endif
51
52/*=====================================================================*/
53/* stuff for packing/unpacking db values */
54
58};
59
60static __inline__ void packints(char *buf, const uint32_t a, const uint32_t b)
61{
62 struct rwcdb_tuple *p = (struct rwcdb_tuple *)buf;
63
64 p->a = SWAP_OUT(a);
65 p->b = SWAP_OUT(b);
66}
67
68static __inline__ void unpackints(char *buf, uint32_t *a, uint32_t *b)
69{
70 struct rwcdb_tuple *p = (struct rwcdb_tuple *)buf;
71
72 *a = SWAP_IN(p->a);
73 *b = SWAP_IN(p->b);
74}
75
76#endif /* _RWCDB_PACK_H_ */
unsigned int uint32_t
Definition: coda.h:105
#define SWAP_OUT(x)
Definition: rwcdb_pack.h:35
#define SWAP_IN(x)
Definition: rwcdb_pack.h:34
Definition: rwcdb_pack.h:55
uint32_t a
Definition: rwcdb_pack.h:56
uint32_t b
Definition: rwcdb_pack.h:57