dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / cfgadm_plugins / ac / common / mema_test_subr.c
blob90a2656358b7a52aea890fefd6205bd4b4fd77aa
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) 1996-1998 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <stddef.h>
30 #include <stdlib.h>
31 #include <assert.h>
32 #include <sys/param.h>
33 #include <memory.h>
34 #include <config_admin.h>
35 #include "mema_test.h"
37 void *
38 mtest_allocate_buf(
39 mtest_handle_t handle,
40 size_t size)
42 struct mtest_alloc_ent *new_ent;
44 new_ent =
45 (struct mtest_alloc_ent *)malloc(sizeof (struct mtest_alloc_ent));
46 if (new_ent == NULL)
47 return (NULL);
49 new_ent->buf = malloc(size);
50 if (new_ent->buf == NULL) {
51 free((void *)new_ent);
52 return (NULL);
54 /* TODO: probably not thread safe? */
55 new_ent->next = handle->alloc_list;
56 handle->alloc_list = new_ent;
58 return (new_ent->buf);
61 /* This routine dedicated to George Cameron */
62 void
63 mtest_deallocate_buf(
64 mtest_handle_t handle,
65 void *buf)
67 struct mtest_alloc_ent **p, *p1;
69 p = &handle->alloc_list;
70 while ((*p) != NULL && (*p)->buf != buf)
71 p = &(*p)->next;
72 assert((*p) != NULL);
73 p1 = *p;
74 *p = (*p)->next;
75 free(p1->buf);
76 free((void *)p1);
79 void
80 mtest_deallocate_buf_all(mtest_handle_t handle)
82 struct mtest_alloc_ent *p1;
84 while ((p1 = handle->alloc_list) != NULL) {
85 handle->alloc_list = p1->next;
86 free(p1->buf);
87 free((void *)p1);
91 void
92 mtest_message(mtest_handle_t handle, const char *msg)
94 if (handle->msgp != NULL && handle->msgp->message_routine != NULL) {
95 (*handle->msgp->message_routine)(handle->msgp->appdata_ptr,
96 msg);