|
|
1.1 ! root 1: /* $Header: util.c,v 1.1 87/09/11 07:50:56 toddb Exp $ */ ! 2: /* ! 3: * These are routines fould in BDS and not found in System V. They are ! 4: * included so that some clients can compile. ! 5: */ ! 6: ! 7: /* Written by Jack Palevich. ! 8: * HP Labs ! 9: * April 1987 ! 10: */ ! 11: ! 12: bcopy (b1, b2, length) ! 13: register unsigned char *b1, *b2; ! 14: register length; ! 15: { ! 16: if (b1 < b2) { ! 17: b2 += length; ! 18: b1 += length; ! 19: while (length--) { ! 20: *--b2 = *--b1; ! 21: } ! 22: } ! 23: else { ! 24: while (length--) { ! 25: *b2++ = *b1++; ! 26: } ! 27: } ! 28: } ! 29: ! 30: bcmp (b1, b2, length) ! 31: register unsigned char *b1, *b2; ! 32: register length; ! 33: { ! 34: while (length--) { ! 35: if (*b1++ != *b2++) return 1; ! 36: } ! 37: return 0; ! 38: } ! 39: ! 40: bzero (b, length) ! 41: register unsigned char *b; ! 42: register length; ! 43: { ! 44: while (length--) { ! 45: *b++ = '\0'; ! 46: } ! 47: } ! 48: ! 49: ! 50: /* Find the first set bit ! 51: * i.e. least signifigant 1 bit: ! 52: * 0 => 0 ! 53: * 1 => 1 ! 54: * 2 => 2 ! 55: * 3 => 1 ! 56: * 4 => 3 ! 57: */ ! 58: ! 59: int ! 60: ffs(mask) ! 61: unsigned int mask; ! 62: { ! 63: register i; ! 64: ! 65: if ( ! mask ) return 0; ! 66: i = 1; ! 67: while (! (mask & 1)) { ! 68: i++; ! 69: mask = mask >> 1; ! 70: } ! 71: return i; ! 72: } ! 73: ! 74: char * ! 75: index (s, c) ! 76: char *s, c; ! 77: { ! 78: return ((char *) strchr (s, c)); ! 79: } ! 80: ! 81: char * ! 82: rindex (s, c) ! 83: char *s, c; ! 84: { ! 85: return ((char *) strrchr (s, c)); ! 86: } ! 87: ! 88: /* ! 89: * insque, remque - insert/remove element from a queue ! 90: * ! 91: * DESCRIPTION ! 92: * Insque and remque manipulate queues built from doubly linked ! 93: * lists. Each element in the queue must in the form of ! 94: * ``struct qelem''. Insque inserts elem in a queue immedi- ! 95: * ately after pred; remque removes an entry elem from a queue. ! 96: * ! 97: * SEE ALSO ! 98: * ``VAX Architecture Handbook'', pp. 228-235. ! 99: */ ! 100: ! 101: struct qelem { ! 102: struct qelem *q_forw; ! 103: struct qelem *q_back; ! 104: char *q_data; ! 105: }; ! 106: ! 107: insque(elem, pred) ! 108: register struct qelem *elem, *pred; ! 109: { ! 110: register struct qelem *q; ! 111: /* Insert locking code here */ ! 112: if ( elem->q_forw = q = (pred ? pred->q_forw : pred) ) ! 113: q->q_back = elem; ! 114: if ( elem->q_back = pred ) ! 115: pred->q_forw = elem; ! 116: /* Insert unlocking code here */ ! 117: } ! 118: ! 119: remque(elem) ! 120: register struct qelem *elem; ! 121: { ! 122: register struct qelem *q; ! 123: if ( ! elem ) return; ! 124: /* Insert locking code here */ ! 125: ! 126: if ( q = elem->q_back ) q->q_forw = elem->q_forw; ! 127: if ( q = elem->q_forw ) q->q_back = elem->q_back; ! 128: ! 129: /* insert unlocking code here */ ! 130: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.