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 /*
28  * MKS library
29  * Copyright 1985, 1992 by Mortice Kern Systems Inc.  All rights reserved.
30  *
31  */
32 #ifdef M_RCSID
33 #ifndef lint
34 static char rcsID[] = "$Header: /rd/src/libc/gen/rcs/eprintf.c 1.17 1994/06/17 19:42:34 hilary Exp $";
35 #endif
36 #endif
37 
38 #include <mks.h>
39 #include <stdio.h>
40 #include <stdarg.h>
41 #include <errno.h>
42 #include <string.h>
43 
44 char *_cmdname;
45 
46 /*f
47  * print error message followed by errno value.
48  * The value of errno is guaranteed to be restored on exit.
49  */
50 /* VARARGS0 */
51 LDEFN int
52 eprintf VARARG1(const char *, fmt)
53 {
54 	va_list args;
55 	register int saveerrno = errno;
56 	register int nprf = 0;
57 	char *str;
58 
59 	if (_cmdname != NULL)
60 		nprf += fprintf(stderr, "%s: ", _cmdname);
61 	va_start(args, fmt);
62 	nprf += vfprintf(stderr, fmt, args);
63 	va_end(args);
64 	str = strerror(saveerrno);
65 	if (*str == '\0')
66 		nprf += fprintf(stderr, ": error %d\n", saveerrno);
67 	else
68 		nprf += fprintf(stderr,": %s\n", str);
69 	errno = saveerrno;
70 	return (nprf);
71 }
72