Properly play a holdtime message if the announce-holdtime option is
[asterisk-bristuff.git] / include / asterisk / unaligned.h
blob16791d6f03b92a237b680217c029562c2693e192
1 /*
2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
19 /*! \file
20 * \brief Handle unaligned data access
23 #ifndef _ASTERISK_UNALIGNED_H
24 #define _ASTERISK_UNALIGNED_H
26 #if defined(__cplusplus) || defined(c_plusplus)
27 extern "C" {
28 #endif
30 #ifdef __GNUC__
31 /* If we just tell GCC what's going on, we can trust it to behave optimally */
32 static inline unsigned int get_unaligned_uint32(void *p)
34 struct { unsigned int d; } __attribute__((packed)) *pp = (void *)p;
36 return pp->d;
38 static inline unsigned short get_unaligned_uint16(void *p)
40 struct { unsigned short d; } __attribute__((packed)) *pp = (void *)p;
42 return pp->d;
45 static inline void put_unaligned_uint32(void *p, unsigned int datum)
47 struct { unsigned int d; } __attribute__((packed)) *pp = (void *)p;
49 pp->d = datum;
52 static inline void put_unaligned_uint16(void *p, unsigned short datum)
54 struct { unsigned short d; } __attribute__((packed)) *pp = (void *)p;
56 pp->d = datum;
58 #elif defined(SOLARIS) && defined(__sparc__)
59 static inline unsigned int get_unaligned_uint32(void *p)
61 unsigned char *cp = p;
63 return (cp[0] << 24) | (cp[1] << 16) | (cp[2] << 8) | cp[3];
66 static inline unsigned short get_unaligned_uint16(void *p)
68 unsigned char *cp = p;
70 return (cp[0] << 8) | cp[1] ;
73 static inline void put_unaligned_uint32(void *p, unsigned int datum)
75 unsigned char *cp = p;
77 cp[0] = datum >> 24;
78 cp[1] = datum >> 16;
79 cp[2] = datum >> 8;
80 cp[3] = datum;
83 static inline void put_unaligned_uint16(void *p, unsigned int datum)
85 unsigned char *cp = p;
87 cp[0] = datum >> 8;
88 cp[1] = datum;
90 #else /* Not GCC, not Solaris/SPARC. Assume we can handle direct load/store. */
91 #define get_unaligned_uint32(p) (*((unsigned int *)(p)))
92 #define get_unaligned_uint16(p) (*((unsigned short *)(p)))
93 #define put_unaligned_uint32(p,d) do { unsigned int *__P = (p); *__P = d; } while(0)
94 #define put_unaligned_uint16(p,d) do { unsigned short *__P = (p); *__P = d; } while(0)
95 #endif
97 #if defined(__cplusplus) || defined(c_plusplus)
99 #endif
102 #endif /* _ASTERISK_UNALIGNED_H */