xref: /illumos-gate/usr/src/cmd/lp/lib/lp/addlist.c (revision d24234c24aeaca4ca56ee3ac2794507968f274c4)
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 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 #ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.7	*/
27 /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
28 
29 #include "string.h"
30 #include "errno.h"
31 #include "stdlib.h"
32 
33 #include "lp.h"
34 
35 /**
36  ** addlist() - ADD ITEM TO (char **) LIST
37  **/
38 
39 int
40 #if	defined(__STDC__)
41 addlist (
42 	char ***		plist,
43 	char *			item
44 )
45 #else
46 addlist (plist, item)
47 	register char		***plist,
48 				*item;
49 #endif
50 {
51 	register char		**pl;
52 
53 	register int		n;
54 
55 	if (*plist) {
56 
57 		n = lenlist(*plist);
58 
59 		for (pl = *plist; *pl; pl++)
60 			if (STREQU(*pl, item))
61 				break;
62 
63 		if (!*pl) {
64 
65 			n++;
66 			*plist = (char **)Realloc(
67 				(char *)*plist,
68 				(n + 1) * sizeof(char *)
69 			);
70 			if (!*plist) {
71 				errno = ENOMEM;
72 				return (-1);
73 			}
74 			(*plist)[n - 1] = Strdup(item);
75 			(*plist)[n] = 0;
76 
77 		}
78 
79 	} else {
80 
81 		*plist = (char **)Malloc(2 * sizeof(char *));
82 		if (!*plist) {
83 			errno = ENOMEM;
84 			return (-1);
85 		}
86 		(*plist)[0] = Strdup(item);
87 		(*plist)[1] = 0;
88 
89 	}
90 
91 	return (0);
92 }
93