diff options
Diffstat (limited to 'tools/ucl/src/ucl_ptr.c')
-rw-r--r-- | tools/ucl/src/ucl_ptr.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/tools/ucl/src/ucl_ptr.c b/tools/ucl/src/ucl_ptr.c new file mode 100644 index 0000000000..b092d2440f --- /dev/null +++ b/tools/ucl/src/ucl_ptr.c | |||
@@ -0,0 +1,81 @@ | |||
1 | /* ucl_ptr.c -- low-level pointer constructs | ||
2 | |||
3 | This file is part of the UCL data compression library. | ||
4 | |||
5 | Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer | ||
6 | All Rights Reserved. | ||
7 | |||
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. | ||
12 | |||
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. | ||
17 | |||
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. | ||
22 | |||
23 | Markus F.X.J. Oberhumer | ||
24 | <markus@oberhumer.com> | ||
25 | http://www.oberhumer.com/opensource/ucl/ | ||
26 | */ | ||
27 | |||
28 | |||
29 | #include "ucl_conf.h" | ||
30 | |||
31 | |||
32 | /*********************************************************************** | ||
33 | // | ||
34 | ************************************************************************/ | ||
35 | |||
36 | UCL_PUBLIC(ucl_ptr_t) | ||
37 | __ucl_ptr_linear(const ucl_voidp ptr) | ||
38 | { | ||
39 | ucl_ptr_t p; | ||
40 | |||
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 | ||
46 | |||
47 | return p; | ||
48 | } | ||
49 | |||
50 | |||
51 | /*********************************************************************** | ||
52 | // | ||
53 | ************************************************************************/ | ||
54 | |||
55 | UCL_PUBLIC(unsigned) | ||
56 | __ucl_align_gap(const ucl_voidp ptr, ucl_uint size) | ||
57 | { | ||
58 | ucl_ptr_t p, s, n; | ||
59 | |||
60 | assert(size > 0); | ||
61 | |||
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 | ||
70 | |||
71 | assert((long)n >= 0); | ||
72 | assert(n <= s); | ||
73 | |||
74 | return (unsigned)n; | ||
75 | } | ||
76 | |||
77 | |||
78 | |||
79 | /* | ||
80 | vi:ts=4:et | ||
81 | */ | ||