import less(1)
[unleashed/tickless.git] / usr / src / lib / libc / port / nsl / t_free.c
blobde07f133df6485a036181bfdb89951201d3790b9
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) 1984, 1986, 1987, 1988, 1989 AT&T */
24 /* All Rights Reserved */
27 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
31 #include "mt.h"
32 #include <xti.h>
33 #include <errno.h>
34 #include <stropts.h>
35 #include <stdlib.h>
36 #include <sys/types.h>
37 #include "tx.h"
39 int
40 _tx_free(char *ptr, int struct_type, int api_semantics)
42 union structptrs {
43 struct t_bind *bind;
44 struct t_call *call;
45 struct t_discon *dis;
46 struct t_optmgmt *opt;
47 struct t_unitdata *udata;
48 struct t_uderr *uderr;
49 } p;
52 * Free all the buffers associated with the appropriate
53 * fields of each structure.
56 switch (struct_type) {
58 case T_BIND:
59 /* LINTED pointer cast */
60 p.bind = (struct t_bind *)ptr;
61 free(p.bind->addr.buf);
62 break;
64 case T_CALL:
65 /* LINTED pointer cast */
66 p.call = (struct t_call *)ptr;
67 free(p.call->addr.buf);
68 free(p.call->opt.buf);
69 free(p.call->udata.buf);
70 break;
72 case T_OPTMGMT:
73 /* LINTED pointer cast */
74 p.opt = (struct t_optmgmt *)ptr;
75 free(p.opt->opt.buf);
76 break;
78 case T_DIS:
79 /* LINTED pointer cast */
80 p.dis = (struct t_discon *)ptr;
81 free(p.dis->udata.buf);
82 break;
84 case T_UNITDATA:
85 /* LINTED pointer cast */
86 p.udata = (struct t_unitdata *)ptr;
87 free(p.udata->addr.buf);
88 free(p.udata->opt.buf);
89 free(p.udata->udata.buf);
90 break;
92 case T_UDERROR:
93 /* LINTED pointer cast */
94 p.uderr = (struct t_uderr *)ptr;
95 free(p.uderr->addr.buf);
96 free(p.uderr->opt.buf);
97 break;
99 case T_INFO:
100 break;
102 default:
103 if (_T_IS_XTI(api_semantics)) {
104 t_errno = TNOSTRUCTYPE;
105 } else { /* TX_TLI_API */
106 t_errno = TSYSERR;
107 errno = EINVAL;
109 return (-1);
112 free(ptr);
113 return (0);