|
|
1.1 root 1: #include <stdlib.h>
2: #include <string.h>
3: #include <stdio.h>
4: #include <stdarg.h>
5: #include <errno.h>
6: #include <mach/mach.h>
7: #include <mach/mach_error.h>
8:
9: #include "stuff/errors.h"
10:
11: unsigned long errors = 0; /* number of calls to error() */
12:
13: /*
14: * Just print the message in the standard format without setting an error.
15: */
16: void
17: warning(
18: const char *format,
19: ...)
20: {
21: va_list ap;
22:
23: va_start(ap, format);
24: fprintf(stderr, "%s: ", progname);
25: vfprintf(stderr, format, ap);
26: fprintf(stderr, "\n");
27: va_end(ap);
28: }
29:
30: /*
31: * Print the error message and return to the caller after setting the error
32: * indication.
33: */
34: void
35: error(
36: const char *format,
37: ...)
38: {
39: va_list ap;
40:
41: va_start(ap, format);
42: fprintf(stderr, "%s: ", progname);
43: vfprintf(stderr, format, ap);
44: fprintf(stderr, "\n");
45: va_end(ap);
46: errors++;
47: }
48:
49: /*
50: * Print the error message, the architecture if not NULL and return to the
51: * caller after setting the error indication.
52: */
53: void
54: error_with_arch(
55: const char *arch_name,
56: const char *format,
57: ...)
58: {
59: va_list ap;
60:
61: va_start(ap, format);
62: fprintf(stderr, "%s: ", progname);
63: if(arch_name != NULL)
64: fprintf(stderr, "for architecture: %s ", arch_name);
65: vfprintf(stderr, format, ap);
66: fprintf(stderr, "\n");
67: va_end(ap);
68: errors++;
69: }
70:
71: /*
72: * Print the error message along with the system error message and return to
73: * the caller after setting the error indication.
74: */
75: void
76: system_error(
77: const char *format,
78: ...)
79: {
80: va_list ap;
81:
82: va_start(ap, format);
83: fprintf(stderr, "%s: ", progname);
84: vfprintf(stderr, format, ap);
85: fprintf(stderr, " (%s)\n", strerror(errno));
86: va_end(ap);
87: errors++;
88: }
89:
90: /*
91: * Print the error message along with the mach error string.
92: */
93: void
94: my_mach_error(
95: kern_return_t r,
96: char *format,
97: ...)
98: {
99: va_list ap;
100:
101: va_start(ap, format);
102: fprintf(stderr, "%s: ", progname);
103: vfprintf(stderr, format, ap);
104: fprintf(stderr, " (%s)\n", mach_error_string(r));
105: va_end(ap);
106: errors++;
107: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.