13 |
|
|
14 |
|
#include <math.h> |
15 |
|
|
16 |
– |
#ifdef getc_unlocked /* avoid horrendous overhead of flockfile */ |
17 |
– |
#undef getc |
18 |
– |
#undef putc |
19 |
– |
#define getc getc_unlocked |
20 |
– |
#define putc putc_unlocked |
21 |
– |
#endif |
16 |
|
|
23 |
– |
|
17 |
|
void |
18 |
|
putstr( /* write null-terminated string to fp */ |
19 |
|
char *s, |
33 |
|
FILE *fp |
34 |
|
) |
35 |
|
{ |
36 |
< |
while (siz--) |
37 |
< |
putc((int)(i>>(siz<<3) & 0xff), fp); |
36 |
> |
siz <<= 3; |
37 |
> |
while ((siz -= 8) >= 0) |
38 |
> |
putc((int)(i>>siz & 0xff), fp); |
39 |
|
} |
40 |
|
|
41 |
|
|
61 |
|
} |
62 |
|
|
63 |
|
|
64 |
+ |
int |
65 |
+ |
putbinary( /* fwrite() replacement for small objects */ |
66 |
+ |
char *s, |
67 |
+ |
int elsiz, |
68 |
+ |
int nel, |
69 |
+ |
FILE *fp) |
70 |
+ |
{ |
71 |
+ |
int nbytes = elsiz*nel; |
72 |
+ |
|
73 |
+ |
if (nbytes > 512) |
74 |
+ |
return(fwrite(s, elsiz, nel, fp)); |
75 |
+ |
|
76 |
+ |
while (nbytes-- > 0) |
77 |
+ |
putc(*s++, fp); |
78 |
+ |
|
79 |
+ |
return(nel); |
80 |
+ |
} |
81 |
+ |
|
82 |
+ |
|
83 |
|
char * |
84 |
|
getstr( /* get null-terminated string */ |
85 |
|
char *s, |
137 |
|
} |
138 |
|
d = (l + (l > 0 ? .5 : -.5)) * (1./0x7fffffff); |
139 |
|
return(ldexp(d, (int)getint(1, fp))); |
140 |
+ |
} |
141 |
+ |
|
142 |
+ |
|
143 |
+ |
int |
144 |
+ |
getbinary( /* fread() replacement for small objects */ |
145 |
+ |
char *s, |
146 |
+ |
int elsiz, |
147 |
+ |
int nel, |
148 |
+ |
FILE *fp) |
149 |
+ |
{ |
150 |
+ |
int nbytes = elsiz*nel; |
151 |
+ |
int c; |
152 |
+ |
|
153 |
+ |
if (nbytes > 512) |
154 |
+ |
return(fread(s, elsiz, nel, fp)); |
155 |
+ |
|
156 |
+ |
while (nbytes-- > 0) { |
157 |
+ |
if ((c = getc(fp)) == EOF) |
158 |
+ |
return((elsiz*nel - nbytes)/elsiz); |
159 |
+ |
*s++ = c; |
160 |
+ |
} |
161 |
+ |
return(nel); |
162 |
|
} |