ucl_ptr.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* ucl_ptr.c -- low-level pointer constructs
  2. This file is part of the UCL data compression library.
  3. Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
  4. All Rights Reserved.
  5. The UCL library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of
  8. the License, or (at your option) any later version.
  9. The UCL library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with the UCL library; see the file COPYING.
  15. If not, write to the Free Software Foundation, Inc.,
  16. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. Markus F.X.J. Oberhumer
  18. <markus@oberhumer.com>
  19. http://www.oberhumer.com/opensource/ucl/
  20. */
  21. #include "ucl_conf.h"
  22. /***********************************************************************
  23. //
  24. ************************************************************************/
  25. UCL_PUBLIC(ucl_ptr_t)
  26. __ucl_ptr_linear(const ucl_voidp ptr)
  27. {
  28. ucl_ptr_t p;
  29. #if defined(__UCL_DOS16) || defined(__UCL_WIN16)
  30. p = (((ucl_ptr_t)(_FP_SEG(ptr))) << (16 - __UCL_HShift)) + (_FP_OFF(ptr));
  31. #else
  32. p = PTR_LINEAR(ptr);
  33. #endif
  34. return p;
  35. }
  36. /***********************************************************************
  37. //
  38. ************************************************************************/
  39. UCL_PUBLIC(unsigned)
  40. __ucl_align_gap(const ucl_voidp ptr, ucl_uint size)
  41. {
  42. ucl_ptr_t p, s, n;
  43. assert(size > 0);
  44. p = __ucl_ptr_linear(ptr);
  45. s = (ucl_ptr_t) (size - 1);
  46. #if 0
  47. assert((size & (size - 1)) == 0);
  48. n = ((p + s) & ~s) - p;
  49. #else
  50. n = (((p + s) / size) * size) - p;
  51. #endif
  52. assert((long)n >= 0);
  53. assert(n <= s);
  54. return (unsigned)n;
  55. }
  56. /*
  57. vi:ts=4:et
  58. */