home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name utsafcpy -- Copy data without danger of straddling
- * segment boundaries.
- *
- * Synopsis ercode = utsafcpy(psource,ptarget,amount);
- *
- * int ercode Returned error code:
- * 0 if data copied successfully.
- * UT_SRC_STRADDLE if source data
- * straddles a segment boundary.
- * UT_TGT_STRADDLE if target data
- * straddles a segment boundary.
- * UT_2_STRADDLE if both source and
- * target buffers straddle segment
- * boundaries.
- * const void far *psource
- * Double word address of source data.
- * void far *ptarget
- * Double word address of target location.
- * unsigned int amount
- * The number of bytes to copy.
- *
- * Description This function copies data from any memory location to
- * any other but only if both the source and target buffers
- * lie completely within one segment (not necessarily the
- * same segment). This prevents segment overrun exceptions
- * (interrupt 0x0e) on the 80286.
- *
- * Returns ercode Returned error code:
- * 0 if data copied successfully.
- * UT_SRC_STRADDLE if source data
- * straddles a segment boundary.
- * UT_TGT_STRADDLE if target data
- * straddles a segment boundary.
- * UT_2_STRADDLE if both source and
- * target buffers straddle segment
- * boundaries.
- *
- * Version 6.00 (C)Copyright Blaise Computing Inc. 1989
- *
- **/
-
- #include <butil.h>
-
- int utsafcpy(psource,ptarget,amount)
- const void far *psource;
- void far *ptarget;
- unsigned int amount;
- {
- int result = 0;
-
- if (amount > 1)
- {
- if (utoff(psource) >= (unsigned) 1 - amount)
- result = UT_SRC_STRADDLE;
- if (utoff(ptarget) >= (unsigned) 1 - amount)
- result += UT_TGT_STRADDLE;
- }
- if (0 == result) /* Copy only if safe. */
- utmovmem(psource,ptarget,amount);
-
- return result;
- }