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