1 /* @(#)gtcomerr.c	1.1 18/06/16 Copyright 1985-1989, 1995-2018 J. Schilling */
2 /*
3  *	Routines for printing command errors
4  *	These routines call gettext() on the message first.
5  *
6  *	Copyright (c) 1985-1989, 1995-2018 J. Schilling
7  */
8 /*
9  * The contents of this file are subject to the terms of the
10  * Common Development and Distribution License, Version 1.0 only
11  * (the "License").  You may not use this file except in compliance
12  * with the License.
13  *
14  * See the file CDDL.Schily.txt in this distribution for details.
15  * A copy of the CDDL is also available via the Internet at
16  * http://www.opensource.org/licenses/cddl1.txt
17  *
18  * When distributing Covered Code, include this CDDL HEADER in each
19  * file and include the License file CDDL.Schily.txt from this distribution.
20  */
21 
22 #include <schily/mconfig.h>
23 #include <schily/unistd.h>	/* include <sys/types.h> try to get size_t */
24 #include <schily/stdio.h>	/* Try again for size_t	*/
25 #include <schily/stdlib.h>	/* Try again for size_t	*/
26 #include <schily/standard.h>
27 #include <schily/varargs.h>
28 #include <schily/string.h>
29 #include <schily/schily.h>
30 #include <schily/errno.h>
31 #include <schily/nlsdefs.h>
32 
33 EXPORT	void	gtcomerr	__PR((const char *, ...));
34 EXPORT	void	gtxcomerr	__PR((int, const char *, ...));
35 EXPORT	void	gtcomerrno	__PR((int, const char *, ...));
36 EXPORT	void	gtxcomerrno	__PR((int, int, const char *, ...));
37 EXPORT	int	gterrmsg	__PR((const char *, ...));
38 EXPORT	int	gterrmsgno	__PR((int, const char *, ...));
39 
40 /*
41  * Fetch current errno, print a related message and exit(errno).
42  */
43 /* VARARGS1 */
44 #ifdef	PROTOTYPES
45 EXPORT void
gtcomerr(const char * msg,...)46 gtcomerr(const char *msg, ...)
47 #else
48 EXPORT void
49 gtcomerr(msg, va_alist)
50 	char	*msg;
51 	va_dcl
52 #endif
53 {
54 	va_list	args;
55 
56 #ifdef	PROTOTYPES
57 	va_start(args, msg);
58 #else
59 	va_start(args);
60 #endif
61 	(void) _comerr(stderr, COMERR_EXIT, 0, geterrno(), _(msg), args);
62 	/* NOTREACHED */
63 	va_end(args);
64 }
65 
66 /*
67  * Fetch current errno, print a related message and exit(exc).
68  */
69 /* VARARGS2 */
70 #ifdef	PROTOTYPES
71 EXPORT void
gtxcomerr(int exc,const char * msg,...)72 gtxcomerr(int exc, const char *msg, ...)
73 #else
74 EXPORT void
75 gtxcomerr(exc, msg, va_alist)
76 	int	exc;
77 	char	*msg;
78 	va_dcl
79 #endif
80 {
81 	va_list	args;
82 
83 #ifdef	PROTOTYPES
84 	va_start(args, msg);
85 #else
86 	va_start(args);
87 #endif
88 	(void) _comerr(stderr, COMERR_EXCODE, exc, geterrno(), _(msg), args);
89 	/* NOTREACHED */
90 	va_end(args);
91 }
92 
93 /*
94  * Print a message related to err and exit(err).
95  */
96 /* VARARGS2 */
97 #ifdef	PROTOTYPES
98 EXPORT void
gtcomerrno(int err,const char * msg,...)99 gtcomerrno(int err, const char *msg, ...)
100 #else
101 EXPORT void
102 gtcomerrno(err, msg, va_alist)
103 	int	err;
104 	char	*msg;
105 	va_dcl
106 #endif
107 {
108 	va_list	args;
109 
110 #ifdef	PROTOTYPES
111 	va_start(args, msg);
112 #else
113 	va_start(args);
114 #endif
115 	(void) _comerr(stderr, COMERR_EXIT, 0, err, _(msg), args);
116 	/* NOTREACHED */
117 	va_end(args);
118 }
119 
120 /*
121  * Print a message related to err and exit(exc).
122  */
123 /* VARARGS3 */
124 #ifdef	PROTOTYPES
125 EXPORT void
gtxcomerrno(int exc,int err,const char * msg,...)126 gtxcomerrno(int exc, int err, const char *msg, ...)
127 #else
128 EXPORT void
129 gtxcomerrno(exc, err, msg, va_alist)
130 	int	exc;
131 	int	err;
132 	char	*msg;
133 	va_dcl
134 #endif
135 {
136 	va_list	args;
137 
138 #ifdef	PROTOTYPES
139 	va_start(args, msg);
140 #else
141 	va_start(args);
142 #endif
143 	(void) _comerr(stderr, COMERR_EXCODE, exc, err, _(msg), args);
144 	/* NOTREACHED */
145 	va_end(args);
146 }
147 
148 /*
149  * Fetch current errno, print a related message and return(errno).
150  */
151 /* VARARGS1 */
152 #ifdef	PROTOTYPES
153 EXPORT int
gterrmsg(const char * msg,...)154 gterrmsg(const char *msg, ...)
155 #else
156 EXPORT int
157 gterrmsg(msg, va_alist)
158 	char	*msg;
159 	va_dcl
160 #endif
161 {
162 	va_list	args;
163 	int	ret;
164 
165 #ifdef	PROTOTYPES
166 	va_start(args, msg);
167 #else
168 	va_start(args);
169 #endif
170 	ret = _comerr(stderr, COMERR_RETURN, 0, geterrno(), _(msg), args);
171 	va_end(args);
172 	return (ret);
173 }
174 
175 /*
176  * Print a message related to err and return(err).
177  */
178 /* VARARGS2 */
179 #ifdef	PROTOTYPES
180 EXPORT int
gterrmsgno(int err,const char * msg,...)181 gterrmsgno(int err, const char *msg, ...)
182 #else
183 EXPORT int
184 gterrmsgno(err, msg, va_alist)
185 	int	err;
186 	char	*msg;
187 	va_dcl
188 #endif
189 {
190 	va_list	args;
191 	int	ret;
192 
193 #ifdef	PROTOTYPES
194 	va_start(args, msg);
195 #else
196 	va_start(args);
197 #endif
198 	ret = _comerr(stderr, COMERR_RETURN, 0, err, _(msg), args);
199 	va_end(args);
200 	return (ret);
201 }
202