Toplevel entrypoints for classes/traits/interfaces
[hiphop-php.git] / hphp / util / htonll.h
bloba04e21b2bb16ea292344e19d5a0ac800c6e9ee7f
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #pragma once
20 * Tries to find a suitable implementation of htonll/ntohll if it doesn't
21 * already exist. This could go into portability.h, but seemed specific enough
22 * to be worth pulling out.
25 #include <folly/portability/Sockets.h>
26 #if defined(__FreeBSD__)
27 # include <sys/endian.h>
28 #elif defined(__APPLE__)
29 # include <machine/endian.h>
30 # include <libkern/OSByteOrder.h>
31 #elif defined(_MSC_VER)
32 # include <stdlib.h>
33 #else
34 # include <byteswap.h>
35 #endif
37 #if __BYTE_ORDER == __LITTLE_ENDIAN
38 # define htolell(x) (x)
39 # define letohll(x) (x)
40 # if !defined(htonll) && !defined(ntohll)
41 # if defined(__FreeBSD__)
42 # define htonll(x) bswap64(x)
43 # define ntohll(x) bswap64(x)
44 # elif defined(__APPLE__)
45 # define htonll(x) OSSwapInt64(x)
46 # define ntohll(x) OSSwapInt64(x)
47 # elif defined(_MSC_VER)
48 # define htonll(x) _byteswap_uint64(x)
49 # define ntohll(x) _byteswap_uint64(x)
50 # else
51 # define htonll(x) bswap_64(x)
52 # define ntohll(x) bswap_64(x)
53 # endif
54 # endif
55 #else
56 # if defined(__FreeBSD__)
57 # define htolell(x) bswap64(x)
58 # define letohll(x) bswap64(x)
59 # elif defined(__APPLE__)
60 # define htolell(x) OSSwapInt64(x)
61 # define letohll(x) OSSwapInt64(x)
62 # elif defined(_MSC_VER)
63 # define htolell(x) _byteswap_uint64(x)
64 # define letohll(x) _byteswap_uint64(x)
65 # else
66 # define htolell(x) bswap_64(x)
67 # define letohll(x) bswap_64(x)
68 # endif
69 # if !defined(htonll) && !defined(ntohll)
70 # define htonll(x) (x)
71 # define ntohll(x) (x)
72 # endif
73 #endif