1 /* Shoggoth - Distributed File System
4 * Copyright (C) 2012 Pawel Dziepak
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, version 3 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
19 #include <arpa/inet.h>
21 static inline int min(int a
, int b
) {
25 static inline int max(int a
, int b
) {
29 #define to_be16(x) htons(x)
30 #define to_be32(x) htonl(x)
32 static inline uint64_t to_be64(uint64_t x
) {
34 unsigned char *py
= (unsigned char*)&y
;
48 #define from_be16(x) ntohs(x)
49 #define from_be32(x) ntohl(x)
51 static inline uint64_t form_be64(uint64_t x
) {
52 unsigned char *px
= (unsigned char*)&x
;
54 return (uint64_t)px
[0] << 56 | (uint64_t)px
[1] << 48 |
55 (uint64_t)px
[2] << 40 | (uint64_t)px
[3] << 32 |
56 (uint64_t)px
[4] << 24 | (uint64_t)px
[5] << 16 |
57 (uint64_t)px
[6] << 8 | (uint64_t)px
[7];