pci: don't do sanity check for missing pci bus, the check can misfire.
[minix.git] / commands / aal / long2str.c
blob7052ecaec8b025494b937d2834f0b7b646dfa006
1 /* $Header$ */
2 /*
3 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4 * See the copyright notice in the ACK home directory, in the file "Copyright".
5 */
6 /* Integer to String translator
7 -> base is a value from [-16,-2] V [2,16]
8 -> base < 0: see 'val' as unsigned value
9 -> no checks for buffer overflow and illegal parameters
10 (1985, EHB)
13 #define MAXWIDTH 32
15 char *
16 long2str(val, base)
17 register long val;
18 register base;
20 static char numbuf[MAXWIDTH];
21 static char vec[] = "0123456789ABCDEF";
22 register char *p = &numbuf[MAXWIDTH];
23 int sign = (base > 0);
25 *--p = '\0'; /* null-terminate string */
26 if (val) {
27 if (base > 0) {
28 if (val < 0L) {
29 long v1 = -val;
30 if (v1 == val)
31 goto overflow;
32 val = v1;
34 else
35 sign = 0;
37 else
38 if (base < 0) { /* unsigned */
39 base = -base;
40 if (val < 0L) { /* taken from Amoeba src */
41 register mod, i;
42 overflow:
43 mod = 0;
44 for (i = 0; i < 8 * sizeof val; i++) {
45 mod <<= 1;
46 if (val < 0)
47 mod++;
48 val <<= 1;
49 if (mod >= base) {
50 mod -= base;
51 val++;
54 *--p = vec[mod];
57 do {
58 *--p = vec[(int) (val % base)];
59 val /= base;
60 } while (val != 0L);
61 if (sign)
62 *--p = '-'; /* don't forget it !! */
64 else
65 *--p = '0'; /* just a simple 0 */
66 return p;