]> git.saurik.com Git - apple/xnu.git/blame - bsd/netat/adsp_misc.c
xnu-1228.15.4.tar.gz
[apple/xnu.git] / bsd / netat / adsp_misc.c
CommitLineData
1c79356b 1/*
5d5c5d0d
A
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
8f6c56a5 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28#include <sys/errno.h>
29#include <sys/types.h>
30#include <sys/param.h>
31#include <machine/spl.h>
32#include <sys/systm.h>
33#include <sys/kernel.h>
34#include <sys/proc.h>
35#include <sys/filedesc.h>
36#include <sys/fcntl.h>
37#include <sys/mbuf.h>
38#include <sys/socket.h>
39
40#include <netat/sysglue.h>
41#include <netat/appletalk.h>
42#include <netat/at_pcb.h>
43#include <netat/debug.h>
44#include <netat/adsp.h>
45#include <netat/adsp_internal.h>
46
47/*
48 * These function replace the Mk68 assembly routines found in qAddToEnd.s and
49 * q????.s
50 * Modified for MP, 1996 by Tuyen Nguyen
51 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
52 */
1c79356b
A
53
54
1c79356b
A
55/* ----------------------------------------------------------------------
56 * void qAddToEnd(void *qhead, void *qelem)
57 *
58 * INPUTS:
59 * Ptr to ptr to 1st item in queue
60 * Ptr to item to add to end of queue
61 * OUTPUTS:
62 * none
63 *
64 * Assumptions: The link field is the FIRST field of the qelem structure.
65 * ----------------------------------------------------------------------
66 */
67int qAddToEnd(qhead, qelem)
68 struct qlink **qhead;
69 struct qlink *qelem;
70{
71 /* define our own type to access the next field. NOTE THAT THE "NEXT"
72 * FIELD IS ASSUMED TO BE THE FIRST FIELD OF THE STRUCTURE
73 */
74
75 register struct qlink *q;
76
77 /* Scan the linked list to the end and update the previous
78 * element next field. (do that protocted).
79 */
80
81 q = *qhead;
82 if (q) {
83 while (q->qlinkp) {
84 /* are we about to link to ourself */
85 if (q == qelem)
86 goto breakit;
87 q = q->qlinkp;
88 }
89 q->qlinkp = qelem;
90 }
91 else {
92 *qhead = qelem;
93 }
94 qelem->qlinkp = (struct qlink *) 0;
95breakit:
96#ifdef NOTDEF
97 DPRINTF("%s: qhead=%x added elem=%x\n","qAddToEnd", qhead, qelem);
98#endif
99 return 0;
100}
101
102
103
104/* ----------------------------------------------------------------------
105 * qfind_m
106 * void* qfind_m(void *qhead, void NPTR match, ProcPtr compare_fnx)
107 *
108 * Hunt down a linked list of queue elements calling the compare
109 * function on each item. When the compare function returns true,
110 * return ptr to the queue element.
111 *
112 *
113 * INPUTS:
114 * qhead Address of ptr to first item in queue
115 * match
116 * compare_fnx
117 * OUTPUTS:
118 * D0 & A0 Ptr to queue element or NIL
119 * REGISTERS:
120 * D0,D1,A0,A1
121 * ----------------------------------------------------------------------
122 */
123void* qfind_m(qhead, match, compare_fnx)
124 CCBPtr qhead;
125 void *match;
126 ProcPtr compare_fnx;
127{
1c79356b
A
128 CCBPtr queue_item = qhead;
129
1c79356b
A
130 while (queue_item) {
131 if ((*compare_fnx)(queue_item,match))
132 break;
133
134 queue_item = queue_item->ccbLink;
135 }
1c79356b
A
136
137 return (queue_item);
138}