home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_03_06 / 3n06059a < prev    next >
Text File  |  1992-04-08  |  1KB  |  30 lines

  1. #include <dos.h>
  2.  
  3. /* Copy bytes from NEAR buffer to HUGE array - using FAR pointers */
  4. /* Split up copy operation where it crosses segment boundary */
  5.  
  6. void hmemcopy(char huge *to, char *from, unsigned long count) {
  7.     unsigned int offset, k, n;
  8.     char huge *toend;
  9.     char far *d;
  10.     char *s;    
  11.  
  12.     toend = to + count - 1;           /* last byte destination */
  13.     while (FP_SEG(to) != FP_SEG(toend)){   /* will it cross boundary ? */
  14.         offset = FP_OFF(to);          /* calculate how much left in segment */
  15.         if (offset == 0) {            /* special case - do in two pieces */
  16.             n = 32768;                /* copy first half */
  17.             d = to; s = from;
  18.             for (k = 0; k < n; k++) *d++ = *s++;
  19.             to += n; from += n; count -= n; offset += n;
  20.         }
  21.         n = 65535U - (offset - 1);    /* avoid arithmetic problems */
  22.         d = to; s = from;          /* copy up to end of segment */
  23.         for (k = 0; k < n; k++) *d++ = *s++;
  24.         to += n; from += n; count -= n;
  25.     }
  26.     d = to; s = from; n = (unsigned int) count;    /* now do last piece */
  27.     for (k = 0; k < n; k++) *d++ = *s++;
  28. }
  29.  
  30.