コード例 #1
0
ファイル: tmpfile.c プロジェクト: andreiw/polaris
/*
 * This is a bit confusing -- some explanation is in order.
 *
 * When we're compiled 64-bit, there's no point in distinguishing
 * a "large" file from a "small" file -- they're all "large".
 * The argument we pass to '_common' is ignored -- we always call
 * mkstemp which will just do the right thing for us.
 */
FILE *
tmpfile(void)
{
	return (_common(B_FALSE));
}
コード例 #2
0
ファイル: tmpfile.c プロジェクト: andreiw/polaris
FILE *
tmpfile64(void)
{
	return (_common(B_TRUE));
}
コード例 #3
0
ファイル: aguri.c プロジェクト: duper/blackbag
/*
 * creat a leaf node and its branch point.
 * then, insert the branch point as the parent of the specified node.
 */
static anode_t *
_alloc(aguri_t *tp, const void *key, anode_t *np) {
	anode_t *bp = NULL, *leaf = NULL;

	/* reclaim two nodes from the LRU list */
	leaf = TAILQ_LAST(&tp->tr_lru, _lru);
	while (leaf->tn_intree)
		leaf = TAILQ_PREV(leaf, _lru, tn_chain);
	TAILQ_REMOVE(&tp->tr_lru, leaf, tn_chain);
	TAILQ_INSERT_HEAD(&tp->tr_lru, leaf, tn_chain);
	leaf->tn_intree = 1;
	tp->tr_nfree--;
	_nreset(leaf);
	memcpy(leaf->tn_key, key, tp->tr_keylen/8);
	leaf->tn_prefixlen = tp->tr_keylen;

	assert(tp->tr_nfree > 0);
	bp = TAILQ_LAST(&tp->tr_lru, _lru);
	while (bp->tn_intree)
		bp = TAILQ_PREV(bp, _lru, tn_chain);
	TAILQ_REMOVE(&tp->tr_lru, bp, tn_chain);
	bp->tn_intree = 1;
	tp->tr_nfree--;
	_nreset(bp);
	bp->tn_prefixlen = _common(np->tn_key, key, tp->tr_keylen, bp->tn_key);

	if (bp->tn_prefixlen >= np->tn_prefixlen) {
		/*
		 * leaf should be a child of np
		 */
		assert(np->tn_left == NULL && np->tn_right == NULL);
		TAILQ_REMOVE(&tp->tr_lru, np, tn_chain);
		TAILQ_INSERT_HEAD(&tp->tr_lru, bp, tn_chain);
		if (bp->tn_prefixlen != np->tn_prefixlen) {
			_set(bp->tn_key, np->tn_prefixlen + 1);
			np->tn_left = leaf;
			np->tn_right = bp;
		} else {
			np->tn_left = bp;
			np->tn_right = leaf;
		}
		bp->tn_parent = np;
		leaf->tn_parent = np;
		return (leaf);
	}

	if (np->tn_parent->tn_left == np)
		np->tn_parent->tn_left = bp;
	else
		np->tn_parent->tn_right = bp;
	bp->tn_parent = np->tn_parent;
	if (_isset(key, bp->tn_prefixlen + 1)) {
		bp->tn_left = np;
		bp->tn_right = leaf;
	} else {
		bp->tn_left = leaf;
		bp->tn_right = np;
	}
	np->tn_parent = bp;
	leaf->tn_parent = bp;

	return (leaf);
}