xref: /onnv-gate/usr/src/cmd/eeprom/common/error.c (revision 13093:48f2dbca79a2)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*13093SRoger.Faulkner@Oracle.COM  * Common Development and Distribution License (the "License").
6*13093SRoger.Faulkner@Oracle.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate 
220Sstevel@tonic-gate /*
23*13093SRoger.Faulkner@Oracle.COM  * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #include <stdio.h>
270Sstevel@tonic-gate #include <stdarg.h>
280Sstevel@tonic-gate #include <errno.h>
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #define	NO_PERROR	0
310Sstevel@tonic-gate #define	PERROR		1
320Sstevel@tonic-gate 
330Sstevel@tonic-gate char *progname;
340Sstevel@tonic-gate 
350Sstevel@tonic-gate void
setpname(char * name)36*13093SRoger.Faulkner@Oracle.COM setpname(char *name)
370Sstevel@tonic-gate {
380Sstevel@tonic-gate 	register char *p = name, c;
390Sstevel@tonic-gate 
400Sstevel@tonic-gate 	if (p)
410Sstevel@tonic-gate 		while (c = *p++)
420Sstevel@tonic-gate 			if (c == '/')
430Sstevel@tonic-gate 				name = p;
440Sstevel@tonic-gate 
450Sstevel@tonic-gate 	progname = name;
460Sstevel@tonic-gate }
470Sstevel@tonic-gate 
480Sstevel@tonic-gate /* _error([no_perror, ] fmt [, arg ...]) */
490Sstevel@tonic-gate /*VARARGS*/
500Sstevel@tonic-gate int
_error(int do_perror,char * fmt,...)510Sstevel@tonic-gate _error(int do_perror, char *fmt, ...)
520Sstevel@tonic-gate {
530Sstevel@tonic-gate 	int saved_errno;
540Sstevel@tonic-gate 	va_list ap;
550Sstevel@tonic-gate 
560Sstevel@tonic-gate 	saved_errno = errno;
570Sstevel@tonic-gate 
580Sstevel@tonic-gate 	/*
590Sstevel@tonic-gate 	 * flush all buffers
600Sstevel@tonic-gate 	 */
610Sstevel@tonic-gate 	(void) fflush(NULL);
620Sstevel@tonic-gate 	if (progname)
630Sstevel@tonic-gate 		(void) fprintf(stderr, "%s: ", progname);
640Sstevel@tonic-gate 
650Sstevel@tonic-gate 	va_start(ap, fmt);
660Sstevel@tonic-gate 	(void) vfprintf(stderr, fmt, ap);
670Sstevel@tonic-gate 	va_end(ap);
680Sstevel@tonic-gate 
690Sstevel@tonic-gate 	if (do_perror == NO_PERROR)
700Sstevel@tonic-gate 		(void) fprintf(stderr, "\n");
710Sstevel@tonic-gate 	else {
720Sstevel@tonic-gate 		(void) fprintf(stderr, ": ");
730Sstevel@tonic-gate 		errno = saved_errno;
740Sstevel@tonic-gate 		perror("");
750Sstevel@tonic-gate 	}
760Sstevel@tonic-gate 
770Sstevel@tonic-gate 	return (1);
780Sstevel@tonic-gate }
79