Bug #166 » xdrtest.c
1 |
#include <rpc/xdr.h>
|
---|---|
2 |
#include <stdio.h>
|
3 |
#include <stdlib.h>
|
4 |
#include <errno.h>
|
5 |
#include <string.h>
|
6 |
|
7 |
/*
|
8 |
* X86 and amd64 machines use IEEE format for floats, which is the same
|
9 |
* as the xdr OTW format.
|
10 |
*/
|
11 |
|
12 |
int
|
13 |
main(int argc, char **argv) |
14 |
{
|
15 |
const char filename[] = "xdrtest.dat"; |
16 |
|
17 |
XDR xdr; |
18 |
FILE *f = NULL; |
19 |
float a, b; |
20 |
|
21 |
a = 0.0F; |
22 |
f = fopen(filename, "w+"); |
23 |
if (f == NULL) { |
24 |
fprintf(stderr, "Unable to open %s: %s\n", filename, |
25 |
strerror(errno)); |
26 |
return (1); |
27 |
}
|
28 |
|
29 |
fwrite(&a, sizeof (a), 1, f); |
30 |
rewind(f); |
31 |
|
32 |
b = 4.2f; |
33 |
|
34 |
xdrstdio_create(&xdr, f, XDR_DECODE); |
35 |
xdr_float(&xdr, &b); |
36 |
printf("b = %f\n", b); |
37 |
fclose(f); |
38 |
|
39 |
return (0); |
40 |
}
|