VirtualBox

source: vbox/trunk/src/VBox/Devices/Storage/swab.h@ 11118

Last change on this file since 11118 was 8155, checked in by vboxsync, 17 years ago

The Big Sun Rebranding Header Change

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.2 KB
Line 
1/** @file
2 *
3 * VBox storage devices:
4 * C++-safe replacements for some Linux byte order macros
5 *
6 * On Linux, DrvHostDVD.cpp includes <linux/cdrom.h>, which in turn
7 * includes <linux/byteorder/swab.h>. Unfortunately, that file is not very
8 * C++ friendly, and our C++ compiler refuses to look at it. The solution
9 * is to define _LINUX_BYTEORDER_SWAB_H, which prevents that file's contents
10 * from getting included at all, and to provide, in this file, our own
11 * C++-proof versions of the macros which are needed by <linux/cdrom.h>
12 * before we include that file. We actually provide them as inline
13 * functions, due to the way they get resolved in the original.
14 */
15
16/*
17 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
18 *
19 * This file is part of VirtualBox Open Source Edition (OSE), as
20 * available from http://www.virtualbox.org. This file is free software;
21 * you can redistribute it and/or modify it under the terms of the GNU
22 * General Public License (GPL) as published by the Free Software
23 * Foundation, in version 2 as it comes in the "COPYING" file of the
24 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
25 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
26 *
27 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
28 * Clara, CA 95054 USA or visit http://www.sun.com if you need
29 * additional information or have any questions.
30 */
31
32#ifndef _VBOX_LINUX_SWAB_H
33#define _VBOX_LINUX_SWAB_H
34
35# define _LINUX_BYTEORDER_SWAB_H
36
37#include <asm/types.h>
38
39/* Sorry for the unnecessary brackets here, but I really think
40 readability requires them */
41static __inline__ __u16 __swab16p(const __u16 *px)
42{
43 __u16 x = *px;
44 return ((x & 0xff) << 8) | ((x >> 8) & 0xff);
45}
46
47static __inline__ __u32 __swab32p(const __u32 *px)
48{
49 __u32 x = *px;
50 return ((x & 0xff) << 24) | ((x & 0xff00) << 8)
51 | ((x >> 8) & 0xff00) | ((x >> 24) & 0xff);
52}
53
54static __inline__ __u64 __swab64p(const __u64 *px)
55{
56 __u64 x = *px;
57 return ((x & 0xff) << 56) | ((x & 0xff00) << 40)
58 | ((x & 0xff0000) << 24) | ((x & 0xff000000) << 8)
59 | ((x >> 8) & 0xff000000) | ((x >> 24) & 0xff0000)
60 | ((x >> 40) & 0xff00) | ((x >> 56) & 0xff);
61}
62
63#endif /* _VBOX_LINUX_SWAB_H */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette