Prevent an unwanted action which increases volume to be triggered at the same time...
[Rockbox.git] / tools / ucl / src / ucl_ptr.c
blobb092d2440f42f2d9592c38916a28586c1ba7424f
1 /* ucl_ptr.c -- low-level pointer constructs
3 This file is part of the UCL data compression library.
5 Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
6 All Rights Reserved.
8 The UCL library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
13 The UCL library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with the UCL library; see the file COPYING.
20 If not, write to the Free Software Foundation, Inc.,
21 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 Markus F.X.J. Oberhumer
24 <markus@oberhumer.com>
25 http://www.oberhumer.com/opensource/ucl/
29 #include "ucl_conf.h"
32 /***********************************************************************
34 ************************************************************************/
36 UCL_PUBLIC(ucl_ptr_t)
37 __ucl_ptr_linear(const ucl_voidp ptr)
39 ucl_ptr_t p;
41 #if defined(__UCL_DOS16) || defined(__UCL_WIN16)
42 p = (((ucl_ptr_t)(_FP_SEG(ptr))) << (16 - __UCL_HShift)) + (_FP_OFF(ptr));
43 #else
44 p = PTR_LINEAR(ptr);
45 #endif
47 return p;
51 /***********************************************************************
53 ************************************************************************/
55 UCL_PUBLIC(unsigned)
56 __ucl_align_gap(const ucl_voidp ptr, ucl_uint size)
58 ucl_ptr_t p, s, n;
60 assert(size > 0);
62 p = __ucl_ptr_linear(ptr);
63 s = (ucl_ptr_t) (size - 1);
64 #if 0
65 assert((size & (size - 1)) == 0);
66 n = ((p + s) & ~s) - p;
67 #else
68 n = (((p + s) / size) * size) - p;
69 #endif
71 assert((long)n >= 0);
72 assert(n <= s);
74 return (unsigned)n;
80 vi:ts=4:et