##// END OF EJS Templates
chg: add util function abortmsgerrno to print error with errno...
Jun Wu -
r28788:57a78a64 default
parent child Browse files
Show More
@@ -7,6 +7,7 b''
7 7 * GNU General Public License version 2 or any later version.
8 8 */
9 9
10 #include <errno.h>
10 11 #include <signal.h>
11 12 #include <stdarg.h>
12 13 #include <stdio.h>
@@ -27,18 +28,33 b' static inline void fsetcolor(FILE *fp, c'
27 28 fprintf(fp, "\033[%sm", code);
28 29 }
29 30
31 static void vabortmsgerrno(int no, const char *fmt, va_list args)
32 {
33 fsetcolor(stderr, "1;31");
34 fputs("chg: abort: ", stderr);
35 vfprintf(stderr, fmt, args);
36 if (no != 0)
37 fprintf(stderr, " (errno = %d, %s)", no, strerror(no));
38 fsetcolor(stderr, "");
39 fputc('\n', stderr);
40 exit(255);
41 }
42
30 43 void abortmsg(const char *fmt, ...)
31 44 {
32 45 va_list args;
33 46 va_start(args, fmt);
34 fsetcolor(stderr, "1;31");
35 fputs("chg: abort: ", stderr);
36 vfprintf(stderr, fmt, args);
37 fsetcolor(stderr, "");
38 fputc('\n', stderr);
47 vabortmsgerrno(0, fmt, args);
39 48 va_end(args);
49 }
40 50
41 exit(255);
51 void abortmsgerrno(const char *fmt, ...)
52 {
53 int no = errno;
54 va_list args;
55 va_start(args, fmt);
56 vabortmsgerrno(no, fmt, args);
57 va_end(args);
42 58 }
43 59
44 60 static int debugmsgenabled = 0;
@@ -17,6 +17,7 b''
17 17 #endif
18 18
19 19 void abortmsg(const char *fmt, ...) PRINTF_FORMAT_;
20 void abortmsgerrno(const char *fmt, ...) PRINTF_FORMAT_;
20 21
21 22 void enablecolor(void);
22 23 void enabledebugmsg(void);
General Comments 0
You need to be logged in to leave comments. Login now