home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / UTSAFCPY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  1.9 KB  |  65 lines

  1. /**
  2. *
  3. * Name        utsafcpy -- Copy data without danger of straddling
  4. *                segment boundaries.
  5. *
  6. * Synopsis    ercode = utsafcpy(psource,ptarget,amount);
  7. *
  8. *        int ercode      Returned error code:
  9. *                    0 if data copied successfully.
  10. *                    UT_SRC_STRADDLE if source data
  11. *                      straddles a segment boundary.
  12. *                    UT_TGT_STRADDLE if target data
  13. *                      straddles a segment boundary.
  14. *                    UT_2_STRADDLE if both source and
  15. *                      target buffers straddle segment
  16. *                      boundaries.
  17. *        const void far *psource
  18. *                  Double word address of source data.
  19. *        void far *ptarget
  20. *                  Double word address of target location.
  21. *        unsigned int amount
  22. *                  The number of bytes to copy.
  23. *
  24. * Description    This function copies data from any memory location to
  25. *        any other but only if both the source and target buffers
  26. *        lie completely within one segment (not necessarily the
  27. *        same segment).    This prevents segment overrun exceptions
  28. *        (interrupt 0x0e) on the 80286.
  29. *
  30. * Returns    ercode          Returned error code:
  31. *                    0 if data copied successfully.
  32. *                    UT_SRC_STRADDLE if source data
  33. *                      straddles a segment boundary.
  34. *                    UT_TGT_STRADDLE if target data
  35. *                      straddles a segment boundary.
  36. *                    UT_2_STRADDLE if both source and
  37. *                      target buffers straddle segment
  38. *                      boundaries.
  39. *
  40. * Version    6.00 (C)Copyright Blaise Computing Inc.  1989
  41. *
  42. **/
  43.  
  44. #include <butil.h>
  45.  
  46. int utsafcpy(psource,ptarget,amount)
  47. const void far *psource;
  48. void       far *ptarget;
  49. unsigned int amount;
  50. {
  51.     int result = 0;
  52.  
  53.     if (amount > 1)
  54.     {
  55.     if (utoff(psource) >= (unsigned) 1 - amount)
  56.         result  = UT_SRC_STRADDLE;
  57.     if (utoff(ptarget) >= (unsigned) 1 - amount)
  58.         result += UT_TGT_STRADDLE;
  59.     }
  60.     if (0 == result)              /* Copy only if safe.          */
  61.     utmovmem(psource,ptarget,amount);
  62.  
  63.     return result;
  64. }
  65.