8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / lp / lib / forms / putform.c
blobbeaff0822007a1b7a6d58ec1961d5db5da583cec
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
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.10 */
32 /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
34 #include "sys/types.h"
35 #include "sys/stat.h"
36 #include "stdio.h"
37 #include "string.h"
38 #include "errno.h"
39 #include "stdlib.h"
41 #include "lp.h"
42 #include "form.h"
44 /**
45 ** putform() - WRITE FORM STRUCTURE TO DISK FILES
46 **/
48 int
49 putform(char *name, FORM *formp, FALERT *alertp, FILE **p_align_fp)
51 register char * path;
53 int fd;
55 struct stat statbuf;
58 if (!name || !*name) {
59 errno = EINVAL;
60 return (-1);
63 if (STREQU(NAME_ALL, name)) {
64 errno = EINVAL;
65 return (-1);
69 * Create the parent directory for this form
70 * if it doesn't yet exist.
72 if (!(path = getformfile(name, (char *)0)))
73 return (-1);
74 if (Stat(path, &statbuf) == 0) {
75 if (!S_ISDIR(statbuf.st_mode)) {
76 Free (path);
77 errno = ENOTDIR;
78 return (-1);
80 } else if (errno != ENOENT || mkdir_lpdir(path, MODE_DIR) == -1) {
81 Free (path);
82 return (-1);
84 Free (path);
87 * Open the configuration file and write out the form
88 * configuration (?)
90 if (formp) {
91 if (!(path = getformfile(name, DESCRIBE)))
92 return (-1);
93 if ((fd = open_locked(path, "w", MODE_READ)) < 0) {
94 Free (path);
95 return (-1);
97 Free (path);
99 if (wrform(name, formp, fd, 0, (int *)0) == -1) {
100 close(fd);
101 return (-1);
103 close(fd);
107 * Write out the alert condition (?)
109 if (alertp) {
110 if (
111 alertp->shcmd
112 && putalert(Lp_A_Forms, name, alertp) == -1
114 return (-1);
118 * Write out the alignment pattern (?)
120 if (p_align_fp && *p_align_fp) {
122 int size = 0,
125 char buf[BUFSIZ];
128 if (!(path = getformfile(name, ALIGN_PTRN)))
129 return (-1);
130 if ((fd = open_locked(path, "w", MODE_READ)) < 0) {
131 Free (path);
132 return (-1);
135 while ((n = fread(buf, 1, BUFSIZ, *p_align_fp)) != 0) {
136 size += n;
137 write (fd, buf, n);
139 close(fd);
141 if (!size)
142 Unlink(path);
144 Free(path);
147 return (0);