xref: /titanic_51/usr/src/lib/libast/common/uwin/err.c (revision 24fe0b3bf671e123467ce1df0b67cadd3614c8e4)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2008 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #include "FEATURE/uwin"
23 
24 #if !_UWIN
25 
26 void _STUB_err(){}
27 
28 #else
29 
30 #pragma prototyped
31 
32 /*
33  * bsd 4.4 compatibility
34  *
35  * NOTE: errorv(ERROR_NOID) => the first arg is the printf format
36  */
37 
38 #include <ast.h>
39 #include <error.h>
40 
41 #include <windows.h>
42 
43 #ifdef __EXPORT__
44 #define extern	__EXPORT__
45 #endif
46 
47 static void
48 errmsg(int level, int code, const char* fmt, va_list ap)
49 {
50 	if (!error_info.id)
51 	{
52 		struct _astdll*	dp = _ast_getdll();
53 		char*		s;
54 		char*		t;
55 
56 		if (s = dp->_ast__argv[0])
57 		{
58 			if (t = strrchr(s, '/'))
59 				s = t + 1;
60 			error_info.id = s;
61 		}
62 	}
63 	errorv(fmt, level|ERROR_NOID, ap);
64 	if ((level & ERROR_LEVEL) >= ERROR_ERROR)
65 		exit(code);
66 }
67 
68 extern void verr(int code, const char* fmt, va_list ap)
69 {
70 	errmsg(ERROR_ERROR|ERROR_SYSTEM, code, fmt, ap);
71 }
72 
73 extern void err(int code, const char* fmt, ...)
74 {
75 	va_list	ap;
76 
77 	va_start(ap, fmt);
78 	errmsg(ERROR_ERROR|ERROR_SYSTEM, code, fmt, ap);
79 	va_end(ap);
80 }
81 
82 extern void verrx(int code, const char* fmt, va_list ap)
83 {
84 	errmsg(ERROR_ERROR, code, fmt, ap);
85 }
86 
87 extern void errx(int code, const char* fmt, ...)
88 {
89 	va_list	ap;
90 
91 	va_start(ap, fmt);
92 	errmsg(ERROR_ERROR, code, fmt, ap);
93 	va_end(ap);
94 }
95 
96 extern void vwarn(const char* fmt, va_list ap)
97 {
98 	errmsg(ERROR_WARNING|ERROR_SYSTEM, 0, fmt, ap);
99 }
100 
101 extern void warn(const char* fmt, ...)
102 {
103 	va_list	ap;
104 
105 	va_start(ap, fmt);
106 	errmsg(ERROR_WARNING|ERROR_SYSTEM, 0, fmt, ap);
107 	va_end(ap);
108 }
109 
110 extern void vwarnx(const char* fmt, va_list ap)
111 {
112 	errmsg(ERROR_WARNING, 0, fmt, ap);
113 }
114 
115 extern void warnx(const char* fmt, ...)
116 {
117 	va_list	ap;
118 
119 	va_start(ap, fmt);
120 	errmsg(ERROR_WARNING, 0, fmt, ap);
121 	va_end(ap);
122 }
123 
124 #endif
125