6 namecmp(char *s, char *t)
8 return strncmp(s, t, ANameSize);
12 namecp(char *dst, char *src)
14 strncpy(dst, src, ANameSize - 1);
15 dst[ANameSize - 1] = '\0';
26 for(t = name; c = *t; t++)
27 if(t - name >= ANameSize
28 || c < ' ' || c >= 0x7f)
34 stru32int(char *s, u32int *r)
44 if(c < '0' || c > '9')
48 nn = n * 10 + c - '0';
54 return s != t && *t == '\0';
58 stru64int(char *s, u64int *r)
68 if(c < '0' || c > '9')
72 nn = n * 10 + c - '0';
78 return s != t && *t == '\0';
84 return type < VtMaxType;
88 logit(int severity, char *fmt, va_list args)
92 s = vsmprint(fmt, args);
97 fprint(2, "%T %s: err %d: %s\n", argv0, severity, s);
99 fprint(2, "%T err %d: %s\n", severity, s);
105 seterr(int severity, char *fmt, ...)
111 s = logit(severity, fmt, args);
114 werrstr("error setting error");
122 logerr(int severity, char *fmt, ...)
128 s = logit(severity, fmt, args);
150 sysfatal("out of memory allocating %lud", n);
153 setmalloctag(p, getcallerpc(&n));
154 if(0)print("emalloc %p-%p by %#p\n", p, (char*)p+n, getcallerpc(&n));
167 sysfatal("out of memory allocating %lud", n);
170 setmalloctag(p, getcallerpc(&n));
171 if(0)print("ezmalloc %p-%p by %#p\n", p, (char*)p+n, getcallerpc(&n));
176 erealloc(void *p, ulong n)
182 sysfatal("out of memory allocating %lud", n);
184 setrealloctag(p, getcallerpc(&p));
185 if(0)print("erealloc %p-%p by %#p\n", p, (char*)p+n, getcallerpc(&p));
198 setmalloctag(t, getcallerpc(&s));
199 if(0)print("estrdup %p-%p by %#p\n", t, (char*)t+n, getcallerpc(&s));
204 * return floor(log2(v))
211 for(i = 0; i < 64; i++)
218 vtproc(void (*fn)(void*), void *arg)
220 proccreate(fn, arg, 256*1024);
229 ie = va_arg(fmt->args, IEntry*);
230 return fmtprint(fmt, "%V %22lld %3d %5d %3d",
231 ie->score, ie->ia.addr, ie->ia.type, ie->ia.size, ie->ia.blocks);
235 ventifmtinstall(void)
237 fmtinstall('F', vtfcallfmt);
238 fmtinstall('H', encodefmt);
239 fmtinstall('I', ientryfmt);
240 fmtinstall('T', vttimefmt);
241 fmtinstall('V', vtscorefmt);
247 return nsec()/1000000;
253 n = (n&0x55555555)+((n>>1)&0x55555555);
254 n = (n&0x33333333)+((n>>2)&0x33333333);
255 n = (n&0x0F0F0F0F)+((n>>4)&0x0F0F0F0F);
256 n = (n&0x00FF00FF)+((n>>8)&0x00FF00FF);
257 n = (n&0x0000FFFF)+((n>>16)&0x0000FFFF);