SCO-duggery (code comparison)

Joseph S. Barrera III joebar at polymathy.org
Tue Aug 19 20:22:34 PDT 2003


Here's the linux code, and the original Unix 6th edition code
("Reproduced under license from the Western Electric Company, NY").

The Unix code is worth reading if only to see what an
ancient dialect of C it's written in (e.g. =+ allowed
as a synonym for += ).

I have to say that the two samples are pretty damn similar,
albeit with modernization applied to the Linux code
(translation to modern dialect of C; use of ASSERT;
use of spinlocks to handle concurrent access).

BTW, the edition of Lion's book that I have has a
big notice from SCO about the code being published
solely for educational purposes...

- Joe

Linux:

/*
  * Allocate 'size' units from the given map.
  * Return the base of the allocated space.
  * In a map, the addresses are increasing and the
  * list is terminated by a 0 size.
  * Algorithm is first-fit.
  */

ulong_t
atealloc(
	struct map *mp,
	size_t size)
{
	register unsigned int a;
	register struct map *bp;
	register unsigned long s;

	ASSERT(size >= 0);

	if (size == 0)
		return((ulong_t) NULL);

	s = mutex_spinlock(maplock(mp));

	for (bp = mapstart(mp); bp->m_size; bp++) {
		if (bp->m_size >= size) {
			a = bp->m_addr;
			bp->m_addr += size;
			if ((bp->m_size -= size) == 0) {
				do {
					bp++;
					(bp-1)->m_addr = bp->m_addr;
				} while ((((bp-1)->m_size) = (bp->m_size)));
				mapsize(mp)++;
			}

			ASSERT(bp->m_size < 0x80000000);
			mutex_spinunlock(maplock(mp), s);
			return(a);
		}
	}

	/*
	 * We did not get what we need .. we cannot sleep ..
	 */
	mutex_spinunlock(maplock(mp), s);
	return(0);
}

Unix 6th edition:

malloc(mp, size)
struct map *mp;
{
     register int a;
     register struct map *bp;

     for (bp = mp; bp->m_size; bp++) {
         if (bp->m_size >= size) {
             a = bp->m_addr;
             bp->m_addr =+ size;
             if ((bp->m_size =- size) == 0)
                 do {
                     bp++;
                     (bp-1)->m_addr = bp->m_addr;
                 } while((bp-1)->m_size = bp->m_size);
             return(a);
         }
     }
     return (0);
}



More information about the FoRK mailing list