Category : C Source Code
Archive   : CSRC2.ZIP
Filename : COPY.C

 
Output of file : COPY.C contained in archive : CSRC2.ZIP
/*
* c o p y . c
*/

/*)LIBRARY
*/

#ifdef DOCUMENTATION

title copy Copy a Given Number of Bytes
index Copy a given number of bytes

synopsis
.s.nf
char *
copy(out, in, nbytes)
char *out; /* Output vector */
char *in; /* Input vector */
unsigned int count; /* Bytes to copy */
.s.f
Description

Copy the indicated number of bytes from the input area
to the output area. Return a pointer to the first free
byte in the output area. (I.e., &out[count]).

The copying will be faster if out and in are either both
even or both odd addresses.

Bugs

Warning, this routine "understands" pdp-11 address conventions.
#endif

#ifdef pdp11
#define SHIFT 1
#define LOWBIT 01
#else
#ifdef vax
#define SHIFT 2
#define LOWBIT 03
#else
#ifdef mc68000
#define SHIFT 2
#define LOWBIT 03
#else
#endif
#endif
#endif

char *
copy(out, in, count)
register char *out;
register char *in;
register unsigned int count;
/*
* Copy a given number of bytes
*/
{
if (count != 0) {
#ifdef SHIFT
if (count > 10) {
/*
* Try to optimize
*/
if ((((unsigned int) in) & LOWBIT) != 0) {
*out++ = *in++;
count--;
}
if ((((unsigned int) out) & LOWBIT) == 0) {
count >>= SHIFT; /* Get a word count */
do {
*((int *)out)++ = *((int *)in)++;
} while (--count != 0);
goto exit;
}
}
#endif
/*
* Here for small copies, strange machines, and copies where
* the output buffer isn't the same parity as the input buffer.
*/
do {
*out++ = *in++;
} while (--count != 0);
}
exit: return (out);
}


  3 Responses to “Category : C Source Code
Archive   : CSRC2.ZIP
Filename : COPY.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/