xref: /illumos-gate/usr/src/lib/libxcurses/src/libc/mks/m_errorx.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 /*
23  * Copyright (c) 1996, by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * Copyright 1993 by Mortice Kern Systems Inc.  All rights reserved.
31  *
32  */
33 
34 #ifdef M_RCSID
35 #ifndef lint
36 static char rcsID[] = "$Id: m_errorx.c 1.9 1995/02/08 15:03:16 rob Exp $";
37 #endif
38 #endif
39 
40 #include <mks.h>
41 #include <errno.h>
42 #include <string.h>
43 
44 #ifndef	ERRORFN
45 
46 #define	ERRORFN	m_errorexit
47 #define	DONE	exit(1)
48 
49 /* Default error msg routine in library */
50 M_ERROR(m_errorexit);
51 
52 #endif	/* ERRORFN */
53 
54 /*f
55  * Print error message with command name and trailing newline.
56  * Leading ! indicates format errno on the end.
57  * The value of errno is restored on completion.
58  */
59 void
60 ERRORFN(const char *fmt, va_list args)
61 {
62 	int saveerrno = errno;
63 	int syserr = 0;
64 
65 	if (_cmdname != NULL)
66 		fprintf(stderr, "%s: ", _cmdname);
67 	fmt = m_strmsg(fmt);
68 	if (*fmt == '!') {
69 		fmt++;
70 		syserr++;
71 	}
72 	vfprintf(stderr, fmt, args);
73 	if (syserr) {
74 		char *str;
75 
76 		/* Do eprintf-like stuff */
77 		str = strerror(saveerrno);
78 		if (*str == '\0')
79 			fprintf(stderr, ": errno = %d", saveerrno);
80 		else
81 			fprintf(stderr,": %s", str);
82 	}
83 	fputc('\n', stderr);
84 	errno = saveerrno;
85 	DONE;
86 }
87 
88 
89