TUM-Logo

libRASCH

 

Home
 

General

About libRASCH/News
Design
Screen shots
Sample programs (with source code)
License
 

Download

libRASCH
Tools
 

Documentation

User
Developer
 

Resources

Mailing list
Supported Formats
Plugins
Status
Links
 
Contact
About this site
 
Last updated
Tue Mar 27 23:03:52 2007
libRASCH: ra_endian.h Source File

ra_endian.h

Go to the documentation of this file.
00001 
00009 /*----------------------------------------------------------------------------
00010  *
00011  * Copyright (C) 2002-2003, Raphael Schneider
00012  * See the file COPYING for information on usage and redistribution.
00013  *
00014  * $Header: /home/cvs_repos.bak/librasch/include/ra_endian.h,v 1.6 2004/06/29 15:50:43 rasch Exp $
00015  *
00016  *--------------------------------------------------------------------------*/
00017 
00018 #ifndef _RA_ENDIAN_H
00019 #define _RA_ENDIAN_H
00020 
00021 #ifdef __cplusplus
00022 extern "C" {
00023 #endif
00024 
00025 #define RA_LITTLE_ENDIAN  1
00026 #define RA_BIG_ENDIAN     2
00027 
00028 #define _swap16(x,l)                                \
00029   do {                                              \
00030     short endian_t = x;                             \
00031         int endian_type = get_endian_type();            \
00032                                                     \
00033     if (l && (endian_type == RA_LITTLE_ENDIAN))     \
00034          break;                                     \
00035     if (!l && (endian_type == RA_BIG_ENDIAN))       \
00036          break;                                     \
00037                                                     \
00038     x = ((endian_t & 0x00ff) << 8) |                \
00039         ((endian_t & 0xff00) >> 8);                 \
00040   } while(0)
00041 
00042 #define _swap32(x,l)                                \
00043   do {                                              \
00044     long endian_t = x;                              \
00045         int endian_type = get_endian_type();            \
00046                                                     \
00047     if (l && (endian_type == RA_LITTLE_ENDIAN))     \
00048          break;                                     \
00049     if (!l && (endian_type == RA_BIG_ENDIAN))       \
00050          break;                                     \
00051                                                     \
00052     x = ((endian_t & 0x000000ff) << 24) |           \
00053         ((endian_t & 0x0000ff00) << 8)  |           \
00054         ((endian_t & 0x00ff0000) >> 8)  |           \
00055         ((endian_t & 0xff000000) >> 24);            \
00056   } while(0)
00057 
00058 
00059 #define be16_to_cpu(x) _swap16(x,0)
00060 #define be32_to_cpu(x) _swap32(x,0)
00061 
00062 #define le16_to_cpu(x) _swap16(x,1)
00063 #define le32_to_cpu(x) _swap32(x,1)
00064 
00065 
00066 #ifdef __cplusplus
00067 }
00068 #endif
00069 
00070 #endif /* _RA_ENDIAN_H */

Generated on Fri May 27 11:32:39 2005 for libRASCH by  doxygen 1.4.2