void vtlogvprint(VtLog *l, char *fmt, va_list arg) { int n; char *p; VtLogChunk *c; if(l == nil) return; qlock(&l->lk); c = l->w; n = c->ep - c->wp; if(n < 512){ c++; if(c == l->chunk+l->nchunk) c = l->chunk; c->wp = c->p; l->w = c; } p = vseprint(c->wp, c->ep, fmt, arg); if(p) c->wp = p; qunlock(&l->lk); }
void panic(char *fmt, ...) { int n; va_list arg; char buf[PRINTSIZE]; strcpy(buf, "panic: "); va_start(arg, fmt); n = vseprint(buf+7, buf+sizeof(buf), fmt, arg) - buf; va_end(arg); buf[n] = '\n'; consputs(buf, n+1); //floppymemwrite(); splhi(); for(;;); if(etherdetach) etherdetach(); if(sddetach) sddetach(); consputs("\nPress almost any key to reset...", 32); spllo(); while(consiq.getc(&consiq) == -1) ; warp86(nil, 0); }
void panic(char *fmt, ...) { int n; Mpl pl; va_list arg; char buf[PRINTSIZE]; consdevs[1].q = nil; /* don't try to write to /dev/kprint */ if(panicking) for(;;); panicking = 1; pl = splhi(); seprint(buf, buf+sizeof buf, "panic: cpu%d: ", machp()->machno); va_start(arg, fmt); n = vseprint(buf+strlen(buf), buf+sizeof(buf), fmt, arg) - buf; va_end(arg); iprint("%s\n", buf); if(consdebug) (*consdebug)(); splx(pl); //prflush(); buf[n] = '\n'; putstrn(buf, n+1); //dumpstack(); delay(1000); /* give time to consoles */ die("wait forever"); exit(1); }
int iprint(char *fmt, ...) { Mpl pl; int i, n, locked; va_list arg; char buf[PRINTSIZE]; pl = splhi(); va_start(arg, fmt); n = vseprint(buf, buf+sizeof(buf), fmt, arg) - buf; va_end(arg); locked = iprintcanlock(&iprintlock); for(i = 0; i < nconsdevs; i++) if((consdevs[i].flags&Ciprint) != 0){ if(consdevs[i].q != nil) qiwrite(consdevs[i].q, buf, n); else consdevs[i].fn(buf, n); } if(locked) unlock(&iprintlock); splx(pl); return n; }
void error(char *fmt, ...) { int i; char buf[2048]; va_list arg; /* Unstack io channels */ if(iop != 0) { for(i = 1; i < iop; i++) Bterm(io[i]); bout = io[0]; iop = 0; } ret = 0; gotint = 0; Bflush(bout); if(silent) silent = 0; else { va_start(arg, fmt); vseprint(buf, buf+sizeof(buf), fmt, arg); va_end(arg); fprint(2, "%L: (error) %s\n", buf); } while(popio()) ; interactive = 1; longjmp(err, 1); }
void error(char *title, char *fmt, ...) { va_list arg; char buf[1024], *out; va_start(arg, fmt); out = vseprint(buf, buf+sizeof(buf), fmt, arg); va_end(arg); *out = 0; hprint(hout, "%s 404 %s\r\n", hversion, title); hprint(hout, "Date: %D\r\n", time(nil)); hprint(hout, "Server: Plan9\r\n"); hprint(hout, "Content-type: text/html\r\n"); hprint(hout, "\r\n"); doctype(); hprint(hout, "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"); hprint(hout, "<head><title>%s</title></head>\n", title); hprint(hout, "<body>\n"); hprint(hout, "<h1>%s</h1>\n", title); hprint(hout, "%s\n", buf); hprint(hout, "</body>\n"); hprint(hout, "</html>\n"); hflush(hout); writelog(connect, "Reply: 404\nReason: %s\n", title); exits(nil); }
int pprint(char *fmt, ...) { Proc *up = externup(); int n; Chan *c; va_list arg; char buf[2*PRINTSIZE]; if(up == nil || up->fgrp == nil) return 0; c = up->fgrp->fd[2]; if(c==0 || (c->mode!=OWRITE && c->mode!=ORDWR)) return 0; n = snprint(buf, sizeof buf, "%s %d: ", up->text, up->pid); va_start(arg, fmt); n = vseprint(buf+n, buf+sizeof(buf), fmt, arg) - buf; va_end(arg); if(waserror()) return 0; c->dev->write(c, buf, n, c->offset); poperror(); lock(&c->r.l); c->offset += n; unlock(&c->r.l); return n; }
void panic(char *fmt, ...) { int s; va_list arg; char buf[PRINTSIZE]; kprintoq = nil; /* don't try to write to /dev/kprint */ if(panicking) for(;;); panicking = 1; s = splhi(); strcpy(buf, "panic: "); va_start(arg, fmt); vseprint(buf+strlen(buf), buf+sizeof(buf), fmt, arg); va_end(arg); iprint("%s\n", buf); if(consdebug) (*consdebug)(); splx(s); prflush(); dumpstack(); if(!cpuserver) for(;;); exit(1); }
static void bprint(Instr *i, char *fmt, ...) { va_list arg; va_start(arg, fmt); i->curr = vseprint(i->curr, i->end, fmt, arg); va_end(arg); }
void testvseprint(char *buf, int n, char *fmt, ...) { va_list arg; va_start(arg, fmt); vseprint(buf, buf+n, fmt, arg); va_end(arg); }
void printerr(char *type, char *fmt, va_list argl) { char buf[1024]; if(!eof)fprint(errorf,"%d: ",yyline); fprint(errorf,"(%s) ", type); vseprint(buf, buf+sizeof(buf), fmt, argl); fprint(errorf, "%s\n", buf); }
void werrstr(char *fmt, ...) { va_list arg; va_start(arg, fmt); vseprint(errstring, errstring+sizeof(errstring), fmt, arg); va_end(arg); SetLastError(Magic); }
char* seprint(char *buf, char *e, char *fmt, ...) { char *p; va_list args; va_start(args, fmt); p = vseprint(buf, e, fmt, args); va_end(args); return p; }
void mchat(char *fmt, ...) { char buf[SIZE], *out; va_list arg; va_start(arg, fmt); out = vseprint(buf, buf+sizeof(buf), fmt, arg); va_end(arg); write(2, buf, (long)(out-buf)); }
void cprint(char *fmt, ...) { char buf[SIZE], *out; va_list arg; va_start(arg, fmt); out = vseprint(buf, buf+SIZE, fmt, arg); va_end(arg); write(cmdfd, buf, (long)(out-buf)); }
void werrstr(char *fmt, ...) { va_list arg; char buf[ERRMAX]; va_start(arg, fmt); vseprint(buf, buf+sizeof(buf), fmt, arg); va_end(arg); kstrcpy(up->env->errstr, buf, ERRMAX); }
int snprint(char *s, int n, char *fmt, ...) { va_list arg; va_start(arg, fmt); n = vseprint(s, s+n, fmt, arg) - s; va_end(arg); return n; }
void dprint(char *z, ...) { char buf[BLOCKSIZE]; va_list arg; va_start(arg, z); vseprint(buf, &buf[BLOCKSIZE], z, arg); va_end(arg); termwrite(buf); }
void itrace(char *fmt, ...) { char buf[128]; va_list arg; va_start(arg, fmt); vseprint(buf, buf+sizeof(buf), fmt, arg); va_end(arg); Bprint(bioout, "%8lux %.8lux %2d %s\n", reg.ar, reg.ir, reg.class, buf); }
static void clog(char *fmt, ...) { char msg[256]; va_list arg; va_start(arg, fmt); vseprint(msg, msg + sizeof msg, fmt, arg); va_end(arg); syslog(0, CRONLOG, msg); }
static void fatal(char *fmt, ...) { char msg[256]; va_list arg; va_start(arg, fmt); vseprint(msg, msg + sizeof msg, fmt, arg); va_end(arg); error("%s", msg); }
/* libmp at least contains a few calls to sysfatal; simulate with panic */ void sysfatal(char *fmt, ...) { char err[256]; va_list arg; va_start(arg, fmt); vseprint(err, err + sizeof err, fmt, arg); va_end(arg); panic("sysfatal: %s", err); }
void errorf(char *fmt, ...) { va_list arg; char buf[PRINTSIZE]; va_start(arg, fmt); vseprint(buf, buf+sizeof(buf), fmt, arg); va_end(arg); error(buf); }
static void _sysfatalimpl(char *fmt, va_list arg) { char buf[1024]; vseprint(buf, buf+sizeof(buf), fmt, arg); if(argv0) fprint(2, "%s: %s\n", argv0, buf); else fprint(2, "%s\n", buf); exits(buf); }
void werrstr(char *fmt, ...) { va_list va; if(up == nil) return; va_start(va, fmt); vseprint(up->syserrstr, up->syserrstr+ERRMAX, fmt, va); va_end(va); }
void warn(char *fmt, ...) { char buf[1024]; va_list arg; sprint(buf, "%q: ", argv0); va_start(arg, fmt); vseprint(buf+strlen(buf), buf+sizeof(buf), fmt, arg); va_end(arg); fprint(2, "%s\n", buf); }
static void styxfatal(char *fmt, ...) { char buf[1024], *out; va_list arg; out = seprint(buf, buf+sizeof(buf), "Fatal error: "); va_start(arg, fmt); out = vseprint(out, buf+sizeof(buf), fmt, arg); va_end(arg); write(2, buf, out-buf); styxexit(1); }
static void fatal(char *fmt, ...) { char buf[4096]; va_list arg; va_start(arg, fmt); vseprint(buf, buf+sizeof(buf), fmt, arg); va_end(arg); fprint(2, "ktrace: %s\n", buf); exits(buf); }
void api_abend_unimpl(struct api_thread *thread, char *srcfile, int lineno, char *msg, ...) { char buf[0x100]; va_list arg; va_start(arg, msg); vseprint(buf, buf+sizeof buf, msg, arg); va_end(arg); api_abend(thread, "%s:%d: %s next", srcfile, lineno, buf); }
int sprint(char *s, char *fmt, ...) { int n; va_list arg; va_start(arg, fmt); n = vseprint(s, s+PRINTSIZE, fmt, arg) - s; va_end(arg); return n; }