Only clear portion of framebuffer that's actually used (clearing 256MB
[cake.git] / tools / toollib / error.c
blobe79c8037b0b8a19141c89e3f929013b64d82bcfe
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <stdio.h>
7 #include <errno.h>
8 #include <string.h>
9 #include <toollib/error.h>
11 void
12 Error (const char * fmt, ...)
14 va_list args;
15 VA_START (args, fmt);
16 fprintf (stderr, "Error: ");
17 vfprintf (stderr, fmt, args);
18 fprintf (stderr, "\n");
19 va_end (args);
22 void
23 Warn (const char * fmt, ...)
25 va_list args;
26 VA_START (args, fmt);
27 fprintf (stderr, "Warning: ");
28 vfprintf (stderr, fmt, args);
29 fprintf (stderr, "\n");
30 va_end (args);
33 void
34 StdError (const char * fmt, ...)
36 va_list args;
37 VA_START (args, fmt);
38 fprintf (stderr, "Error: ");
39 vfprintf (stderr, fmt, args);
40 fprintf (stderr, ": %s\n", strerror (errno));
41 va_end (args);
44 void
45 StdWarn (const char * fmt, ...)
47 va_list args;
48 VA_START (args, fmt);
49 fprintf (stderr, "Warning: ");
50 vfprintf (stderr, fmt, args);
51 fprintf (stderr, ": %s\n", strerror (errno));
52 va_end (args);
55 static int ErrorSP = 0;
56 static char * ErrorStack[32];
58 void
59 PushMsg (const char * pre, const char * fmt, va_list args, const char * post)
61 char buffer[256];
62 int len, rest;
64 strcpy (buffer, pre);
65 len = strlen (buffer);
66 strcpy (buffer+len, ": ");
67 len += 2;
69 rest = sizeof (buffer) - len;
71 #ifdef HAVE_VSNPRINTF
72 len = vsnprintf (buffer+len, rest, fmt, args);
73 #else
74 len = vsprintf (buffer+len, fmt, args);
75 #endif
77 rest -= len;
79 if (post)
81 len = strlen (post);
83 if (rest >= 2)
85 strcat (buffer, ": ");
86 rest -= 2;
89 if (len < rest)
91 strcpy (buffer + sizeof(buffer) - rest, post);
93 else
95 strncpy (buffer + sizeof(buffer) - rest, post, rest-1);
96 buffer[sizeof (buffer) - 1] = 0;
100 ErrorStack[ErrorSP++] = xstrdup (buffer);
103 void
104 PrintErrorStack (void)
106 while (ErrorSP--)
107 fprintf (stderr, "%s\n", ErrorStack[ErrorSP]);
109 ErrorSP = 0;
112 void
113 ClearErrorStack (void)
115 ErrorSP = 0;
118 void
119 PushError (const char * fmt, ...)
121 va_list args;
122 VA_START (args, fmt);
123 PushMsg ("Error", fmt, args, NULL);
124 va_end (args);
127 void
128 PushWarn (const char * fmt, ...)
130 va_list args;
131 VA_START (args, fmt);
132 PushMsg ("Warning", fmt, args, NULL);
133 va_end (args);
136 void
137 PushStdError (const char * fmt, ...)
139 va_list args;
140 VA_START (args, fmt);
141 PushMsg ("Error", fmt, args, strerror (errno));
142 va_end (args);
145 void
146 PushStdWarn (const char * fmt, ...)
148 va_list args;
149 VA_START (args, fmt);
150 PushMsg ("Warning", fmt, args, strerror (errno));
151 va_end (args);
154 void
155 ErrorExit (int ec)
157 PrintErrorStack ();
159 exit (ec);