1 |
– |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Portable i/o for binary files |
6 |
+ |
* |
7 |
+ |
* External symbols declared in rtio.h |
8 |
|
*/ |
9 |
|
|
10 |
< |
#include <stdio.h> |
10 |
> |
#include "copyright.h" |
11 |
|
|
12 |
+ |
#include "rtio.h" |
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 |
22 |
+ |
|
23 |
+ |
|
24 |
+ |
void |
25 |
|
putstr(s, fp) /* write null-terminated string to fp */ |
26 |
|
register char *s; |
27 |
|
register FILE *fp; |
32 |
|
} |
33 |
|
|
34 |
|
|
35 |
+ |
void |
36 |
|
putint(i, siz, fp) /* write a siz-byte integer to fp */ |
37 |
|
long i; |
38 |
|
register int siz; |
43 |
|
} |
44 |
|
|
45 |
|
|
46 |
+ |
void |
47 |
|
putflt(f, fp) /* put out floating point number */ |
48 |
|
double f; |
49 |
|
FILE *fp; |
50 |
|
{ |
51 |
< |
extern double frexp(); |
51 |
> |
long m; |
52 |
|
int e; |
53 |
|
|
54 |
< |
putint((long)(frexp(f,&e)*0x7fffffff), 4, fp); |
54 |
> |
m = frexp(f, &e) * 0x7fffffff; |
55 |
> |
if (e > 127) { /* overflow */ |
56 |
> |
m = m > 0 ? (long)0x7fffffff : -(long)0x7fffffff; |
57 |
> |
e = 127; |
58 |
> |
} else if (e < -128) { /* underflow */ |
59 |
> |
m = 0; |
60 |
> |
e = 0; |
61 |
> |
} |
62 |
> |
putint(m, 4, fp); |
63 |
|
putint((long)e, 1, fp); |
64 |
|
} |
65 |
|
|
106 |
|
getflt(fp) /* get a floating point number */ |
107 |
|
FILE *fp; |
108 |
|
{ |
109 |
< |
extern double ldexp(); |
109 |
> |
long l; |
110 |
|
double d; |
111 |
|
|
112 |
< |
d = (double)getint(4, fp)/0x7fffffff; |
112 |
> |
l = getint(4, fp); |
113 |
> |
if (l == 0) { |
114 |
> |
getc(fp); /* exactly zero -- ignore exponent */ |
115 |
> |
return(0.0); |
116 |
> |
} |
117 |
> |
d = (l + (l > 0 ? .5 : -.5)) * (1./0x7fffffff); |
118 |
|
return(ldexp(d, (int)getint(1, fp))); |
119 |
|
} |