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
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]
23 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
24 /* All Rights Reserved */
28 * Copyright (c) 1997, by Sun Microsystems, Inc.
29 * All rights reserved.
33 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
35 #include <sys/types.h>
41 #define DEFMSG "ERROR: "
42 #define MS sizeof (DEFMSG)
43 #define INVINP "invalid input"
46 puterror(FILE *fp
, char *defmesg
, char *error
)
52 /* use default message since no error was provided */
53 n
= (defmesg
? strlen(defmesg
) : strlen(INVINP
));
54 tmp
= calloc(MS
+n
+1, sizeof (char));
55 (void) strcpy(tmp
, DEFMSG
);
56 (void) strcat(tmp
, defmesg
? defmesg
: INVINP
);
58 } else if (defmesg
!= NULL
) {
60 if (error
[0] == '~') {
61 /* prepend default message */
62 tmp
= calloc(MS
+n
+strlen(defmesg
)+2, sizeof (char));
63 (void) strcpy(tmp
, DEFMSG
);
64 (void) strcat(tmp
, defmesg
);
65 (void) strcat(tmp
, "\n");
67 (void) strcat(tmp
, error
);
68 } else if (n
&& (error
[n
-1] == '~')) {
69 /* append default message */
70 tmp
= calloc(MS
+n
+strlen(defmesg
)+2, sizeof (char));
71 (void) strcpy(tmp
, DEFMSG
);
72 (void) strcat(tmp
, error
);
73 /* first -1 'cuz sizeof (DEFMSG) includes terminator */
75 (void) strcat(tmp
, "\n");
76 (void) strcat(tmp
, defmesg
);
78 tmp
= calloc(MS
+n
+1, sizeof (char));
79 (void) strcpy(tmp
, DEFMSG
);
80 (void) strcat(tmp
, error
);
84 tmp
= calloc(MS
+n
+1, sizeof (char));
85 (void) strcpy(tmp
, DEFMSG
);
86 (void) strcat(tmp
, error
);
88 (void) puttext(fp
, tmp
, ckindent
, ckwidth
);
89 (void) fputc('\n', fp
);