xref: /illumos-gate/usr/src/lib/libnsl/nsl/t_free.c (revision 08855964b9970604433f7b19dcd71cf5af5e5f14)
1 /*
2  * CDDL HEADER START
3  *
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.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
24 /*	  All Rights Reserved  	*/
25 
26 /*
27  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
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"
38 
39 int
40 _tx_free(char *ptr, int struct_type, int api_semantics)
41 {
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;
50 
51 	/*
52 	 * Free all the buffers associated with the appropriate
53 	 * fields of each structure.
54 	 */
55 
56 	switch (struct_type) {
57 
58 	case T_BIND:
59 		/* LINTED pointer cast */
60 		p.bind = (struct t_bind *)ptr;
61 		if (p.bind->addr.buf != NULL)
62 			free(p.bind->addr.buf);
63 		break;
64 
65 	case T_CALL:
66 		/* LINTED pointer cast */
67 		p.call = (struct t_call *)ptr;
68 		if (p.call->addr.buf != NULL)
69 			free(p.call->addr.buf);
70 		if (p.call->opt.buf != NULL)
71 			free(p.call->opt.buf);
72 		if (p.call->udata.buf != NULL)
73 			free(p.call->udata.buf);
74 		break;
75 
76 	case T_OPTMGMT:
77 		/* LINTED pointer cast */
78 		p.opt = (struct t_optmgmt *)ptr;
79 		if (p.opt->opt.buf != NULL)
80 			free(p.opt->opt.buf);
81 		break;
82 
83 	case T_DIS:
84 		/* LINTED pointer cast */
85 		p.dis = (struct t_discon *)ptr;
86 		if (p.dis->udata.buf != NULL)
87 			free(p.dis->udata.buf);
88 		break;
89 
90 	case T_UNITDATA:
91 		/* LINTED pointer cast */
92 		p.udata = (struct t_unitdata *)ptr;
93 		if (p.udata->addr.buf != NULL)
94 			free(p.udata->addr.buf);
95 		if (p.udata->opt.buf != NULL)
96 			free(p.udata->opt.buf);
97 		if (p.udata->udata.buf != NULL)
98 			free(p.udata->udata.buf);
99 		break;
100 
101 	case T_UDERROR:
102 		/* LINTED pointer cast */
103 		p.uderr = (struct t_uderr *)ptr;
104 		if (p.uderr->addr.buf != NULL)
105 			free(p.uderr->addr.buf);
106 		if (p.uderr->opt.buf != NULL)
107 			free(p.uderr->opt.buf);
108 		break;
109 
110 	case T_INFO:
111 		break;
112 
113 	default:
114 		if (_T_IS_XTI(api_semantics)) {
115 			t_errno = TNOSTRUCTYPE;
116 		} else {	/* TX_TLI_API */
117 			t_errno = TSYSERR;
118 			errno = EINVAL;
119 		}
120 		return (-1);
121 	}
122 
123 	free(ptr);
124 	return (0);
125 }
126