2 * This file has been modified for the cdrkit suite.
4 * The behaviour and appearence of the program code below can differ to a major
5 * extent from the version distributed by the original author(s).
7 * For details, see Changelog file distributed with the cdrkit package. If you
8 * received this file from another source then ask the distributing person for
9 * a log of modifications.
13 /* @(#)comerr.c 1.29 03/06/15 Copyright 1985-1989, 1995-2003 J. Schilling */
15 * Routines for printing command errors
17 * Copyright (c) 1985-1989, 1995-2003 J. Schilling
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License version 2
22 * as published by the Free Software Foundation.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License along with
30 * this program; see the file COPYING. If not, write to the Free Software
31 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 #include <unixstd.h> /* include <sys/types.h> try to get size_t */
36 #include <stdio.h> /* Try again for size_t */
37 #include <stdxlib.h> /* Try again for size_t */
44 extern char *sys_errlist[];
48 EXPORT int on_comerr __PR((void (*fun)(int, void *), void *arg));
49 EXPORT void comerr __PR((const char *, ...));
50 EXPORT void comerrno __PR((int, const char *, ...));
51 EXPORT int errmsg __PR((const char *, ...));
52 EXPORT int errmsgno __PR((int, const char *, ...));
53 LOCAL int _comerr __PR((int, int, const char *, va_list));
54 EXPORT void comexit __PR((int));
55 EXPORT char *errmsgstr __PR((int));
59 void (*func) __PR((int, void *));
67 void (*func) __PR((int, void *));
72 fp = malloc(sizeof (*fp));
86 comerr(const char *msg, ...)
101 (void) _comerr(TRUE, geterrno(), msg, args);
109 comerrno(int err, const char *msg, ...)
112 comerrno(err, msg, va_alist)
125 (void) _comerr(TRUE, err, msg, args);
133 errmsg(const char *msg, ...)
136 errmsg(msg, va_alist)
149 ret = _comerr(FALSE, geterrno(), msg, args);
157 errmsgno(int err, const char *msg, ...)
160 errmsgno(err, msg, va_alist)
174 ret = _comerr(FALSE, err, msg, args);
181 * On BeOS errno is a big negative number (0x80000000 + small number).
182 * We assume that small negative numbers are safe to be used as special
183 * values that prevent printing the errno text.
185 * We tried to use #if EIO < 0 but this does not work because EIO is
186 * defined to a enum. ENODEV may work as ENODEV is defined to a number
189 #define silent_schily_error(e) ((e) < 0 && (e) >= -1024)
192 * On UNIX errno is a small non-negative number, so we assume that
193 * negative values cannot be a valid errno and don't print the error
194 * string in this case. However the value may still be used as exit()
195 * code if 'exflg' is set.
197 #define silent_schily_error(e) ((e) < 0)
200 _comerr(exflg, err, msg, args)
208 char *prognam = get_progname();
210 if (silent_schily_error(err)) {
211 fprintf(stderr, "%s: ", prognam);
212 vfprintf(stderr, msg, args);
214 errnam = errmsgstr(err);
215 if (errnam == NULL) {
216 (void) snprintf(errbuf, sizeof (errbuf),
220 fprintf(stderr, "%s: %s. ", prognam, errnam);
221 vfprintf(stderr, msg, args);
235 (*exfuncs->func)(err, exfuncs->arg);
236 exfuncs = exfuncs->next;
248 * POSIX compliance may look strange...
250 int errsav = geterrno();
258 if (ret == NULL || err)
262 if (err < 0 || err >= sys_nerr) {
265 return (sys_errlist[err]);