dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / efcode / engine / resource.c
blob5ede6eea741d603255075affc390fab72554d2c6
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright (c) 1999 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
33 #include <fcode/private.h>
34 #include <fcode/log.h>
36 fc_resource_t *
37 find_resource(fc_resource_t **head, void *ptr, int (cmp)(void *, void *))
39 fc_resource_t *f, *prev, *r = *head;
41 f = NULL;
42 prev = NULL;
43 while (r) {
44 if (r->data == NULL) {
45 fc_resource_t *dead;
47 if (prev)
48 prev->next = r->next;
49 else {
50 *head = r->next;
52 dead = r;
53 r = r->next;
54 FREE(dead);
55 } else {
56 if (cmp(ptr, r->data)) {
57 f = r;
58 break;
60 prev = r;
61 r = r->next;
64 return (f);
67 void *
68 add_resource(fc_resource_t **head, void *ptr, int (cmp)(void *, void *))
70 fc_resource_t *r;
72 r = find_resource(head, ptr, cmp);
73 if (r == NULL) {
74 r = MALLOC(sizeof (fc_resource_t));
75 r->data = ptr;
76 r->next = *head;
77 *head = r;
78 return (r->data);
80 log_message(MSG_ERROR, "add_resource: Duplicate entry: %p\n", ptr);
81 return (NULL);
84 void
85 free_resource(fc_resource_t **head, void *ptr, int (cmp)(void *, void *))
87 fc_resource_t *r;
89 if ((r = find_resource(head, ptr, cmp)) != NULL)
90 r->data = NULL;
91 else
92 log_message(MSG_ERROR, "free_resource: No such Entry: %p\n",
93 ptr);
96 #ifdef DEBUG
98 static int
99 dump_print(void *s, void *d)
101 log_message(MSG_DEBUG, "Buffer: %p\n", d);
102 return (0);
105 void
106 dump_resources(fcode_env_t *env)
108 fc_resource_t **head;
110 head = (fc_resource_t **) POP(DS);
111 (void) find_resource(head, NULL, dump_print);
114 void
115 propbufs(fcode_env_t *env)
117 PUSH(DS, (fstack_t) &env->propbufs);
120 #pragma init(_init)
122 static void
123 _init(void)
125 fcode_env_t *env = initial_env;
127 NOTICE;
128 ASSERT(env);
130 FORTH(0, "propbufs", propbufs);
131 FORTH(0, "dump-resource", dump_resources);
134 #endif