added gentoo ebuilds
[libmixp.git] / libmixp / error.c
blobe7e09c1b632eacd05913fe39e7c3fe07cfd12a32
1 #include <errno.h>
2 #include <stdarg.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <9p-mixp/err.h>
6 #include "mixp_local.h"
8 /* Approach to errno handling taken from Plan 9 Port. */
9 enum {
10 EPLAN9 = 0x19283745,
13 FILE* mixp_error_stream = NULL;
14 FILE* mixp_debug_stream = NULL;
16 const char*
17 mixp_errbuf() {
18 char *errbuf;
20 errbuf = mixp_thread->errbuf();
21 if(errno == EINTR)
22 strncpy(errbuf, "interrupted", IXP_ERRMAX);
23 else if(errno != EPLAN9)
24 strncpy(errbuf, strerror(errno), IXP_ERRMAX);
25 return errbuf;
28 void
29 mixp_errstr(char *buf, int n) {
30 char tmp[IXP_ERRMAX];
32 strncpy(tmp, buf, sizeof(tmp));
33 mixp_rerrstr(buf, n);
34 strncpy(mixp_thread->errbuf(), tmp, IXP_ERRMAX);
35 errno = EPLAN9;
38 void
39 mixp_rerrstr(char *buf, int n) {
40 strncpy(buf, mixp_errbuf(), n);
43 void
44 mixp_werrstr(char *fmt, ...) {
45 char tmp[IXP_ERRMAX];
46 va_list ap;
48 va_start(ap, fmt);
49 vsnprintf(tmp, sizeof(tmp), fmt, ap);
50 va_end(ap);
51 strncpy(mixp_thread->errbuf(), tmp, IXP_ERRMAX);
52 errno = EPLAN9;