File:  [MW Coherent from dump] / coherent / b / lib / libc / gen / malloc / notmem.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:35 2019 UTC (7 years ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent

/*
 * notmem.c
 * Test if pointer is in malloc arena.
 */

#include <stdio.h>
#include <sys/malloc.h>

/*
 * Return 1 if cp is not in the malloc arena,
 * 0 if cp is in the malloc arena, or
 * -1 if trouble is detected in the arena.
 * Note that this returns 0 for freed blocks in the arena.
 */
notmem(cp) char *cp;
{
	register unsigned len, counter;
	register MBLOCK *mp, *ap;

	if (cp == NULL
	   || (mp = __a_scanp) == NULL
	   || ((ap = mblockp(cp))->blksize) == 0)
		return 1;			/* obviously bad */

	for (counter = __a_count; counter--; ) {
		if (mp == ap)
			return 0;		/* obviously good */
		len = mp->blksize;
		mp = (len) ? bumpp(mp, realsize(len)) : mp->uval.next;
	}
	if (mp != __a_scanp)
		return -1;			/* trouble in arena */
	return 1;				/* not found */
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.