xref: /illumos-gate/usr/src/cmd/lp/lib/forms/delform.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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.11	*/
27 /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
28 
29 #include "errno.h"
30 #include "sys/types.h"
31 #include "stdlib.h"
32 
33 #include "lp.h"
34 #include "form.h"
35 
36 #if	defined(__STDC__)
37 static int		_delform ( char * );
38 #else
39 static int		_delform();
40 #endif
41 
42 /**
43  ** delform()
44  **/
45 
46 int
47 #if	defined(__STDC__)
delform(char * name)48 delform (
49 	char *			name
50 )
51 #else
52 delform (name)
53 	char			*name;
54 #endif
55 {
56 	long			lastdir;
57 
58 
59 	if (!name || !*name) {
60 		errno = EINVAL;
61 		return (-1);
62 	}
63 
64 	if (STREQU(NAME_ALL, name)) {
65 		lastdir = -1;
66 		while ((name = next_dir(Lp_A_Forms, &lastdir)))
67 			if (_delform(name) == -1)
68 				return (-1);
69 		return (0);
70 	} else
71 		return (_delform(name));
72 }
73 
74 /**
75  ** _delform()
76  **/
77 
78 static int
79 #if	defined(__STDC__)
_delform(char * name)80 _delform (
81 	char *			name
82 )
83 #else
84 _delform (name)
85 	char			*name;
86 #endif
87 {
88 	register char		*path;
89 
90 #define RMFILE(X)	if (!(path = getformfile(name, X))) \
91 				return (-1); \
92 			if (rmfile(path) == -1) { \
93 				Free (path); \
94 				return (-1); \
95 			} \
96 			Free (path)
97 	RMFILE (DESCRIBE);
98 	RMFILE (COMMENT);
99 	RMFILE (ALIGN_PTRN);
100 	RMFILE (ALLOWFILE);
101 	RMFILE (DENYFILE);
102 
103 	delalert (Lp_A_Forms, name);
104 
105 	if (!(path = getformfile(name, (char *)0)))
106 		return (-1);
107 	if (Rmdir(path) == -1) {
108 		Free (path);
109 		return (-1);
110 	}
111 	Free (path);
112 
113 	return (0);
114 }
115