1 #include "all.h" 2 3 extern int cmdfd; 4 5 Float 6 famd(Float a, int b, int c, int d) 7 { 8 ulong x, m; 9 10 x = (a + b) * c; 11 m = x % d; 12 x /= d; 13 if(m >= d / 2) 14 x++; 15 return x; 16 } 17 18 ulong 19 fdf(Float a, int d) 20 { 21 ulong x, m; 22 23 m = a % d; 24 x = a / d; 25 if(m >= d / 2) 26 x++; 27 return x; 28 } 29 30 long 31 belong(char *s) 32 { 33 uchar *x; 34 35 x = (uchar *)s; 36 return (x[0] << 24) + (x[1] << 16) + (x[2] << 8) + x[3]; 37 } 38 39 void 40 panic(char *fmt, ...) 41 { 42 char buf[8192], *s; 43 va_list arg; 44 45 46 s = buf; 47 s += sprint(s, "%s %s %d: ", progname, procname, getpid()); 48 va_start(arg, fmt); 49 s = vseprint(s, buf + sizeof(buf) / sizeof(*buf), fmt, arg); 50 va_end(arg); 51 *s++ = '\n'; 52 write(2, buf, s - buf); 53 abort(); 54 exits(buf); 55 } 56 57 #define SIZE 4096 58 59 void 60 cprint(char *fmt, ...) 61 { 62 char buf[SIZE], *out; 63 va_list arg; 64 65 va_start(arg, fmt); 66 out = vseprint(buf, buf+SIZE, fmt, arg); 67 va_end(arg); 68 write(cmdfd, buf, (long)(out-buf)); 69 } 70 71 /* 72 * print goes to fd 2 [sic] because fd 1 might be 73 * otherwise preoccupied when the -s flag is given to kfs. 74 */ 75 int 76 print(char *fmt, ...) 77 { 78 va_list arg; 79 int n; 80 81 va_start(arg, fmt); 82 n = vfprint(2, fmt, arg); 83 va_end(arg); 84 return n; 85 } 86 87