ReactOS 0.4.15-dev-8138-g1e75ea8
comerr.c File Reference
#include <schily/mconfig.h>
#include <schily/unistd.h>
#include <schily/stdio.h>
#include <schily/stdlib.h>
#include <schily/standard.h>
#include <schily/varargs.h>
#include <schily/string.h>
#include <schily/schily.h>
#include <schily/errno.h>
Include dependency graph for comerr.c:

Go to the source code of this file.

Classes

struct  ex
 

Macros

#define silent_error(e)   ((e) < 0)
 

Typedefs

typedef struct ex ex_t
 

Functions

EXPORT int on_comerr __PR ((void(*fun)(int, void *), void *arg))
 
EXPORT void comerr __PR ((const char *,...))
 
EXPORT void xcomerr __PR ((int, const char *,...))
 
EXPORT void xcomerrno __PR ((int, int, const char *,...))
 
EXPORT int _comerr __PR ((FILE *, int, int, int, const char *, va_list))
 
LOCAL int _ex_clash __PR ((int))
 
EXPORT int on_comerr (void *func, void *arg)
 
EXPORT void comerr (char *msg, va_alist)
 
EXPORT void xcomerr (int exc, char *msg, va_alist)
 
EXPORT void comerrno (int err, char *msg, va_alist)
 
EXPORT void xcomerrno (int exc, int err, char *msg, va_alist)
 
EXPORT int errmsg (char *msg, va_alist)
 
EXPORT int errmsgno (int err, char *msg, va_alist)
 
EXPORT int _comerr (FILE *f, int exflg, int exc, int err, const char *msg, va_list args)
 
LOCAL int _ex_clash (int exc)
 
EXPORT void comexit (int err)
 
EXPORT charerrmsgstr (int err)
 

Variables

LOCAL ex_texfuncs
 

Macro Definition Documentation

◆ silent_error

#define silent_error (   e)    ((e) < 0)

Definition at line 256 of file comerr.c.

Typedef Documentation

◆ ex_t

typedef struct ex ex_t

Function Documentation

◆ __PR() [1/6]

EXPORT void comerr __PR ( (const char *,...)  )

◆ __PR() [2/6]

EXPORT int _comerr __PR ( (FILE *, int, int, int, const char *, va_list )

◆ __PR() [3/6]

LOCAL int _ex_clash __PR ( (int )

◆ __PR() [4/6]

EXPORT void xcomerr __PR ( (int, const char *,...)  )

◆ __PR() [5/6]

EXPORT void xcomerrno __PR ( (int, int, const char *,...)  )

◆ __PR() [6/6]

EXPORT int on_comerr __PR ( (void(*fun)(int, void *), void *arg )

◆ _comerr()

EXPORT int _comerr ( FILE f,
int  exflg,
int  exc,
int  err,
const char msg,
va_list  args 
)

Definition at line 259 of file comerr.c.

266{
267 char errbuf[20];
268 char *errnam;
269 char *prognam = get_progname();
270
271 if (silent_error(err)) {
272 js_fprintf(f, "%s: %r", prognam, msg, args);
273 } else {
274 errnam = errmsgstr(err);
275 if (errnam == NULL) {
276 (void) js_snprintf(errbuf, sizeof (errbuf),
277 "Error %d", err);
278 errnam = errbuf;
279 }
280 js_fprintf(f, "%s: %s. %r", prognam, errnam, msg, args);
281 }
282 if (exflg) {
283 if (exflg & COMERR_EXCODE)
284 err = exc;
285 else
286 err = _ex_clash(err);
287 comexit(err);
288 /* NOTREACHED */
289 }
290 return (err);
291}
#define msg(x)
Definition: auth_time.c:54
EXPORT char * errmsgstr(int err)
Definition: comerr.c:352
LOCAL int _ex_clash(int exc)
Definition: comerr.c:294
#define silent_error(e)
Definition: comerr.c:256
EXPORT void comexit(int err)
Definition: comerr.c:331
#define NULL
Definition: types.h:112
GLfloat f
Definition: glext.h:7540
EXPORT int js_fprintf(FILE *file, char *form, va_alist)
Definition: jsprintf.c:71
EXPORT int js_snprintf(char *buf, unsigned maxcnt, char *form, va_alist)
Definition: jssnprintf.c:62
#define err(...)
EXPORT char * get_progname()
Definition: saveargs.c:151
Definition: match.c:390

Referenced by comerr(), comerrno(), errmsg(), errmsgno(), xcomerr(), and xcomerrno().

◆ _ex_clash()

LOCAL int _ex_clash ( int  exc)

Definition at line 294 of file comerr.c.

296{
297 int exmod = exc % 256;
298
299 /*
300 * On a recent POSIX System that supports waitid(), siginfo.si_status
301 * holds the exit(2) value as an int. So if waitid() is used to wait
302 * for the process, we do not have problems from folded exit codes.
303 * All other wait*() functions fold the exit code by masking it
304 * with 0377.
305 *
306 * Exit codes used with comerr*()/comexit() are frequently errno values
307 * that have been in the range 0..31 with UNIX.V5 in the mid 1970s and
308 * that now are in the range 0..151 on Solaris. These values do not
309 * cause problems from folding to 8 bits, but "sysexits.h" contains
310 * definitions in the range 64..79 that cause (even unfolded) clashes
311 * with errno values.
312 *
313 * To avoid clashes with errno values, "schily/standard.h" defines
314 * EX_BAD (-1) as default error exit code and
315 * EX_CLASH (-64) as marker for clashes.
316 * Exit codes in the range -2..-63 (254..193 seen as unsigned two's
317 * complement) are available as software specific exit codes.
318 * We map all other negative exit codes to EX_CLASH if they would fold
319 * to -2..-63.
320 */
321 if (exc != exmod && exmod <= 0 && exmod >= EX_CLASH)
322 exc = EX_CLASH;
323 return (exc);
324}
#define EX_CLASH
Definition: standard.h:63

Referenced by _comerr().

◆ comerr()

EXPORT void comerr ( char msg,
va_alist   
)

Definition at line 84 of file comerr.c.

88{
90
91#ifdef PROTOTYPES
93#else
95#endif
96 (void) _comerr(stderr, COMERR_EXIT, 0, geterrno(), msg, args);
97 /* NOTREACHED */
98 va_end(args);
99}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
EXPORT int _comerr(FILE *f, int exflg, int exc, int err, const char *msg, va_list args)
Definition: comerr.c:259
EXPORT int geterrno()
Definition: geterrno.c:34
#define stderr
Definition: stdio.h:100
#define args
Definition: format.c:66

Referenced by e_malloc(), e_strdup(), errconfig(), fill_boot_desc(), gen_add_list(), genboot_write(), get_graft(), get_ldate(), main(), merge_isofs(), readsecs(), scan_sparc_boot(), scan_sunx86_boot(), sunboot_write(), sunlabel_write(), and xfwrite().

◆ comerrno()

◆ comexit()

EXPORT void comexit ( int  err)

Definition at line 331 of file comerr.c.

333{
334 while (exfuncs) {
335 ex_t *fp;
336
337 (*exfuncs->func)(err, exfuncs->arg);
338 fp = exfuncs;
340 free(fp);
341 }
342 exit(err);
343 /* NOTREACHED */
344}
LOCAL ex_t * exfuncs
Definition: comerr.c:50
#define free
Definition: debug_ros.c:5
#define exit(n)
Definition: config.h:202
Definition: comerr.c:44
struct ex * next
Definition: comerr.c:45
void * arg
Definition: comerr.c:47

Referenced by ___malloc(), ___realloc(), _comerr(), errabort(), and main().

◆ errmsg()

EXPORT int errmsg ( char msg,
va_alist   
)

Definition at line 192 of file comerr.c.

196{
198 int ret;
199
200#ifdef PROTOTYPES
201 va_start(args, msg);
202#else
203 va_start(args);
204#endif
205 ret = _comerr(stderr, COMERR_RETURN, 0, geterrno(), msg, args);
206 va_end(args);
207 return (ret);
208}
int ret

Referenced by ___malloc(), ___realloc(), cmd_type(), DoTypeFile(), gen_add_match(), generate_xa_rr_attributes(), get_module_version(), insert_file_entry(), main(), read_rcfile(), scan_directory_tree(), write_one_file(), and xmlFatalErr().

◆ errmsgno()

◆ errmsgstr()

EXPORT char * errmsgstr ( int  err)

Definition at line 352 of file comerr.c.

354{
355#ifdef HAVE_STRERROR
356 /*
357 * POSIX compliance may look strange...
358 */
359 int errsav = geterrno();
360 char *ret;
361
362 seterrno(0);
363 ret = strerror(err);
364 err = geterrno();
365 seterrno(errsav);
366
367 if (ret == NULL || err)
368 return (NULL);
369 return (ret);
370#else
371 if (err < 0 || err >= sys_nerr) {
372 return (NULL);
373 } else {
374 return (sys_errlist[err]);
375 }
376#endif
377}
#define sys_errlist
Definition: stdlib.h:1346
#define sys_nerr
Definition: stdlib.h:1347
const char * strerror(int err)
Definition: compat_str.c:23
EXPORT int seterrno(int err)
Definition: seterrno.c:34

Referenced by _comerr().

◆ on_comerr()

EXPORT int on_comerr ( void func,
void arg 
)

Definition at line 58 of file comerr.c.

61{
62 ex_t *fp;
63
64 fp = malloc(sizeof (*fp));
65 if (fp == NULL)
66 return (-1);
67
68 fp->func = func;
69 fp->arg = arg;
70 fp->next = exfuncs;
71 exfuncs = fp;
72 return (0);
73}
#define malloc
Definition: debug_ros.c:4
GLenum func
Definition: glext.h:6028
void * arg
Definition: msvc.h:10

◆ xcomerr()

EXPORT void xcomerr ( int  exc,
char msg,
va_alist   
)

Definition at line 110 of file comerr.c.

115{
117
118#ifdef PROTOTYPES
119 va_start(args, msg);
120#else
121 va_start(args);
122#endif
123 (void) _comerr(stderr, COMERR_EXCODE, exc, geterrno(), msg, args);
124 /* NOTREACHED */
125 va_end(args);
126}

◆ xcomerrno()

EXPORT void xcomerrno ( int  exc,
int  err,
char msg,
va_alist   
)

Definition at line 164 of file comerr.c.

170{
172
173#ifdef PROTOTYPES
174 va_start(args, msg);
175#else
176 va_start(args);
177#endif
178 (void) _comerr(stderr, COMERR_EXCODE, exc, err, msg, args);
179 /* NOTREACHED */
180 va_end(args);
181}

Variable Documentation

◆ exfuncs

LOCAL ex_t* exfuncs

Definition at line 50 of file comerr.c.

Referenced by comexit().