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
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]
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
27 * Copyright (c) 1997, by Sun Microsystems, Inc.
28 * All rights reserved.
31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
38 * listdgrp() List devices that belong to a device group.
42 * Header files referenced:
43 * <sys/types.h> System Data Types
44 * <errno.h> UNIX and C error definitions
45 * <string.h> String handling definitions
46 * <devmgmt.h> Device management definitions
47 * "devtab.h" Local device table definitions
50 #include <sys/types.h>
63 * Structure definitions:
67 * Local functions referenced
79 * char **listdgrp(dgroup)
82 * List the members of a device group.
85 * char *dgroup The device group needed
88 * A pointer to a list of pointers to char-strings containing
89 * the members of the device group.
92 * - malloc()ed space containing addresses
96 listdgrp(char *dgroup
) /* The device group to list */
99 struct dgrptabent
*dgrpent
; /* Device group description */
100 struct member
*member
; /* Device group member */
101 char **listbuf
; /* Buffer allocated for addrs */
102 char **rtnval
; /* Value to return */
103 char **pp
; /* Running ptr through addrs */
104 int noerror
; /* Flag, TRUE if all's well */
113 * Get the record for this device group
116 if (dgrpent
= _getdgrprec(dgroup
)) {
118 /* Count the number of members in the device group */
120 for (member
= dgrpent
->membership
; member
; member
= member
->next
)
123 /* Get space for the list to return */
124 if (listbuf
= malloc(n
*sizeof (char **))) {
127 * For each member in the device group, add that device
128 * name to the list of devices we're building
133 for (member
= dgrpent
->membership
; noerror
&& member
;
134 member
= member
->next
) {
136 if (*pp
= malloc(strlen(member
->name
)+1))
138 (void) strcpy(*pp
++, member
->name
);
139 else noerror
= FALSE
;
144 * If there's no error, terminate the list we've built.
145 * Otherwise, free the space allocated to the stuff we've built
152 /* Some error occurred. Clean up allocations */
153 for (pp
= listbuf
; *pp
; pp
++) free(*pp
);
158 } /* if (malloc()) */
160 /* Free space alloced to the device group entry */
161 _freedgrptabent(dgrpent
);
163 } /* if (_getdgrprec()) */
167 /* Finished -- wasn't that simple? */