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 standard.h |
8 |
|
*/ |
9 |
|
|
10 |
+ |
#include "copyright.h" |
11 |
+ |
|
12 |
|
#include <stdio.h> |
13 |
|
|
14 |
+ |
#include "rtio.h" |
15 |
|
|
16 |
+ |
#include <math.h> |
17 |
+ |
|
18 |
+ |
#ifdef getc_unlocked /* avoid horrendous overhead of flockfile */ |
19 |
+ |
#undef getc |
20 |
+ |
#undef putc |
21 |
+ |
#define getc getc_unlocked |
22 |
+ |
#define putc putc_unlocked |
23 |
+ |
#endif |
24 |
+ |
|
25 |
+ |
|
26 |
+ |
void |
27 |
|
putstr(s, fp) /* write null-terminated string to fp */ |
28 |
|
register char *s; |
29 |
|
register FILE *fp; |
34 |
|
} |
35 |
|
|
36 |
|
|
37 |
+ |
void |
38 |
|
putint(i, siz, fp) /* write a siz-byte integer to fp */ |
39 |
|
long i; |
40 |
|
register int siz; |
45 |
|
} |
46 |
|
|
47 |
|
|
48 |
+ |
void |
49 |
|
putflt(f, fp) /* put out floating point number */ |
50 |
|
double f; |
51 |
|
FILE *fp; |
52 |
|
{ |
38 |
– |
extern double frexp(); |
53 |
|
int e; |
54 |
|
|
55 |
|
putint((long)(frexp(f,&e)*0x7fffffff), 4, fp); |
99 |
|
getflt(fp) /* get a floating point number */ |
100 |
|
FILE *fp; |
101 |
|
{ |
102 |
< |
extern double ldexp(); |
102 |
> |
long l; |
103 |
|
double d; |
104 |
|
|
105 |
< |
d = (double)getint(4, fp)/0x7fffffff; |
105 |
> |
l = getint(4, fp); |
106 |
> |
if (l == 0) { |
107 |
> |
getc(fp); /* exactly zero -- ignore exponent */ |
108 |
> |
return(0.0); |
109 |
> |
} |
110 |
> |
d = (l + (l > 0 ? .5 : -.5)) * (1./0x7fffffff); |
111 |
|
return(ldexp(d, (int)getint(1, fp))); |
112 |
|
} |