dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / dfs.cmds / sharemgr / shareutil.c
blobd164a562387f4b5a34e0d78267843102a312fb27
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/types.h>
30 #include "sharemgr.h"
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <string.h>
36 * Utility functions shared by sharemgr and sharectl.
40 * add_opt(optlist, optarg, security?)
41 * Add a new parsed option to the option list provided.
42 * If the option is a security option, only add if we are
43 * processing security options.
45 int
46 add_opt(struct options **optlistp, char *optarg, int unset)
48 struct options *newopt, *tmp, *optlist;
49 char *optname;
50 char *optvalue;
52 optlist = *optlistp;
53 newopt = (struct options *)malloc(sizeof (struct options));
54 if (newopt == NULL)
55 return (OPT_ADD_MEMORY);
57 /* extract property/value pair */
58 optname = optarg;
59 if (!unset) {
60 optvalue = strchr(optname, '=');
61 if (optvalue == NULL) {
62 free(newopt);
63 return (OPT_ADD_SYNTAX);
65 *optvalue++ = '\0'; /* separate the halves */
66 } else {
67 optvalue = NULL;
70 newopt->optname = optname;
71 newopt->optvalue = optvalue;
72 newopt->next = NULL;
73 if (optlist == NULL) {
74 optlist = newopt;
75 } else {
76 for (tmp = optlist; tmp->next != NULL;
77 tmp = tmp->next) {
79 * Check to see if this is a duplicate
80 * value. We want to replace the first
81 * instance with the second.
83 if (strcmp(tmp->optname, optname) == 0) {
84 tmp->optvalue = optvalue;
85 free(newopt);
86 goto done;
89 tmp->next = newopt;
91 done:
92 *optlistp = optlist;
93 return (OPT_ADD_OK);