dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libadm / common / listdgrp.c
blobfd7747919e592fe834ba5835d04a0c5964e64fac
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
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 */
32 /*LINTLIBRARY*/
35 * listdgrp.c
37 * Contents:
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>
51 #include <errno.h>
52 #include <string.h>
53 #include <stdlib.h>
54 #include <devmgmt.h>
55 #include "devtab.h"
58 * Local definitions
63 * Structure definitions:
67 * Local functions referenced
71 * Global Data
75 * Static Data
79 * char **listdgrp(dgroup)
80 * char *dgroup
82 * List the members of a device group.
84 * Arguments:
85 * char *dgroup The device group needed
87 * Returns: char **
88 * A pointer to a list of pointers to char-strings containing
89 * the members of the device group.
91 * Notes:
92 * - malloc()ed space containing addresses
95 char **
96 listdgrp(char *dgroup) /* The device group to list */
98 /* Automatic data */
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 */
105 int n; /* Counter */
109 * Initializations
113 * Get the record for this device group
116 if (dgrpent = _getdgrprec(dgroup)) {
118 /* Count the number of members in the device group */
119 n = 1;
120 for (member = dgrpent->membership; member; member = member->next)
121 n++;
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
131 pp = listbuf;
132 noerror = TRUE;
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
148 if (noerror) {
149 *pp = NULL;
150 rtnval = listbuf;
151 } else {
152 /* Some error occurred. Clean up allocations */
153 for (pp = listbuf; *pp; pp++) free(*pp);
154 free(listbuf);
155 rtnval = NULL;
158 } /* if (malloc()) */
160 /* Free space alloced to the device group entry */
161 _freedgrptabent(dgrpent);
163 } /* if (_getdgrprec()) */
164 else rtnval = NULL;
167 /* Finished -- wasn't that simple? */
168 return (rtnval);