33 |
|
FILE *fp |
34 |
|
) |
35 |
|
{ |
36 |
< |
while (siz--) |
37 |
< |
putc((int)(i>>(siz<<3) & 0xff), fp); |
36 |
> |
while (siz > sizeof(long)) { |
37 |
> |
putc((i<0)*0xff, fp); |
38 |
> |
siz--; |
39 |
> |
} |
40 |
> |
siz <<= 3; |
41 |
> |
while ((siz -= 8) > 0) |
42 |
> |
putc((int)(i>>siz & 0xff), fp); |
43 |
> |
putc((int)(i & 0xff), fp); |
44 |
|
} |
45 |
|
|
46 |
|
|
62 |
|
e = 0; |
63 |
|
} |
64 |
|
putint(m, 4, fp); |
65 |
< |
putint((long)e, 1, fp); |
65 |
> |
putint(e, 1, fp); |
66 |
|
} |
67 |
|
|
68 |
|
|
69 |
< |
int |
69 |
> |
size_t |
70 |
|
putbinary( /* fwrite() replacement for small objects */ |
71 |
< |
char *s, |
72 |
< |
int elsiz, |
73 |
< |
int nel, |
71 |
> |
const void *p, |
72 |
> |
size_t elsiz, |
73 |
> |
size_t nel, |
74 |
|
FILE *fp) |
75 |
|
{ |
76 |
< |
int nbytes = elsiz*nel; |
76 |
> |
const char *s = (const char *)p; |
77 |
> |
size_t nbytes = elsiz*nel; |
78 |
|
|
79 |
< |
if (nbytes > 512) |
80 |
< |
return(fwrite(s, elsiz, nel, fp)); |
79 |
> |
if (nbytes > 128) |
80 |
> |
return(fwrite(p, elsiz, nel, fp)); |
81 |
|
|
82 |
|
while (nbytes-- > 0) |
83 |
< |
putc(*s++, fp); |
83 |
> |
if (putc(*s++, fp) == EOF) |
84 |
> |
return((elsiz*nel - nbytes)/elsiz); |
85 |
|
|
86 |
|
return(nel); |
87 |
|
} |
116 |
|
|
117 |
|
if ((c = getc(fp)) == EOF) |
118 |
|
return(EOF); |
119 |
< |
r = 0x80&c ? -1<<8|c : c; /* sign extend */ |
119 |
> |
r = c; |
120 |
> |
if (c & 0x80) /* sign extend? */ |
121 |
> |
r |= ~255L; |
122 |
|
while (--siz > 0) { |
123 |
|
if ((c = getc(fp)) == EOF) |
124 |
|
return(EOF); |
149 |
|
} |
150 |
|
|
151 |
|
|
152 |
< |
int |
152 |
> |
size_t |
153 |
|
getbinary( /* fread() replacement for small objects */ |
154 |
< |
char *s, |
155 |
< |
int elsiz, |
156 |
< |
int nel, |
154 |
> |
void *p, |
155 |
> |
size_t elsiz, |
156 |
> |
size_t nel, |
157 |
|
FILE *fp) |
158 |
|
{ |
159 |
< |
int nbytes = elsiz*nel; |
159 |
> |
char *s = (char *)p; |
160 |
> |
size_t nbytes = elsiz*nel; |
161 |
|
int c; |
162 |
|
|
163 |
< |
if (nbytes > 512) |
164 |
< |
return(fread(s, elsiz, nel, fp)); |
163 |
> |
if (nbytes > 128) |
164 |
> |
return(fread(p, elsiz, nel, fp)); |
165 |
|
|
166 |
|
while (nbytes-- > 0) { |
167 |
|
if ((c = getc(fp)) == EOF) |