From a8fe90b28bdd9643cfd4168c006069d165cef101 Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Sun, 21 Aug 2005 14:15:00 +0200 Subject: Replaced the get/put_unaligned() macros from with own inline functions --- tools.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'tools.h') diff --git a/tools.h b/tools.h index 0644f4e6..0a8ee8b6 100644 --- a/tools.h +++ b/tools.h @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: tools.h 1.73 2005/08/06 09:53:21 kls Exp $ + * $Id: tools.h 1.74 2005/08/21 14:06:38 kls Exp $ */ #ifndef __TOOLS_H @@ -57,6 +57,21 @@ template inline void swap(T &a, T &b) { T t = a; a = b; b = t; } #define BCDCHARTOINT(x) (10 * ((x & 0xF0) >> 4) + (x & 0xF)) int BCD2INT(int x); +// Unfortunately there are no platform independent macros for unaligned +// access. so we do it this way: + +template inline T get_unaligned(T *p) +{ + struct s { T v; } __attribute__((packed)); + return ((s *)p)->v; +} + +template inline void put_unaligned(unsigned int v, T* p) +{ + struct s { T v; } __attribute__((packed)); + ((s *)p)->v = v; +} + class cString { private: char *s; -- cgit v1.2.3