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 |
> |
putc((int)(i & 0xff), fp); |
40 |
|
} |
41 |
|
|
42 |
|
|
58 |
|
e = 0; |
59 |
|
} |
60 |
|
putint(m, 4, fp); |
61 |
< |
putint((long)e, 1, fp); |
61 |
> |
putint(e, 1, fp); |
62 |
|
} |
63 |
|
|
64 |
|
|
65 |
+ |
int |
66 |
+ |
putbinary( /* fwrite() replacement for small objects */ |
67 |
+ |
const void *p, |
68 |
+ |
int elsiz, |
69 |
+ |
int nel, |
70 |
+ |
FILE *fp) |
71 |
+ |
{ |
72 |
+ |
const char *s = (const char *)p; |
73 |
+ |
int nbytes = elsiz*nel; |
74 |
+ |
|
75 |
+ |
if (nbytes > 128) |
76 |
+ |
return(fwrite(p, elsiz, nel, fp)); |
77 |
+ |
|
78 |
+ |
while (nbytes-- > 0) |
79 |
+ |
if (putc(*s++, fp) == EOF) |
80 |
+ |
return((elsiz*nel - nbytes)/elsiz); |
81 |
+ |
|
82 |
+ |
return(nel); |
83 |
+ |
} |
84 |
+ |
|
85 |
+ |
|
86 |
|
char * |
87 |
|
getstr( /* get null-terminated string */ |
88 |
|
char *s, |
140 |
|
} |
141 |
|
d = (l + (l > 0 ? .5 : -.5)) * (1./0x7fffffff); |
142 |
|
return(ldexp(d, (int)getint(1, fp))); |
143 |
+ |
} |
144 |
+ |
|
145 |
+ |
|
146 |
+ |
int |
147 |
+ |
getbinary( /* fread() replacement for small objects */ |
148 |
+ |
void *p, |
149 |
+ |
int elsiz, |
150 |
+ |
int nel, |
151 |
+ |
FILE *fp) |
152 |
+ |
{ |
153 |
+ |
char *s = (char *)p; |
154 |
+ |
int nbytes = elsiz*nel; |
155 |
+ |
int c; |
156 |
+ |
|
157 |
+ |
if (nbytes > 128) |
158 |
+ |
return(fread(p, elsiz, nel, fp)); |
159 |
+ |
|
160 |
+ |
while (nbytes-- > 0) { |
161 |
+ |
if ((c = getc(fp)) == EOF) |
162 |
+ |
return((elsiz*nel - nbytes)/elsiz); |
163 |
+ |
*s++ = c; |
164 |
+ |
} |
165 |
+ |
return(nel); |
166 |
|
} |